Description context – character depth and possibility of multiple contexts?

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 Ernest Marcinko 7 months, 2 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #35020
    nickchomey18
    nickchomey18
    Participant

    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/

    #35024
    nickchomey18
    nickchomey18
    Participant

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

    #35029
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

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


    #35046
    nickchomey18
    nickchomey18
    Participant

    1. 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?

    #35051
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    2. Sure, you can find it in wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search.php
    from line 348 (context_find)

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.