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

Cannot recognize keyword's array if term contains spaces " " #34

Open terrynguyen255 opened 5 years ago

terrynguyen255 commented 5 years ago

Hi @nepsilon ,

Thank you for your work on this awesome package. I'd like to report an issue I found:

Code:

const parsedParams = advancedSearchParser.parse(
  `sentFrom:"Harry Potter","Hermione Granger","Ron Weasley" you are a wizard`,
  {
    alwaysArray: true,
    keywords: ['sentFrom'],
    offsets: false
  }
);

Reality:

{
  text: ',"Hermione Granger","Ron Weasley you are a wizard',
  sentFrom: [ 'Harry Potter' ],
  exclude: {}
}

Expectation:

{
  text: 'you are a wizard',
  sentFrom: [ 'Harry Potter', 'Hermione Granger', 'Ron Weasley' ],
  exclude: {}
}

These work-around cases work, but sometime we just cannot walk around:

sentFrom:Harry,Hermione,Ron you are a wizard
sentFrom:"Harry Potter" sentFrom:"Hermione Granger" sentFrom:"Ron Weasley" you are a wizard

Thank you for your time.

Pranoy1c commented 5 years ago

@Nogias9x I found that if you change your text to

`sentFrom:"Harry Potter,Hermione Granger,Ron Weasley" you are a wizard`

then it works fine. Aka, remove the double quotes between the names.

terrynguyen255 commented 5 years ago

Thank you for checking it @Pranoy1c .

By now, I'm not having time to check it at my end. But I will. So just close this issue. I will get back to you when I checked it.

Thank you so much and best regards.

terrynguyen255 commented 5 years ago

BTW, I think it'd be great if we have this case update in document. Just my 2 cents :)