1

I have entry titles that contain dashes (i.e. ABC-123). When I search for 'ABC', 'ABC-123', 'ABC 123', '123' etc the entry is shown in the results (I have fuzzy search enabled). However, when I search for 'ABC123' or anything with the dash omitted from the query the entry does not appear in the results. The same goes for misspellings (i.e. 'ABB-123').

Is there a way for search to return a result that is only a partial match to the query to take into account slight differences between the query and a page title?

Please note that I have the following fuzzy search config settings:

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

And I have the following search query template code:

{% set query = craft.request.getParam('q')|replace('/(( )+|(\\n)+)/', ' ')|split(' ')|join(' OR ') %}

1 Answer 1

0

Is there a way for search to return a result that is only a partial match to the query to take into account slight differences between the query and a page title?

Not natively.

When you put a title of "ABC-123" into a title in Craft, it will normalize it down to " abc 123 " when putting it into the craft_searchindex table (lowercasing all letter and removing punctuation). And Craft does a similar thing for searches (lowercases them and removes punctuation).

With subLeft and subRight enabled, searching for ABC turns it into a MySQL fulltext search with wildcards on the left and right... i.e. LIKE '%abc%' so it will match what's in the search_index table.

Likewise ABC-123 gets converted to %abc 123%, which will match, ABC 123 also gets converted to %abc 123%, which will match and 123 into %123% which will match.

ABC123 would get converted to %abc123% which wouldn't match (nor would ABB-123.

MySQL does have a SOUNDEX() method, which might do what you're looking for, but it does have enough drawbacks that Craft wouldn't use it natively.

i.e. it won't work against full text indexes, inconsistent results in non-English languages and inconsistent results with multi-byte characters (even if they are UTF-8).

Some other search services might offer more robust solutions (Algolia, Apache Lucere, etc.) that you could wrap with a plugin for searches on the front-end of a Craft site, but you should add a thumbs-up comment to this Github issue if you'd like the ability for plugins to swap out the core search provider that Craft uses wholesale (including for the Control Panel).

1
  • Thanks for the help Brad. Your feedback confirmed what I had been thinking about the limitations of what we should expect to be able to do with the built-in search Jun 15, 2017 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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