• Hi,

    Thanks for creating this search plugin. ??

    I am having a bit of problem in trying to make the search results more relevant.

    For example, if someone searches for “best herbal soap under”, any posts titled “best herbal soaps under” are not shown at the top of search results. They appear mixed with other relatively less relevant results without any special boost.

    I tried to solve this issue by adding “soap = soaps” to the synonyms. However, it did not have any effect on the rankings.

    I have set the default operator to “AND”, default order to “Relevance” and keyword matching to “Whole Words”.

    These did not seem to have a major impact on the rankings.

    Could you please help me resolve this issue?

    Thanks.

    • This topic was modified 5 years, 2 months ago by 9itish.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Synonyms are not used with the AND operator, they only work with the OR operator. The way synonyms work is that when you search for “soap”, the search becomes “soap soaps”. In an OR search, that expands the search, which is the goal, but in an AND search, it makes the search more constricted. Thus the synonyms are not used in the AND search.

    So, if you want synonyms, you need to use the OR search. Relevanssi Premium can use synonyms in AND searches as well. Premium also includes a simple English-language stemmer that will make “soap” and “soaps” the same word without any need for synonyms.

    Another approach is to add a filter function that will make sure that if the post title has the word “soaps”, Relevanssi will also index it as “soap”. For simple “s” plurals, that’s not particularly complicated (index each word that ends with an “s” also without the “s”).

    Thread Starter 9itish

    (@9itish)

    Thanks Mikko ??

    Could you please point me to a link where I can read more about the filter function? Currently, I don’t make enough money from my website to purchase the premium version of the plugin. ??

    Do I have to make the change somewhere in the plugin code or in my functions.php file?

    Plugin Author Mikko Saari

    (@msaari)

    For titles, you need the relevanssi_post_title_before_tokenize filter hook. Any functions set on that hook (if you don’t know what hooks are, see help here) gets to see and modify the title before Relevanssi indexes it.

    So, you’d want to add a function on that filter hook that reads in the title, sees if there are words that end with “s”, creates versions of the words without the “s” and adds them to the title and returns that.

    You’d do that in the theme functions.php file, yes.

    Thread Starter 9itish

    (@9itish)

    Thanks Mikko ??

    I added the following code to my functions.php file. However, it did not seems to make any difference in the search results.

    
    function rlv_plural_index($title) {
        $title = preg_replace('/(\w+)s\s+/', '$1 $1s ', $title);
        return $title;
    }
    add_filter('relevanssi_post_title_before_tokenize', 'rlv_plural_index');
    

    If I am correct, the above should have changed “best herbal soaps under” in the title to “best herbal soap soaps under” for indexing purposes.

    After uploading the functions.php, I clicked on “Build the Index” in the Relevanssi pluging settings.

    After that, I used the same search query “best herbal soap under” once more but there was no change in the results. Posts with title “best herbal soaps under” were still not appearing at the top. However, they did appear at the top when I searched for “best herbal soaps under”.

    Did I do anything wrong?

    Thanks.

    • This reply was modified 5 years, 2 months ago by 9itish.
    Plugin Author Mikko Saari

    (@msaari)

    Nope, nothing wrong, that should work. I added the function on my test site and it made Relevanssi index “best herbal soaps under” as “best herbal soap soaps under” just as expected.

    You can check how the post is indexed by Relevanssi from the wp_relevanssi database table, the doc column is the post ID. Does the post have the “soap” in the indexed words?

    • This reply was modified 5 years, 2 months ago by Mikko Saari.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search is not working properly with Synonyms and Plurals’ is closed to new replies.