Skip to main contentSkip to footer

Relevanssi has a minimum word length setting that is set to three characters. Any one- or two-letter words are not indexed unless you change this setting from the Relevanssi advanced indexing settings. Sometimes it would be helpful to ignore short words but to index one- and two-digit numbers.

You can do that with a bit of help. Adjust the minimum word length to 1 or 2 depending on your needs, add this function to your site and rebuild the index:

add_filter( 'relevanssi_remove_punctuation', function( $str) {
    return implode(
        ' ',
        array_filter(
            explode( ' ', $str ),
            function( $word ) {
                if ( relevanssi_strlen( $word ) < 3 ) {
                    return is_numeric( $word );
                }
                return true;
            }
        )
    );
} );

This function will let short numbers through while blocking short words.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Modal search form shortcode

…search restrictions as the regular searchform shortcode. Parameters that are not modal settings are passed to the search form. Search Search this site Search for: will restrict the search form to just products. Search Search this site Search for: will restrict the search form to posts, pages and news. Search…Relevanssi includes a modal search form shortcode that opens the search form in a dialog. The shortcode is relevanssi_modal_search. Search Search this site Search for: will display a “Search” button that opens the modal search form. Changing the labels Use the label parameter to change the text on the button:……Search this site Search for: will restrict the search form to categories 10, 14 and 17. Search Search this site Search for: will do a multisite search on blogs 1, 2 and 3. These parameters are added to the search form as hidden input fields. Adding dropdowns The modal shortcode…

WP Event Manager
Using Relevanssi with WP Event Manager requires you to adjust the search process in WP Event Manager a bit. Fortunately,…

Related Posts:

Comment Section:

3 Comments. Leave new

  • I’m not sure this snippet is working. After adding it to my functions.php file, and rebuilding the index, searching for two-digit numbers still returns “No Results”

    Default view (no search): https://tppr.me/5Ymd1D (notice the two and three-digit office numbers marked on the screenshot)
    Three-digit number search: https://tppr.me/QxdmvB (returns results)
    Two-digit number search: https://tppr.me/Cmlr9c

    Is there a chance that the provided function (that should enable indexing < 3 character words if they are numerical) is not working?

    Reply
    • Daniel, did you also adjust the minimum word length to 2 from the advanced indexing settings?

      The function works for two-digit numbers, but in your case, it’s possible this function runs before the one that removes punctuation, so “2-46” is not a two-digit number when this function runs. Try changing the priority of this function to bigger than 10 (add_filter( 'relevanssi_remove_punctuation', function( $str) {...}, 11 );).

      Reply
      • Hi Mikko, thank you for the prompt reply.

        Changing the priority of the function solved the issue.

        Thanks once again, appreciate the quick response!

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed