how to parse search string without fields limit in lucene

Viewed 30

For example:

title:lucene+((author:jack)^300.0 (bookname:how to use lucene)^200.0 (price:[100 TO 200])^100.0)~1

Is there anyWay parse the lucene query string to Query Object like Query query = Function(String queryString) in lucene?

1 Answers

You can use the classic QueryParser to build a parser:

QueryParser parser = new QueryParser(default_field_name, analyzer);

If you provide field names in your query string (as you do in your example), then the default field name is not used.

The analyzer should typically be the same as the analyzer which was used to build the index. For example, the StandardAnalyzer:

Analyzer analyzer = new StandardAnalyzer();

And then you can use the string containing your query as follows:

Query query = parser.parse(your_query_string);

The demo code provided as part of Lucene shows an example of this approach. See lines 118 and 135 in the SearchFiles.html code.

Related