flexsearch icon indicating copy to clipboard operation
flexsearch copied to clipboard

Document search with multiple fields

Open benstrum opened this issue 3 years ago • 1 comments

I am trying to get Document searching to work using an array of criteria as the first param. From the documentation, it appears you should be able to do something like this:

index.search([{
    field: "content",
    query: "some query",
    limit: 100,
    suggest: true
},{
    field: "content",
    query: "some other query",
    limit: 100,
    suggest: true
}]);

However, the issue appears to be that the code for Document.search does not properly set the query variable in the loop here:

https://github.com/nextapps-de/flexsearch/blob/master/src/document.js#L552

Thus query is null when the code gets here: https://github.com/nextapps-de/flexsearch/blob/master/src/document.js#L552

res = this.index[key].search(query, limit, opt || options);

I believe this can easily be fixed by doing the following

for(let i = 0, res, key, len; i < field.length; i++){

        let opt;

        key = field[i];

        if(!is_string(key)){

            opt = key;
            key = key["field"];
            query = key["query"];  // (NEW) set the query variable
        }

benstrum avatar Feb 24 '22 16:02 benstrum

I had the same question - believe this has already been asked via #257, which remains unanswered.

amcclain avatar Mar 24 '22 23:03 amcclain

I had the same question - believe this has already been asked via #257, which remains unanswered.

There is also this: https://github.com/nextapps-de/flexsearch/issues/264 and this mystery https://github.com/nextapps-de/flexsearch/pull/277

I have a feeling the git history has been lost for this fix

brendanmoore avatar Sep 23 '22 14:09 brendanmoore

This is now fixed in v0.7.23

ts-thomas avatar Oct 03 '22 10:10 ts-thomas