Am using Lucene 4.7.2 version.
I have indexed some information and have create a UI to query on that interface. I create a BooleanQuery based on the user input,
example:
BooleanQuery bq = new BooleanQuery();
NumericRangeQuery<Integer> 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());
This prints,
+age[20 TO 30] AND name:einstein
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.
I found this idea of converting BooleanQuery.toString() to String and back to BooleanQuery but am not able to find any API to convert String query to Query type.
use this:
String queryString="Name:alivaliolah";
Query QueryObj=new QueryParser("", perFieldAnalyzor).parse(queryString);
TopDocs topDocFounded = searcher.search(QueryObj, hitsPerPage);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With