Closed amir20 closed 4 months ago
Hi @amir20 ,
MiniSearch provides exact match, prefix match, and fuzzy match. In your case, to match work
in worker
, you want to use prefix match, which is enabled by the prefix
search option:
index.search('work', { prefix: true })
Which correctly returns:
[
{
id: 'clashleaders_worker',
score: 0.5736936071097007,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_worker'
},
{
id: '2ccd0d8d390d',
score: 0.5219485808434806,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_worker.3',
host: 'clashleaders.com'
},
{
id: 'd5ebaf1db23e',
score: 0.5219485808434806,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_worker.2',
host: 'clashleaders.com'
},
{
id: '9174709bfdfd',
score: 0.5219485808434806,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_worker.1',
host: 'clashleaders.com'
},
{
id: 'clashleaders_rq_calculation_worker',
score: 0.4821054773767198,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_rq_calculation_worker'
},
{
id: 'f8e46128f172',
score: 0.45048148169779756,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_rq_calculation_worker.1',
host: 'clashleaders.com'
},
{
id: '709a529ef23c',
score: 0.45048148169779756,
terms: [ 'worker' ],
queryTerms: [ 'work' ],
match: { worker: [Array] },
name: 'clashleaders_rq_war_worker.1',
host: 'clashleaders.com'
}
]
Note that you still won't be able to match at arbitrary positions inside a term, like leaders
in clashleaders
. If you need that too, one possibility is to do what explained here: https://github.com/lucaong/minisearch/issues/194#issuecomment-1369229601
It basically amounts to indexing all suffixes of a field, then applying prefix search. This will result in a larger index, but will solve your use case in a performant way, and it is a reasonable solution for short fields.
I hope this helps
Missed the response. Thanks.
That makes sense. I was coming from fuse.js
. I don't think this was super clear to me reading the documentation.
I have a few dozen containers that I am trying to search. I am searching by name and host fields.
I would expect this to return all documents that have the word
work
but it returns[]
.My package.json