Closed robokozo closed 2 years ago
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?
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.
You can also use just one document index. After getting back the result you can merge the fields like the example above.
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!