flexsearch
flexsearch copied to clipboard
logic operators are not working
Somehow it does not matter if I use the
const searchQueries = [{
field: 'productDescription',
query: '17',
bool: 'and',
}, {
field: 'ean',
query: '17',
bool: 'and',
}];
or
const searchQueries = {
field: ['productDescription', 'ean'],
query: '17',
bool: 'and',
};
It always show all possible documents where any of both fields has 17 in it.
Came here to report a similar (or the same) issue.
import { Document as FlexDocument } from 'flexsearch'
// @ts-expect-error flex-search 0.7.x doesn't have types defined
const foo = new FlexDocument({
worker: true,
document: {
id: 'id',
tag: 'tag',
},
})
foo.add({ id: '0', tag: ['a', 'b'] })
foo.add({ id: '1', tag: ['a', 'c'] })
console.log(foo.search({ tag: ['a', 'c'], bool: 'and' }))
Result:
[
{
"tag": "a",
"result": [
"0",
"1"
]
},
{
"tag": "c",
"result": [
"1"
]
}
]
From the docs, I'm not really sure what the combined result set should look like... but it's pretty explicit about how it should only return results that contain both tags. In this case: '1'