lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.83k stars 137 forks source link

Search results found by duplicate value #80

Closed pechischev closed 3 years ago

pechischev commented 3 years ago

I found problem in lib when I tried input duplicate value by value of tag (in a white small box - SC*). I wanted to get an empty result, but no. I think it's a bug.

My current options:

const miniSearch = new MiniSearch({
  idField: 'id',
  fields: ['title', 'ticker'],
  storeFields: ['logo_uri', 'title', 'ticker', 'short_description', 'added', 'id'],
  tokenize: (string, _fieldName) => string.split(' '),
})

...

const result = miniSearch.search(searchValue, {
   prefix: true,
   combineWith: 'AND',
})

I tried using without options, but the result was wrong.

image

lucaong commented 3 years ago

Hi @pechischev , the example you provide seems to work as expected. You are searching for sc1 sc1 sc1 sc1 with prefix search enabled and combining with AND. This search query will be tokenized as ["sc1", "sc1", "sc1", "sc1"].

The combineWith: 'AND' won't have an effect here, because the query translates to: "find all results that match sc1 AND sc1 AND sc1 AND sc1", which is equivalent to "find all results that match sc1".

Therefore it will find all documents that contain terms (in title or ticker) starting with sc1. All the returned results have a ticker that starts in fact with SC1 (SC1, SC13, SC14, SC15, SC16).

What is unexpected to you? Maybe I misunderstood your question, feel free to clarify what the issue is 🙂

lucaong commented 3 years ago

I will close this issue for now, but feel free to comment on it if your problem is not solved.