Creating a parser for the Lucene query syntax

Apr 29, 2014 at 12:41 PM
I'm attempting to use Irony to make a parser for the Lucene Query Syntax (see links at the end for more info). The current version of my grammar is here https://gist.github.com/mattwarren/11398785.

As a starting point, I'm trying to make it make this BNF definition:
Query -> Clause (And Clause | Or Clause | NotClause | Clause)*;
NotClause -> Not Clause;
Clause -> (SubClause | Term);
SubClause -> (PLUS Query) | (MINUS Query) | (OPEN_PAREN Query CLOSE_PAREN);

Term -> Range | QualifiedTerm | UnqualifiedTerm;
QualifiedTerm -> FIELD_NAME ( Range | TEXT_VALUE | STRING_LITERAL );
Range -> OPEN_SQUARE UnqualifiedTerm TO UnqualifiedTerm CLOSE_SQUARE;
UnqualifiedTerm -> (STRING_LITERAL | TEXT_VALUE);
But I'm struggling with the definition of the top-level query, I'm not sure how to properly make (optional) BinaryExpressions, with an implied OR operator. Can anyone give me any pointers?

These are the queries I'm currently testing with:
  • title:(+return +"pink panther")
  • "jakarta apache" -"Apache Lucene"
  • (jakarta OR apache) AND website
  • jakarta apache website matt name:bob age:123
  • +(Term:bar Term2:baz) +Term3:foo -Term4:rob
  • mod_date:[20020101 TO 20030101] Name:bob
  • title:(Do AND it)
  • title:"Do it right" AND (right:go OR matt:no)
There is some info on the grammar in these links:
  1. http://lucene.apache.org/core/2_9_4/queryparsersyntax.html
  2. https://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html
  3. https://lucene.apache.org/core/3_5_0/api/contrib-queryparser/org/apache/lucene/queryParser/standard/StandardQueryParser.html
Coordinator
Apr 29, 2014 at 4:29 PM
Look at FullTextSearch grammar sample, your grammar seems similar to FTS/Google search language, start from this grammar