nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.49k stars 491 forks source link

Results are not unique when matches in more than one field #38

Closed manuelportela closed 5 years ago

manuelportela commented 5 years ago

I expected to get matching documents to be unique within result. What is the angle for repeating these?

Example:

const f = new FlexSearch({
    doc: {
        id: 'id',
        field: ['field1', 'field2']
    }
})

const docs = [
    {id: 1, field1: 'phrase', field2: 'phrase'}
]

f.add(docs)
console.log(f.search('phrase'))
// Result = [{id: 1, field1: "phrase", field2: "phrase"} 1: {id: 1, field1: "phrase", field2: "phrase"}]
ts-thomas commented 5 years ago

Simply pass field in a custom search:

console.log(f.search('phrase', {field: 'field1'}));
console.log(f.search('phrase', {field: 'field2'}));

Edit: the uniqueness is actually a bug and will be fixed soon. Thanks for the hint.

manuelportela commented 5 years ago

Overlapping with your answer: That works indeed, but in my case I want all results that have a match somewhere but I only care for the matching document to appear once in the result. I can manage by filtering afterwards, but this could clash when using a limit search. Why do you return the resulting docs more then once?

ts-thomas commented 5 years ago

This issue refers to: https://github.com/nextapps-de/flexsearch/milestone/7 The merging of results from different fields provides this issue actually and should be fixed with this milestone.

ts-thomas commented 5 years ago

This issue is fixed (v0.5.2).