flexsearch icon indicating copy to clipboard operation
flexsearch copied to clipboard

Search across indexes?

Open erezsh opened this issue 2 years ago • 2 comments

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.

erezsh avatar Nov 05 '21 13:11 erezsh

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

FrancescoBonizzi avatar Feb 28 '22 14:02 FrancescoBonizzi

No, no answer yet.

erezsh avatar Feb 28 '22 15:02 erezsh

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
});

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

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

erezsh avatar Oct 02 '22 16:10 erezsh