flexsearch icon indicating copy to clipboard operation
flexsearch copied to clipboard

Flatten results

Open robokozo opened this issue 2 years ago • 2 comments

I'm use flexsearch to do some web client side filtering of some objects. While I appreciate getting the search results broken down by the object field that matches, it is often unnecessary in my use cases and I find myself having to flatten and filter my results down to a unique set. I feel like performance can be improved when searching in this proposed mode because flexsearch can ignore already matched items.

Thanks!

robokozo avatar Sep 23 '21 22:09 robokozo

I have the same issue: https://codesandbox.io/s/flexsearch-search-tests-forked-40gk9?file=/src/index.ts

It is not even about performance, but how do I sort those 2 independent arrays of results, if there is no score included in results?

pie6k avatar Oct 11 '21 16:10 pie6k

I have the same issue: https://codesandbox.io/s/flexsearch-search-tests-forked-40gk9?file=/src/index.ts

It is not even about performance, but how do I sort those 2 independent arrays of results, if there is no score included in results?

What I would do is to make 2 indexes. E.g.

const indexContent = new Document({
  id: "id",
  index: ["content"]
});
const indexLol = new Document({
  id: "id",
  index: ["lol"]
});
...

for (const message of messages) {
  indexContent.add(message);
  indexLol.add(message);
}

...

const result = [
  ...indexContent.search({
    query: input,
    index: ["content",]
  }), 
  ...indexLol.search({
    query: input,
    index: ["lol"]
  })
]

Now, that result will look something like this: [ID10, ID123, ID10, ID55] so you as turn this back from identifiers to documents, you use a Set to keep track of which ones you've seen.

peterbe avatar Oct 25 '21 14:10 peterbe

You can also use just one document index. After getting back the result you can merge the fields like the example above.

ts-thomas avatar Oct 02 '22 16:10 ts-thomas