NopLunr – (5) Loose Matching with Fuzzy Search / Wildcard Search

By default, nopLunr uses “phrase matching” algorithm using Porter Stemmer as the stemming algorithm and BM25 as the scoring (result sorting) algorithm.

It’s okay if you don’t understand what is “stemming” and “scoring”, you just need to know that – nopLunr returns search results with consideration of:

  1. Grammatical tenses. For example, “searching”, “searched”, “searchable” and “search” are considered a match.
  2. Singular / Plural. For example, “apples” and “apple” are considered a match, as well as “men” and “man”.
  3. Terms frequency. The more a search term occurs in a product, the more that term will increase that product’s score. But, the more a search term occurs in other products, the less that term will increase a product’s score. For example, if you have 10 products, each of them has some occurrence of the keyword “apple” (you are a fruit stall), then the keyword “apple” will not receive high score. However, if you have one product named “Sweet Fuji Apple from Japan”, searching “apple fuji” will return this product as the first result (highest score), because the keyword “fuji” only appear in one of the 10 products.

On top of the default “phrase matching” algorithm, you can also choose to relax the search criteria using 2 methods:

  1. Fuzzy Search. Fuzzy search works by “edit distance”. An “edit distance of 1″ allows words to match if either adding, removing, changing or transposing one character in the word would lead to a match. For example, “book” requires a single edit (replacing “k” with “t”) to match “boot”; or a single edit (replacing I with “c”) to match “cook”. In nopLunr, if this setting is turned on, an edit distance of 1 is used.
  2. Wildcard Search. A wildcard is represented as an asterisk (*) and can appear anywhere in a search term. When an asterisk appears, it means it can match anything in that particular location. For example, “foo*” would match “foodie”, “*test” would match “attest” and “*limb*” would match “climbing”. In nopLunr, if this setting is turned on, 2 asterisks will be added ot the search term, one in front and one at the back.

Powered by BetterDocs