Roman,

I'm not familiar with the contrib, but you can write your own Java code to
create Query objects from the tree produced by your lexer and parser
something like this:

StandardLuceneGrammarLexer lexer = new ANTLRReaderStream(new
StringReader(queryString));
CommonTokenStream tokens = new CommonTokenStream(lexer);
StandardLuceneGrammarParser parser = new
StandardLuceneGrammarParser(tokens);
StandardLuceneGrammarParser.query_return ret = parser.mainQ();
CommonTree t = (CommonTree) ret.getTree();
parseTree(t);

parseTree (Tree t) {

// recursively parse the Tree, visit each node

   visit (node);

}

visit (Tree node) {

switch (node.getType()) {
case (StandardLuceneGrammarParser.AND:
// Create BooleanQuery, push onto stack
...
}
}

I use the stack to build up the final Query from the queries produced in the
tree parsing.

Hope this helps.
Peter


On Tue, Sep 13, 2011 at 3:16 PM, Jason Toy <jason...@gmail.com> wrote:

> I'd love to see the progress on this.
>
> On Tue, Sep 13, 2011 at 10:34 AM, Roman Chyla <roman.ch...@gmail.com>
> wrote:
>
> > Hi,
> >
> > The standard lucene/solr parsing is nice but not really flexible. I
> > saw questions and discussion about ANTLR, but unfortunately never a
> > working grammar, so... maybe you find this useful:
> >
> >
> https://github.com/romanchyla/montysolr/tree/master/src/java/org/apache/lucene/queryParser/iqp/antlr
> >
> > In the grammar, the parsing is completely abstracted from the Lucene
> > objects, and the parser is not mixed with Java code. At first it
> > produces structures like this:
> >
> >
> https://svnweb.cern.ch/trac/rcarepo/raw-attachment/wiki/MontySolrQueryParser/index.html
> >
> > But now I have a problem. I don't know if I should use query parsing
> > framework in contrib.
> >
> > It seems that the qParser in contrib can use different parser
> > generators (the default JavaCC, but also ANTLR). But I am confused and
> > I don't understand this new queryParser from contrib. It is really
> > very confusing to me. Is there any benefit in trying to plug the ANTLR
> > tree into it? Because looking at the AST pictures, it seems that with
> > a relatively simple tree walker we could build the same queries as the
> > current standard lucene query parser. And it would be much simpler and
> > flexible. Does it bring something new? I have a feeling I miss
> > something...
> >
> > Many thanks for help,
> >
> >  Roman
> >
>
>
>
> --
> - sent from my mobile
> 6176064373
>

Reply via email to