nextapps-de / flexsearch

Next-Generation full text search library for Browser and Node.js
Apache License 2.0
12.53k stars 491 forks source link

Search across indexes? #285

Closed erezsh closed 2 years ago

erezsh commented 3 years ago

Currently, the entire search must completely match at least one index.

But the behavior I want is for each part of the search to match one of the indexes, even if they are different.

Here's a code example that demonstrates my problem:

import FlexSearch from 'flexsearch';

function main() {

    let flex = new FlexSearch.Document({
        tokenize: "full",
        document: {
            id: "id",
            index: ["a", "b"],
        }
    });

    flex.add({id: 0, a: "foo", b: "bar"})
    console.log(flex.search('foo'))              // Ok, finds  the item
    console.log(flex.search('bar'))              // Ok, finds the item
    console.log(flex.search('foo bar'))         // Bad, doesn't find the item

}

main()

Is there a way to do it with FlexSearch?

I can split the words myself, search for each one, and then do the intersection on the results myself. But it feels like there should be a better way to do it.

FrancescoBonizzi commented 2 years ago

Did you find an answer? I have the same concern!

erezsh commented 2 years ago

No, no answer yet.

ts-thomas commented 2 years ago

For this purpose the suggestion feature is provided. The order in result is accordingly to the count of matched items.

index.search({
    field: "content",
    query: "some query",
    limit: 100,
    suggest: true
});
erezsh commented 2 years ago

I looked through the README, it contains no explanation of what suggest does.