search-string
search-string copied to clipboard
Whitelisting conditions
Great job on this library!
One thing: it seems important to support a whitelist of conditions. What if I wanted to search for text that had colons in it? Let's say a book is called "Foobar: The story of Steve", and a user tries to search for that phrase? You'll currently strip Foobar: out of the text.
Most query DSLs will have a specific set of conditions that are valid. search-query-parser shows their usage here. It would make sense to ignore anything else, imo.
I guess you'd need a breaking change that looked something like this: parse(string, { config })
@braco sorry for the delay. Thanks for the kind words and advice! I think that currently works by wrapping that text in quotes e.g.:
const str = 'title:"Foobar: The story of Steve"';
const searchString = SearchString.parse(str);
Then we do not strip out the : as a delimiter. See this repl example.
Does that make sense?
That does make sense, but I think it's asking too much of the user. It would depend on the application, but in this particular one and Google who normalized this parameter style, these are advanced/discoverable features.
I built a wrapper that tries to restore the original query text, but the word order can't be guaranteed, so it's not ideal. Without doing that, words would just fall into a black hole.
Thinking about it, I guess an ignoreEmptyParameters: true feature would help if nothing else. That way "param: " would be parsed as regular text...?
@braco sorry not totally following. Mind adding a PR with some tests that show the behavior you're looking for?