title: JavaScript library for search engine style searching?
body: <p>Is there a JavaScript library that can determine if a string matches a search query? It should be efficient and provide advanced query functionality like that of Google or LexisNexis (things like and/or operators, synonyms, and parentheses). Any kind of advanced search features would be great; it doesn't have to be an exact match to any particular search engine.</p>
  
  <p>Motivation: I have an HTML page with a search box followed by a bunch of paragraphs (which have unique ids and are generated from a JavaScript array). When the user types a search query in the box and presses enter, all paragraphs should be hidden (i.e. their <code>display</code> set to <code>none</code>) if they don't match the query.</p>
  
  <p>My current strategy (using jQuery):</p>
  
  <ol>
  <li>Separate the query string into an array of keywords by splitting it over whitespace.</li>
  <li>Hide all paragraphs with <code>$('p').hide()</code>.</li>
  <li>For each keyword, show a paragraph containing it with <code>$('p:contains("'+keyword+'")').show()</code>.</li>
  </ol>
  
  <p>Which is an extremely limited search feature that is case-sensitive, treats all keywords as optional, and doesn't provide operators like <code>and</code>, <code>or</code>, or parentheses. It's also inefficient because it goes through each string once for each keyword even if it has already been matched.</p>