Wednesday, February 22, 2006

Apache Lucene - Query Parser Syntax - Apache Lucene

Apache Lucene - Query Parser Syntax - Apache Lucene: "Although Lucene provides the ability to create your own queries through its API, it also provides a rich query language through the Query Parser.

This page provides syntax of Lucene's Query Parser, a lexer which interprets a string into a Lucene Query using JavaCC.

Before choosing to use the provided Query Parser, please consider the following:

1. If you are programmatically generating a query string and then parsing it with the query parser then you should seriously consider building your queries directly with the query API. In other words, the query parser is designed for human-entered text, not for program-generated text.
2. Untokenized fields are best added directly to queries, and not through the query parser. If a field's values are generated programmatically by the application, then so should query clauses for this field. An analyzer, which the query parser uses, is designed to convert human-entered text to terms. Program-generated values, like dates, keywords, etc., should be consistently program-generated.
3. In a query form, fields which are general text should use the query parser. All others, such as date ranges, keywords, etc. are better added directly through the query API. A field with a limit set of values, that can be specified with a pull-down menu should not be added to a query string which is subsequently parsed, but rather added as a TermQuery clause."