[Resolved] Combined Search field and distance filter in view
This thread is resolved. Here is a description of the problem and solution.
Problem:
The user wanted to use the distance filter in a view but it does not work.
Solution:
The search was also using Relevanssi to search in custom fields. In fact, debugging my views shows that when a term is used in the text search filter, the search query against the database does not include distance/geolocation parameters. Check these screenshots:
- With search box query: http://prntscr.com/shff99
- Without search box query: http://prntscr.com/shfgc4
According to our documentation:
Once you add a search filter that includes custom fields, the entire search operation is performed by the Relevanssi plugin, which means that Relevanssi is also responsible for providing the results order. This is why the Views sorting order options are not used.
I have a view with various filter options on the page "Für Unternehmen" on the specified website. If I fill in the text search field and also fill in the distance filter field, the distance field is no longer considered. Entries outside the entered radius are also displayed. If I leave the search field empty, the distance search works correctly. What can I do?
Hello. Thank you for contacting the Toolset support.
As I understand, with your page: hidden link
- The custom search do not display expected result when you input values for text search as well as distance search but if you only input the distance search value - it works. Correct? If yes:
- Can you please share what keyword you use for text search and share few locations using which I can search and tell me what is your expected results.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Sorry, but unfortunately, it still not working at this end. I have also checked with one of my colleagues and for him as well admin login page is not working and he sees the same error which I see: Service Unavailable
Hello! Minesh asked me to continue on this ticket as I can access your website.
I logged in and was able to test with the provided example, searching for "Nels" in "Munich" returned a "Hamburg" result, which is far from the search radius/distance.
I run a test with the latest releases of Toolset Types, Views, Maps, 2020theme and I was not able to reproduce the issue.
On your test site, please check if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Fourteen. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at the time to track where the incompatibility is produced.
You may also clear the cached addresses in Toolset->Settings->Maps->Cached data. The cache data is regenerated when a marker is rendered inside a map, you may want to create a map view on a private window which will display all addresses, just to recreate the cache. Then test again.
Note that Google only Allows 10 requests per second. You have currently 531 addresses. The first map render could take more than 53seconds.
Before clearing all the addresses, you may want to clear only some addresses that produce the issue (Nels from Hamburg).
Dear Jamal,
I have deactivated all not necessary plugins except the Toolset Plugins and activated a default WordPress theme. Unfortunately it still does not work. I also deleted the cache of addresses. Unfortunately without success. For testing purposes I created a second page (hidden link) and duplicated the existing view. You can also use this page for your tests. I found out that it works correctly if you select in the filter option when adding a search box in the view that only the post content and title should be searched and not custom post types as well. This is not acceptable, but it might help in troubleshooting.
Thank you! I was able to build a copy of your website and test it locally. The issue was reproduced.
First, I removed the search box and the related query from the view and recreated them again. When the search box is bound to title or title and content, it works. When it is also bound on custom fields it does not.
Searching inside custom fields requires the Relevanssi plugin. The plugin was already activated in my local copy. Then I realized that Relevanssi had an empty index. Check this screenshot hidden link
After building the index, the search worked without issues. hidden link
Check the following screenshot from my local copy,I don't really know Germany's geography, but I think that the results are correct. hidden link
Please check again on your website, activate Relevanssi, and rebuild its index. Let me know what you will get.
Thanks for your answer. Unfortunately, it's not correct. Magdeburg is definitely more than 50 km away from Munich. I tried it on the productive website with other examples and unfortunately it did not work. I think that this is not the mistake.
I checked again on my local setup and I was able to reproduce the issue. Once we use a search term and a distance, while configuring the search to query custom fields too, the results are not accurate.
In fact, debugging my views shows that when a term is used in the text search filter, the search query against the database does not include distance/geolocation parameters. Check these screenshots:
- With search box query: hidden link
- Without search box query: hidden link
Once you add a search filter that includes custom fields, the entire search operation is performed by the Relevanssi plugin, which means that Relevanssi is also responsible for providing the results order. This is why the Views sorting order options are not used.
Maybe it is expected to let Relevanssi do the search! To be sure, let me approach our 2nd Tier for assistance on the subject and I'll get back to you as soon as possible.
Hello and my apologies for the late reply. Our 2nd Tier has confirmed that once Relevanssi is used for searching through custom fields, it takes over the view query. The distance filter is hooked into the view query which is not used in this case.