1

I am struggling to get my head around plurals and fuzzy search etc.

I have seen this article, which seems to help answer this but am hoping someone can clarify based on my scenario Search forms handling of plurals

If i search commerce products for 'sponge' i seem to get results that the word's 'sponge' and also 'sponges' which is great.

If I search for 'sponges' I get the 'sponges' results but ALSO I thought I would get the singular 'sponge' results, but this does not seem to be the case. This is what I want to achieve - is this possible?

In config I have:

    'defaultSearchTermOptions' => array( 
        'subLeft' => true,
        'subRight' => true,
    ),

//////////////////////////////////

Can anyone clarify what results i should expect or I am doing something wrong?

Thanks Malcolm

1

This is the expected behaviour. To say that the native search in Craft has support for plurals, is a stretch. What the search options indicate is whether or not to allow for extra characters to the left and right in the indexed keywords, when searching for a term.

So, if "sponges" is indexed, "sponges", "sponge", "spon", or "pong", would result in a match when using 'subLeft' => true and 'subRight' => true. If they were false, only "sponges" would match.

If the indexed word is "sponge" and you search for "sponges", there will be no matches because "sponges" is not a subset of "sponge".

If you want more advanced search capabilities, you need to integrate some kind of third-party search engine like Algolia.

1

Agree with André's answer, Craft does support fuzzy search, which is what you have setup.

If you are looking for better search capabilities, agreed that Algolia would be the best suit, you can use the Scout plugin to support pushing content to your index. It is getting support for PHP 8 very shortly too. You can then use this in multiple ways, not only to just show results, you can easily incorporate autocomplete or for more out-the-box filtering you can incorporate Algolia's InstantSearch.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.