Skip Navigation

[Resolved] Toolset Maps Distance search returns wrong result

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 3 voices.

Last updated by Waqar 1 year, 3 months ago.

Assisted by: Nigel.

Author
Posts
#2440613

The attached duplicator features a Map on the /find-an-artist/ page.
Below the map, there is a Custom Search for Distance.

1. Attempt to search by 25mi from Washington D.C., DC, USA (use the autosuggested address for "Washington" please).
2. You will see several results returned on the map.
3. At least one of them is not in Washington D.C., DC, USA, rather it is in Charlotte, NC, USA - which is several hundred miles away from Washington D.C., DC, USA

1) Now, edit that result (Charlotte, NC, USA) and make its address to be Zurich, Switzerland or anything very far, very different from USA.
2) Reload the map, and search again for Washington D.C., DC, USA
3) You will see the post for Zurich, Switzerland (Previously Charlotte, NC, USA) returns again in the results. This time, it is several thousand miles away from Washington D.C., DC, USA and has absolutely nothing to do with anything USA.

Given all this, I do not believe this is the known Google Bug explained here https://toolset.com/errata/search-by-distance-may-produce-wrong-results/, rather some different bug or problem I can't put my fingers on.

Please find a clean duplicate below with the issue visible as per the steps above.
The duplicate user and password is test1/root

#2440733

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Beda

Good to hear from you.

I installed the site and noticed there were 2 posts being returned that should not have been (with ID 3545 and 3544).

(To make it easier to see what was going on I had simplified the output of the View to include just the post title and ID, location, and distance.)

There was something odd about these 2 posts: they both had postmeta entries with a key "Location" that had addresses close to Washington D.C., although the wpcf- address fields had different locations much further away.

Somehow the distance calculation used in the modified post query seemed to be getting the coordinates from these fields, and I don't know how that might have arisen.

In any case, I resolved the problem by just deleting those two postmeta entries (with meta_id 37230 and 37227 respectively), and that fixed the issue. (I checked and there doesn't appear to be an active field with key "Location".)

#2440743

Hi Nigel,

Thanks for the help on this.
Indeed, I had seen those fields as well (they probably are from the import process from their old HTML based site). I had not considered deleting them because clearly the View should (and according debug info of the view query) does query by a wpcf- field.

Does this warrant more investigation, since it seems that if a post has any field with a value LIKE%% location, it picks that one as the address?
This should not happen, since the query is set for a particular, precise field key.
I confirmed that simply adding a (Toolset Types) single line field with Name "Location" immediately brings the issue back.

I did not try on clean install but I am relatively sure this is replicable, and thus sounds like a BUG to me, it seems like the plugin queries fields by a LIKE%% location key instead of a precise key (even thou, according the SQL log that is not the case...)

Thanks!

#2440779

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Actually, it's worse than that.

Here's the query resulting from that search:

SELECT TGB_posts.*
FROM TGB_posts
INNER JOIN TGB_postmeta AS tmapsmeta
ON ( TGB_posts.ID = tmapsmeta.post_id )
LEFT JOIN TGB_toolset_maps_address_cache
ON TGB_toolset_maps_address_cache.address_passed = tmapsmeta.meta_value
WHERE 1=1
AND TGB_posts.post_type = 'artist-listing'
AND ((TGB_posts.post_status = 'publish'
OR TGB_posts.post_status = 'private'))
AND ST_Distance_Sphere(ST_PointFromText('POINT(-77.036871 38.907192)'), TGB_toolset_maps_address_cache.point) < 40233.6
GROUP BY TGB_posts.ID
ORDER BY TGB_posts.post_date DESC

Notes that it doesn't specify a post meta key at all, it looks at all postmeta entries for any that have a value included in the maps address cache.

I tested by adding a custom field with the key "bananas" and it also came up in the results.

I'll circle back to this a little later to escalate properly.

#2440819

Right, I'm sorry - I could have sworn I saw the wpcf- field in that SQL log, yet it's not there.

🥲 truly bananas.

Thanks for digging!

#2441031

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

It will be Monday before I create the tickets to escalate, but I just wanted to share with you that my suspicions were that a postmeta condition for the address field key may only be added when ordering by distance, and sure enough that is the case.

Your problem is that you have implemented this using Blocks (!), and the option to order results by distance was never added to the View block, you can only add it when creating a View with the legacy editor.

But! There is a workaround for when using a View block: https://toolset.com/errata/cannot-order-results-by-distance-in-views-created-with-the-block-editor/

#2441299

Thanks for the update Nigel

Unfortunately here the client wants explicitly ordered Random (makes sense so to give each artist the same „chance“ to be first on the list)

Goes without saying that I didn’t implement the search itself 😅
I’d have used legacy to start with haha.

Anyway - for our case here removing the field works.

Looking forward to some fix, nonetheless, since it seems also rather inefficient to not query by a specified field?

Thanks again…

#2445675

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I had a busy week so I've only just gotten back to this.

I've reproduced on a clean test site and escalated that to the maps developers.

I'll keep you posted.

#2634987

Hi Beda,

Hope you're doing great!

I'd like to inform you that fix for this issue was covered in the recent release of the Maps plugin ( ver: 2.1.3 ).

Feel free to update the Toolset plugins to the latest versions and let us know if the issue persists.

regards,
Waqar