Group Details Private

administrators

Member List

  • How to modify word-break behaviour of the indexing engine?

    Sometimes it is necessary to change the behavior of the indexing engine when breaking the text into separate words (you may be more familiar with the word "tokenization").

    For example, you want to make it so that SKU numbers that contain periods, minuses, or spaces are perceived by the search engine as a whole. Let's say the article number "EBR-001-567" should be found only on the substrings "EBR" or "EBR-001", but never on the substrings "56" or "567".

    By default, the indexer tokenizer of the WPFTS treats minus as a separator, so it will place three different words "EBR", "001", "567" in the index, and even though the phrase "EBR 001 567" will still have priority in the search (since the engine gives a bonus of relevance to whole phrases), it will still be possible to find "567" or "001" separately, which is unacceptable in our case.

    In order to overcome this problem, we must change the behavior of the tokenizer so that the minus is no longer a word separator. Note that this can be solved in at least two ways: a simple one - to exclude the minus from the list of separators for the entire text and a complex one - to calculate which words are articles and turn off the breakdown only for them.

    Here's some sample code we could use to follow a simple script.

    It uses two regular expressions to split the text (they are very similar, but actually different - look carefully!)

    add_filter('wpfts_split_to_words', function($words, $text)
    {
        // The context stores useful information about current post and cluster
        global $wpfts_context;
        
        // Check if we are in the indexing stage
        if ($wpfts_context && ($wpfts_context->index_post > 0)) {
                // Ok, we are indexing now
                // Let's apply different rules for post_title and any other cluster
                if ($wpfts_context->index_token == 'post_title') {
                    // The part number can be in the title, using the rule where "minus" is NOT a divider
                    $rule = "~([\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w][\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w'\-]*[\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w]+|[\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w]+)~u";
                } else {
                    // Other parts of the document will be broken assuming "minus" is a divider
                    $rule = "~([\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w][\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w']*[\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w]+|[\x{00C0}-\x{1FFF}\x{2C00}-\x{D7FF}\w]+)~u";
                }
    
                // Finally let's make a split
                $matches = false;
                preg_match_all($rule, $text, $matches);
                if (isset($matches[1])) {
                    $words = $matches[1];
                } else {
                    $words = array();
                }
        }
      
        return $words;
    });
    

    Yes, it may look a bit complex, but actually nothing too hard to understand.

    posted in Recipes and Known Solutions
  • [Solved] Does not show Smart Excerpt with Total Theme

    Another try by the Total Theme developers to make their own "excerpt" generator hardly replaces the integrated native WP's the_excerpt() method. This is a reason why we can't see Smart Excerpt output in search results when using Total Theme.

    How to fix that? Fortunately, the theme developers allowed us to redefine their generator with our own using hooks.

    Please open your functions.php from the theme root and add this code to the beginning of the file.

    add_filter('wpex_excerpt_output', function($output, $params)
    {
    	ob_start();
    	the_excerpt();
    	return ob_get_clean();
    }, 10, 2); 
    
    

    It should help definitely. If you're not familiar with PHP coding and don't want to modify the theme code, you can download and install this addon plugin (which does the same).

    Download WPFTS Addon for Total Theme

    posted in Recipes and Known Solutions
  • RE: Very slow search query on large wordpress site

    @jwktje Actually this flag is disabled by default. We know about the disasters it can make. Should be you or someone else who has an access to admin switched it ON occasionally.

    Thank you.

    posted in Bugs and Fixes
  • RE: Very slow search query on large wordpress site

    @jwktje Please check if you have "Deep Search" flag set ON at the WPFTS Settings / Search & Output page. If so, try to check it OFF.

    Also, there may be some limitations with your hoster (for example they limited CPU resources for you in case your website is too heavy for shared hosting etc).

    We have an experimental WPFTS version which makes faster search - we could try this too.

    posted in Bugs and Fixes
  • RE: Very slow search query on large wordpress site

    @jwktje Which version of WPFTS you are using?

    posted in Bugs and Fixes
  • [Solved] The plugin shows wrong results for search with BeTheme template

    When you're using the BeTheme theme on your website, you may notice that sometimes the search gives really strange results.

    It happens because the BeTheme has its own implementation of the search (which is very poor, btw). This search algorithm only searches queried words in post titles and post contents which gives fewer results than the WPFTS Pro search and also does not search in attachment contents etc. This BeTheme algorithm automatically disables itself in case the search query is too complex (and it can not find anything) and this is a place where WPFTS Pro becomes working freely. As a result, you can see an only small amount of results for simple queries and a lot more results for complex queries.

    To solve this problem, we need to add this simple line of the code to the functions.php of the BeTheme (or child theme).

    function mfn_search( $search_query ) { return false; }; 
    

    This code overrides the internal "genius" search algorithm of BeTheme so it never runs.

    Hope this helps!

    posted in Recipes and Known Solutions
  • RE: [Solved] Divi theme Smart Excerpts when using Builder template

    In the newer versions of Divi, the line number should be 1881. Other things as before.

    E20200901-164836-001[1].png

    posted in Recipes and Known Solutions
  • RE: PDF Search Results: Titles and Excerpts

    Hi @Nick

    Did you solve the issue? I think we can extract the title from the PDF metadata. Just a little script will be required for that.

    Let me know if you still looking for a solution.

    Thanks!

    posted in Recipes and Known Solutions
  • RE: Default Search Logic (AND / OR) broken since Version 1.28.75

    Hi Charles @clapierre

    We just released v1.35.96 which should have the AND/OR issue fixed. Could you check it?

    Thanks! ✋

    posted in Bugs and Fixes
  • RE: Sorry no posts match your criteria

    Hi @teri-sahm

    It looks like this message is generated by some other plugin or maybe "auto-suggestion" feature of the theme. Could you try to check if there is an option in the theme settings or some AJAX Search plugin? Could you try to disable it?

    Thank you for this report!

    posted in Recipes and Known Solutions