nepsilon / search-query-parser

A simple parser for advanced search query syntax
https://www.npmjs.org/package/search-query-parser
MIT License
253 stars 40 forks source link

The "alwaysArray" option doesn't apply to "exclude" #27

Open davidmz opened 5 years ago

davidmz commented 5 years ago

See example at: https://runkit.com/davidmz/5c86c4ecc72b580012f955eb

I expect that it should be exclude: {in: ["space"]} but got exclude: {in: "space"}

nepsilon commented 5 years ago

Thanks for the report. Would you want to provide a PR handling this case?

nepsilon commented 5 years ago

Thanks @rschick 👍 Merged and published as v1.5.1.

LordMike commented 3 years ago

Hey - with 1.6.0, I'm seeing the following:

searchQueryParse('-banana', {tokenize: true, offsets: false})
{
    "exclude": {
        "text": "banana"
    }
}

searchQueryParse('-banana', {tokenize: true, offsets: false, alwaysArray: true})
{
    "exclude": {
        "text": "banana"
    }
}

But doing multiple values works:

searchQueryParse('-banana -baddie', {tokenize: true, offsets: false})
{
    "exclude": {
        "text": [
            "banana",
            "baddie"
        ]
    }
}
nepsilon commented 3 years ago

Thanks @LordMike , I confirm I see the same issue. I added 4 more tests in #50 , 2 of them are failing due to this bug. I don't have time to work on this at the moment but will follow up on the PR if anyone can help out.