flexsearch icon indicating copy to clipboard operation
flexsearch copied to clipboard

logic operators are not working

Open a-tonchev opened this issue 4 years ago • 1 comments

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.

a-tonchev avatar Nov 30 '21 19:11 a-tonchev

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'

jordmantheman avatar Oct 13 '22 02:10 jordmantheman