deitch/searchjs

Support wildcards in string searching

m1dst opened this issue · 4 comments

m1dst commented

It would be great if you could support some wildcards so that string searches could be more like the SQL LIKE syntax. That would be awesome!

Hi @m1dst . Have you seen text searching? Flag it as _text: true, and it will do case-insensitive, any-part-of-the-word matching. So {_text: true, name: "davi"} is the moral equivalent of /davi/.

Or are you thinking explicitly wildcards, as in a regex? I would be hesitant to throw SQL's syntax in here, as this is a JS lib and is trying to be json-compatible, but I think supporting js RegEx string representatives might work.

How would we flag that it is a RegExp, and not a regular string? E.g. one person is searching for any usage of atterso (from your name), so they look for the RegExp /atterso/i, and the other is looking for the literal string "/atterso/i". I don't think I can use real RegExp (as in /atterso/I) in json without quoting it, so then it is a string all over again.

Nope, I tried, lint gives:

Error: Parse error on line 4:
..."/atterso/i",	"c": /atterso/i}
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

I guess we could use a flag _regexp: true like we have _word and _text?

m1dst commented