Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Description context – character depth and possibility of multiple contexts?
This topic contains 4 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 5 months ago.
- AuthorPosts
- October 5, 2021 at 10:20 pm #35020
I have two questions about the result description context.
1. Using Apache Tika as described in a previous ticket, I have uploaded some books to my website and I would like for the search results to show the context for matches in the entire document. It appears that the context is limited by the character depth setting, so is there a performance impact from setting the character depth to something like 1 million?
2. Is there a way to have a single result show multiple different contexts? ASP obviously matches all instances of a search term in the entire document, so it would be nice if it could show the separate contexts (all limited to, say, 200 characters) with a user-selectable maximum number of contexts. This is something that is possible with Relevanssi. https://www.relevanssi.com/knowledge-base/multi-part-excerpts/
October 6, 2021 at 2:39 am #35024I should also say that I am open to doing some custom coding for #2 if it seems like something that is feasible and you can guide me.
October 6, 2021 at 9:49 am #35029Hi,
1. Very likely, but you should try it. The function used for that creates an array of words, then tries to match the closest ones. It is the best possible tested solution we could come up with, which works for longer strings (around 10000 characters).
So iterating through a bigger array of strings may lead to memory and processing issues.2. I’m afraid not possible without custom coding. The internal function currently used only matches the first matching context, and then exits. The best possible approach to this would be to simply create a function, which can get a number of matching and non-overlapping contexts, then during the post process replace the result contents via the asp_results hook. Something like:
add_filter('asp_results', 'asp_my_custom_contexts', 10, 1); function asp_my_custom_contexts($results) { foreach ( $results as $k => &$r ) { $p = get_post($r->id); $r->content = my_magic_multiple_context_function($p->post_content); } return $results; } function my_magic_multiple_context_function($s) { // Do the magic here return "extracted contexts.."; }
This would work then after plugin updates too. Maybe there is a way to extraxt the method used by relevanssi from their source code to do this.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 6, 2021 at 10:08 pm #350461. Thanks, I’ll just test it all out then.
2. Thank you. Unfortunately Relevanssi only does this in their Pro version, and I don’t want to buy it just for this purpose, much less buy and return it.
Would you please be able to point me to the internal ASP function that handles this, so that I can use it as a starting point?
October 7, 2021 at 7:25 am #350512. Sure, you can find it in wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search.php
Best,
from line 348 (context_find)
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.