underscore.string icon indicating copy to clipboard operation
underscore.string copied to clipboard

Added multi-term search function, with tests

Open gregmac opened this issue 11 years ago • 0 comments

Multi-term (AND) search of one or more source strings.

I'm using it in a single-page app to allow the user to filter a number of objects (representing websites) by the text they enter, searching in multiple properties of the objects (URL and site name). This allows the user to enter, for example, "test1 widget" and find the object {url:'test1.w-co.net',name:'Widget Inc - Test Site 1'}.

eg: Successful searches:

_.search('foo bar','match foo this bar')
_.search('foo bar',['here is foo','here is bar'])

Note, I have a dependency on underscorejs, specifically, this uses _.isArray, _.every, and _.some. I just use them, so it will fail if underscorejs isn't loaded. Is there a better/desired way to handle this?

Possible Todo's:

  • Add a case-insensitive option. In my use now, I just call .toLowerCase() before passing.

gregmac avatar Jun 27 '13 03:06 gregmac