Support » Plugin: Relevanssi - A Better Search » Exact queries with single digits

  • Resolved JD


    In response to your request to have me open a new ticket, here it is.

    You asked:

    If you can give a link to your site, that would be helpful, and please do searches in the Dashboard > Admin search for “workbook lesson” and “workbook lesson 2” and please report if the results are different or exactly the same.

    I added the link to my site to this topic and tested out the queries as you suggested. Here’s what I found:

    Query: “Workbook Lesson”
    – Results in WP admin area: Workbook Lesson 1, Workbook Lesson 2, Workbook Lesson 3, Workbook Lesson 4, etc.
    – Results with Relevanssi on frontend of the site: Workbook Lesson 193, Workbook Lesson 132. Workbook Lesson 151, Workbook Lesson 154, Workbook Lesson 158, etc.

    Query: “Workbook Lesson 2”
    – Results in WP admin area: Workbook Lesson 2, Workbook Lesson 20, Workbook Lesson 21, Workbook Lesson 22, Workbook Lesson 23, etc.
    – Results with Relevanssi on frontend of the site Workbook Lesson 200, Workbook Lesson 26, Workbook Lesson 28, Workbook Lesson 24, Workbook Lesson 23, Workbook Lesson 25, Workbook Lesson 21, Workbook Lesson 20, Workbook Lesson 29, Workbook Lesson 2, etc.

    The other thing you suggested was:

    The main problem here is that “2” is just not a good search term at all, and in order to get the title match to jump up to the top you need something like this:

    I have to say, I get why you say that “2” is not a good search term, but I think that really depends on the website. My website offers a book online and we want people to be able to use the search function to be able to find the lessons in this book, by for example, using the query that I’ve been testing with, “workbook lesson 2”. So, for my site, “2” is in fact a good search term—especially when paired with “workbook lesson”.

    I added the code provided on the page you linked, however, it didn’t change anything regarding the search results for “workbook lesson 2”.

    Thank you for your continued help!!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari


    It may be a useful search term, but it’s not a good search term, because it’s so popular, that’s just what I’m saying.

    Anyway, looks like the problem here is partial matching. If you switch to whole word matching (see the “Keyword matching” setting on the Searching tab of Relevanssi settings), you should probably get cleaner results. Am I right?

    Now you may need partial matching for other reasons. I think it might be a good idea to change Relevanssi behaviour a bit – I don’t think one-word search terms should do partial matching.

    If you’re running Relevanssi 4.2.0, you can try this version of lib/search.php:

    This version won’t use partial matching for one-letter search terms. That should help.



    Hi Mikko,

    Thank you for explaining why it’s not a good search term. It makes sense now 😉

    I checked the “Keyword matching” setting on the Searching tab of Relevanssi settings, and it’s already been set to “Whole words” for this whole time. Should I still try out the new version of the lib/search.php file?

    Thank you!

    Plugin Author Mikko Saari


    Well, it won’t help then, but if Relevanssi is not doing partial matching, I’m not sure why the lesson numbers are all starting with 2 then.

    Anyway, now that I looked at your content, yeah, those single digits are even worse: your all posts have numbered verses, so all of those lesson posts will match to all single-digit numbers.

    Were you using Relevanssi Premium, I would recommend the new “content stopwords” feature: you could make the single digits stopwords in post content only. However, you can achieve something similar with the free version as well. Try listing all the single digit numbers as stopwords and add this to your theme functions.php and then rebuild the index:

    add_filter( 'relevanssi_remove_stopwords_in_titles', '__return_false' );

    This will deindex the single digit numbers everywhere except your titles.



    Hi Mikko,

    I decided to undo all the work I did since nothing seemed to help my situation substantially. Then I tested some hooks individually.

    Right now, I am using only the add_filter( 'relevanssi_block_one_letter_searches', '__return_false' ); hook filter and nothing else… and somehow everything is working as it should now! Little confusing but happy it’s working now.

    I can search for “workbook lesson 2” and “lesson 2” and I get only one search result that shows lesson 2.

    Thank you for all the help!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exact queries with single digits’ is closed to new replies.