This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Issues with relevance, etc.

#18976
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

This is a tough one, but I think there is a possible way to improve it with a minor code customization and a few other changes.
The problem with the additional search keywords field is, that it should be used for single keywords, that may describe the item as a result. It is not suitable for entering multi-word ‘phrases’. Another problem is, that recognizing phrases (such as multi-word city names) between word boundaries is basically impossible during the database search process. However I think that could be resolved for this specific case, with a special configuration.

I have made a modification to the main search file, that will look for matches within custom fields, that only exactly match the whole search phrase, as well as only if the match is surrounded by a comma-space from both sides – so that only separate cities/zip codes are recognized.

To make this one work, please follow the steps below:

1. Before starting, make sure to have a full-site back-up of everything, just to be sure that nothing goes wrong.
2. Open up the wp-content\plugins\ajax-search-pro\includes\classes\search\class-asp-search-cpt.php file on your server, and replace it’s contents with this. This change will make sure this specific boundary matching. Make sure to save this file.
3. Instead of using the additional keywords field, let’s make a different custom field, I am using the name ‘search_locations’: https://i.imgur.com/ViHIH5z.png
4. In this field, enter the city and zip code names, separated by a comma+space, like so:
[html]Big city1, Big city 2, Space city 1, Zip1123, Other city[/html]
5. Save the post, save the field.
6. On the search instance back-end options, make sure to choose this custom field for searching: https://i.imgur.com/Bcvxik3.png
7. ..also, this will only work with the regular engine, so make sure you are using that: https://i.imgur.com/hLu2P1E.png
8. ..and also, I recommend using this setup for the search logic: https://i.imgur.com/wcUw3ZN.png

Now, entering a city name or a Zip code, will only match, if the whole phrase is matched between the boundaries, no partial matches. This is still not the fully expected solution, but I believe it is the closest possible one.