Closed FrancescoBonizzi closed 2 years ago
You will need to apply logical operator manually to the result (like union):
const index = new Document({
preset: 'match',
tokenize: 'full',
language: 'it',
resolution: 1,
charset: 'latin:advanced',
document: {
id: 'id',
index: ['id', 'brand', 'name'],
},
});
index.add({ id: 0, brand: "oreo", name: 'biscuit' });
index.add({ id: 1, brand: "barilla", name: 'biscuit' });
const result = index.search([{
field: "brand",
query: "oreo"
},{
field: "name",
query: "biscuit"
}]);
const union = [...new Set(...result.map(res => res.result))];
console.log(union);
While I understand the reason to leave this to the implementer, there are also strong ones to implement it internally:
limit
(and the performance costs it'd incurs to artificially increase it).Searching for results having two or more terms across all distinct Document fields is a must-have and should be possible without having to ressort to individual inefficient OR-ed queries.
Consider this index definition:
I add the items to the document like this:
When i search for 'oreo' or 'biscuit' I get the correct results, but what I want to achieve is that a query
oreo biscuit
gives me the object with id 1, but in my configuration it doesn't return anything.How can I do it? Thanks.