title: How to Serialize Lucene Query or convert query to String and back to Query
body: <p>Am using Lucene 4.7.2 version.</p>
  
  <p>I have indexed some information and have create a UI to query on that interface. I create a BooleanQuery based on the user input,</p>
  
  <p>example:</p>
  
  <pre><code>BooleanQuery bq = new BooleanQuery();
  NumericRangeQuery&lt;Integer&gt; nrq = NumericRangeQuery.newIntRange("age", 20, 30, true, true);
  bq.add(nrq, BooleanClause.Occur.MUST);
  
  Term term = new Term("name", "einstein");
  TermQuery termQuery = new TermQuery(term);
  bq.add(termQuery, BooleanClause.Occur.MUST);
  
  System.out.println(bq.toString());
  </code></pre>
  
  <p>This prints,</p>
  
  <pre><code>+age[20 TO 30] AND name:einstein
  </code></pre>
  
  <p>Lucene runs on a separate server and it expects Query object to perform search. As the Query or BooleanQuery is not serializable, am trying to convert above String query across and convert it to Query/Boolean object.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/13699209/why-query-termquery-etc-are-not-longer-implementing-serializable-in-lucene-4-0">this idea of converting BooleanQuery.toString() to String and back to BooleanQuery</a> but am not able to find any API to convert String query to Query type.</p>