solrsap-commerce-cloudsolrjsolrcloudhybris-data-hub

Hybris SOLR Text, fuzzy, wildcard and phrase Free text query


I'm trying to customize the Search of Hybris disabling some attributes like 'manufactureName' and enabling others to work in the Search autocomplete and spellcheck, however, for example: I find that there are multiple "attributes" for the SolrSearchQueryProperty "manufacturerName":

enter image description here

enter image description here

enter image description here

enter image description here

What mean all of these attributes (free text, fuzzy text, wildcard and phrase)?


Solution

  • Based on this configuration, the solr query will be built for a search on solr. If at least one of these types is set to true, that type of query will be added in the query. If multiple are set to true, all will be appended to the search query.

    General parameters

    Boost

    With the boost parameter, you can configure that a match for this type will account for a better match. For example, if something matches exactly, you usually want this to appear higher then when it's a close match, so you add a larger boost here.

    Min length

    You also have the min length parameter. This defines the minimum number of characters that should be entered before this type of search is activated. You could define that before the fuzzy search activates, that you need to enter a minimum of 5 characters. This is to prevent some search types to return to much results with a low amount of characters

    What do the types mean

    Suppose for the examples we have a solr index with 3 entries for the manufactureName field: test, testing, real test. All examples are against the manufactureName field.

    Free Text Query

    This an exact match search. Only when the exact keyword is found in the solr index, you will get a result. Do note that this does not mean it has to match the entire value. In the case of real test solr considers real and test separate keywords. If you would search for multiple keywords, for example on "real test" solr would search for the keyword "real" and the keyword "test"

    Solr Query

    (manufactureName_text : test)

    Result

    test
    real test
    

    Free Text Wildcard Query

    As the name states, this is a wildcard search. Meaning that you can enter a part of your search term. With the wildcard type you can determine where the wildcard will be placed in the search. Do you want a full wildcard, or only at the end.

    Solr query with postFix query type

    (manufactureName_text : test*)
    

    Result

    test
    testing
    real test
    

    Free Text Fuzzy Query

    Fuzzy queries are used when you allow for mistakes in your searches. This means that you will also match search keywords that have a few wrong characters. The fuzzyness factor determines how much can be wrong for the result to show up. Note that the fuzzy search does not have wildcards. It behaves more like an exact match

    Solr Query with 1 character wrong

    (manufactureName_text : tast∼)
    

    Result

    test
    real test
    

    Free Text Phrase Query

    Last we have a Text Phrase Search. With a phrase search, we also take the spaces into account, not just the keywords. With phrase search, you have the possibility to enter a slop factor. Sloppiness defines the maximum number of positions that characters can be moved to still find a match. This is to still find results if the search differs a bit from the results. with a slop factor of 2, test real would give a match with real test, because with 1 position switch, we can find the result.

    Solr Query

    (manufactureName_text:"real test")
    

    Result

    real test
    

    Combining

    If you activate multiple search styles, all of these solr query parts are appended with an OR. With the boost rules, and calculations in solr, the most matching items will be shown at the top of the result list. Basically you decide what type of searches you allow, and how they should affect the results that are returned

    Example query with Free Text Query and Free Text Phrase query active

    (manufactureName_text : real) OR (manufactureName_text : test) OR (manufactureName_text:"real test")

    Result

    real test
    test