Skip Navigation

[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.

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/#integration-with-custom-searches

This support ticket is created 4 years, 7 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 15 replies, has 3 voices.

Last updated by yannicN 4 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#1619863

Dear support team,

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?

Thanks for your help.

#1621139

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#1621377

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Unfortunately - when I try to access the wp-admin, it throws the following error with a blank page:

Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Do you have any county wise or IP restrictions set - if yes, can you please remove those.

#1621405

Please try again. There are no IP restrictions.

#1622461

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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

#1622601

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

This is strange. I checked with one of our supporter (Jamal) and at least he is able to access your site so passing this ticket to him.

#1622603

Oh really weird. Please change my last reply with the screenshots and my phone number. Thank you.

#1622791

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).

#1623505

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 for your help.

#1624277

Thank you for your feedback. Instead of testing/debugging on your live site, I'd rather prefer to take a copy of it and investigate the issue locally.

We prefer a Duplicator copy as described here https://toolset.com/faq/provide-supporters-copy-site/
Please use filter to reduce the size of the copy as described in this video around 1:00 hidden link

If Duplicator fails to create a copy, we'll need a database copy/export, plugins, and theme folders, all in a zip file.

Your next reply will be private to let you share the download link safely.

#1624627

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.

#1624805

Hi, Jamal,

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.

Thanks for your help!

#1626157

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

According to our documentation, in the last paragraph in this section https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/#integration-with-custom-searches

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.

#1626265

Thank you for the information and your help. I am curious to hear the response from your 2nd Tier.

#1629987

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.

To continue using the distance filter, you will need to avoid searching through custom fields. If you need to combine both, distance and custom fields search, please ask this feature here https://toolset.com/contact-us/suggest-a-new-feature-for-toolset/

I hope this helps. Let me know your feedback.