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

Document search with multiple fields #313

Closed benstrum closed 2 years ago

benstrum commented 2 years ago

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
        }
amcclain commented 2 years ago

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

brendanmoore commented 2 years ago

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

ts-thomas commented 2 years ago

This is now fixed in v0.7.23