jeancroy / FuzzySearch

:mag: Fast autocomplete suggestion engine using approximate string matching
MIT License
194 stars 32 forks source link

Highlight exact search query #22

Open goliney opened 5 years ago

goliney commented 5 years ago

Characters that are not present in a search query get highlighted:

Code

import FuzzySearch from 'fz-search'; // v1.0.0

const nodes = [
  {
    value: 'primer'
  },
];

const fuzzy = new FuzzySearch({
  source: nodes,
  keys: 'value',
});

const [result] = fuzzy.search('pre').map(
  item => fuzzy.highlight(item.value)
);

console.log(result);

Actual result

<strong class="highlight">prime</strong>r

primer

Expected result

<strong class="highlight">pr</strong>im<strong class="highlight">e</strong>r

primer

Problem

As you can see, symbols im aren't present in a search query, but they are still highlighted.

Is it possible to avoid highlighting of symbols that are not present in a search query?

jeancroy commented 5 years ago

Sorry for late reply. Gap filling is a feature for less tech savy that prefer word and word-part than bag of letters. However it's optional, set this to 0:

highlight_bridge_gap: 0, // default 2