Tagged: ajax, ajax search, enfold, relevanssi, search
-
AuthorPosts
-
August 1, 2023 at 3:29 pm #1415158
Hi guys,
I have raised this as a ticket with Relevanssi but wondered if there has been an update from Enfold’s end.
Previous posts have not provided a valid solution.When Relevanssi is installed the Ajax search results that appear from the Enfold Search bar is set to all results meaning you get an extremely long load time for ajax results and a list as long as the entire page!
If you turn on Throttling in Relevanssi settings it limits this to 500 entries but also limits the full search results page to 500 entries.If I add the following function it limits the Ajax search to 5 entries BUT also limits the full search results page to 5 entries. This is obviously not great for users and in solving the ajax issue it causes another problem!
add_filter( 'pre_option_relevanssi_throttle_limit', function( $limit ) { return 5; } );
Is there a way to limit just the Ajax search results to 5 rather than globally adjusting the Relevanssi search to 5.
I want to limit Ajax instant searches to between 5 – 50 results and let the actual search results page display all or use the standard 500 throttle limit.
August 1, 2023 at 3:51 pm #1415171Hey Thomas,
I did not dig deeper in it, but when the full search result page does not use ajax you could try:
if( wp_doing_ajax() ) { add_filter( 'pre_option_relevanssi_throttle_limit', function( $limit ) { return 5; } ); }
Best regards,
GünterAugust 1, 2023 at 3:57 pm #1415172Hi Gunter,
That works. But the theme developer is suggesting a better way to do this.
https://wordpress.org/support/topic/limit-ajax-search-to-5-posts/#post-16938764Although this works
It means the Ajax search results are a lot less accurate so it isnt perfect but at least it gives much better control over the ajax and increases the speed.
Setting this to 25-50 seems to improve the search accuracy on the site I am using it on.- This reply was modified 1 year, 4 months ago by thinkjarvis.
- This reply was modified 1 year, 4 months ago by thinkjarvis.
- This reply was modified 1 year, 4 months ago by thinkjarvis.
August 1, 2023 at 4:18 pm #1415178Hi,
Have a look into enfold\config-relevanssi\class-avia-relevanssi.php
Around line 170 you find:
$tempquery->query_vars = $search_parameters; relevanssi_do_query( $tempquery );
Try the following:
$tempquery->query_vars = $search_parameters; $tempquery->set( 'posts_per_page', 5 ); relevanssi_do_query( $tempquery );
Best regards,
GünterAugust 1, 2023 at 4:31 pm #1415180Hi Gunter,
Sorry crossed wires here.
I have updated my response to your original post.
The second fix enfold\config-relevanssi\class-avia-relevanssi.php seems to workHowever both of your suggestions cause the ajax search to have different results to the search page.
BUT
The longer and more specific the search term – The less this is a problem.I have changed the value to 25 in class-avia-relevanssi.php and also used the css below to control the size of the dropdown:
.ajax_search_response { max-height: 300px; overflow-y: scroll; }
August 1, 2023 at 4:49 pm #1415182Hi,
If this is a solution I can add a filter for next release.
Just let me know.Best regards,
GünterAugust 1, 2023 at 5:24 pm #1415184Hi Gunter,
The filter works as expected when the standard search layout is used – but has thrown another problem.
Please add the filter it is a good solution.I have customised the searchform.php file adding:
<input type=”hidden” name=”post_type” value=”product”>
into the <form> tags.This is causing the search to show different results to the ajax search.
Any idea how I can bring the two into alignment?The search query changes from
/?s=samsung
to
/?s=samsung&post_type=productAugust 1, 2023 at 5:57 pm #1415188I’ve figured out what it is doing.
I am happy with the results please add the filter.August 1, 2023 at 6:01 pm #1415189Hi,
Filter will be in 5.6.6:
searchform.php
This is the default that a form collects all input on submit.
Try this (adding the disabled attribute):
Best regards,
GünterAugust 1, 2023 at 9:17 pm #1415203Thanks Gunter,
The main reason for using Relevanssi for me was a speed improvement (where the SKU is included in the search). Relevanssi creates its own search index which helps keep the lookups quick.
I now have a couple of extremely large woocommerce sites with Enfold that are all running extremely smoothly so Relevanssi is a natural progression to improve search.
August 3, 2023 at 9:12 am #1415310Hi,
Thanks for providing insight into relevanssi and that it helps on large sites and works well with Enfold.
Have a great day.
Best regards,
GünterAugust 3, 2023 at 9:50 am #1415311No problem,
Thanks again for finding a solution to this – really happy with this. I used to use an old script for adding SKUs to the default search however it now uses depreciated code (and it was a slow query) so this is a much better solution.
Can the documentation be updated with the new snippet/filter once 5.6.6 gets released?
There are a few highly ranking Enfold forum entries with the incorrect solution on them. If they are still open to comment I’ll add the new solution to the posts once 5.6.6 is released.
August 3, 2023 at 11:19 am #1415323Hi,
I tagged Yigit for this topic. He will come back to you in case he needs more info for the docu.
We appreciate your help.
Best regards,
GünterAugust 3, 2023 at 12:37 pm #1415328Hey Thomas,
I’ve added a new section to our documentation with the new filter. Please see the link in the private content field.
Regards,
YigitAugust 3, 2023 at 12:50 pm #1415330Thanks Yigit
See comments belowAugust 3, 2023 at 1:36 pm #1415333 -
AuthorPosts
- You must be logged in to reply to this topic.