title: Which special characters need escaping in a solr query?
body: <p><strong>Update:</strong> I <em>think</em> this question has to do with solr syntax in general, and not Chef in particular. So while I ran into this working with Chef, I presume that anyone working with Solr will also experience this...</p>
  
  <hr>
  
  <p>I'm working on an application that communicates with the Chef server's search API to find particular nodes.</p>
  
  <p>Based on this <a href="http://docs.opscode.com/essentials_search.html#special-characters">http://docs.opscode.com/essentials_search.html#special-characters</a>, it seems that a number of special characters need to be escaped.</p>
  
  <p><strong>Note:</strong> I'm only concerned with exact-matching patterns, <em>not</em> wildcards. I realize that the reason some of these characters are wildcards.</p>
  
  <p>Here's the list at the time of this writing, as copied from the URL above:</p>
  
  <pre><code>+  -  &amp;&amp;  | |  !  ( )  { }  [ ]  ^  "  ~  *  ?  :  \
  </code></pre>
  
  <p>When I try various <code>knife search</code> commands with these characters, however, I see inconsistent behaviour.</p>
  
  <p>For the following examples, I set up a node that is tagged with <code>+&amp;|!(){}[]^\"~*?:\\"</code></p>
  
  <p><em>These commands were run from a Linux box, in a bash shell:</em></p>
  
  <pre><code>$ knife search node 'tags:+&amp;|!(){}[]^"~*?:\'
  ERROR: knife search failed: invalid search query: 'tags:+&amp;|!(){}[]^"~*?:\'
  </code></pre>
  
  <p>That behaved as expected, since nothing was escaped. Now, I escape everything with a single <code>\</code> as the docs suggest:</p>
  
  <pre><code>$ knife search node 'tags:\+\&amp;\|\!\(\)\{\}\[\]\^\"\~\*\?\:\\'
  ERROR: knife search failed: invalid search query: 'tags:\+\&amp;\|\!\(\)\{\}\[\]\^\"\~\*\?\:\\'
  </code></pre>
  
  <p>Strange.</p>
  
  <p>Can anyone shed some light on this, and maybe suggest a query that's capable of matching that tag?</p>
  
  <p>It's obviously unlikely that anyone will ever have an attribute containing all those special characters, but I'd like to understand better how the special characters should be escaped.</p>
  
  <p>Thanks!</p>