FAQ
Hi,
I want to write my own query expander. It needs to obtain the AST
(abstract syntax tree) of an already parsed query string, navigate to
certain parts of it (words) and make logical phrases of those words by
adding to the AST - where necessary.

This cannot be done to the string because the query logic cannot be
semantically altered. (e.g. AND, OR, paren's etc) so it must be parsed
first.

How can this be done with SolrJ?

thanks for any tips.
Darren

Search Discussions

  • Mike Sokolov at May 31, 2011 at 7:09 pm
    I believe there is a query parser that accepts queries formatted in XML,
    allowing you to provide a parse tree to Solr; perhaps that would get you
    the control you're after.

    -Mike
    On 05/31/2011 02:24 PM, darren@ontrenet.com wrote:
    Hi,
    I want to write my own query expander. It needs to obtain the AST
    (abstract syntax tree) of an already parsed query string, navigate to
    certain parts of it (words) and make logical phrases of those words by
    adding to the AST - where necessary.

    This cannot be done to the string because the query logic cannot be
    semantically altered. (e.g. AND, OR, paren's etc) so it must be parsed
    first.

    How can this be done with SolrJ?

    thanks for any tips.
    Darren

  • Darren at May 31, 2011 at 7:18 pm
    Hi, thanks for the tip. I noticed the XML stuff, but the trouble is I am
    taking a query string entered by a user such as "this OR that AND (this
    AND that)" so I'm not sure how to go from that to a representational AST
    parse tree...
    I believe there is a query parser that accepts queries formatted in XML,
    allowing you to provide a parse tree to Solr; perhaps that would get you
    the control you're after.

    -Mike
    On 05/31/2011 02:24 PM, darren@ontrenet.com wrote:
    Hi,
    I want to write my own query expander. It needs to obtain the AST
    (abstract syntax tree) of an already parsed query string, navigate to
    certain parts of it (words) and make logical phrases of those words by
    adding to the AST - where necessary.

    This cannot be done to the string because the query logic cannot be
    semantically altered. (e.g. AND, OR, paren's etc) so it must be parsed
    first.

    How can this be done with SolrJ?

    thanks for any tips.
    Darren

  • Jonathan Rochkind at May 31, 2011 at 7:26 pm
    You're going to have to parse it yourself. Or, since Solr is open
    source, you can take pieces of the existing query parsers (dismax or
    lucene), and repurpose them. But I don't _think_ (I could be wrong)
    there is any public API in Solr/SolrJ that will give you an AST.
    On 5/31/2011 3:18 PM, darren@ontrenet.com wrote:
    Hi, thanks for the tip. I noticed the XML stuff, but the trouble is I am
    taking a query string entered by a user such as "this OR that AND (this
    AND that)" so I'm not sure how to go from that to a representational AST
    parse tree...
    I believe there is a query parser that accepts queries formatted in XML,
    allowing you to provide a parse tree to Solr; perhaps that would get you
    the control you're after.

    -Mike
    On 05/31/2011 02:24 PM, darren@ontrenet.com wrote:
    Hi,
    I want to write my own query expander. It needs to obtain the AST
    (abstract syntax tree) of an already parsed query string, navigate to
    certain parts of it (words) and make logical phrases of those words by
    adding to the AST - where necessary.

    This cannot be done to the string because the query logic cannot be
    semantically altered. (e.g. AND, OR, paren's etc) so it must be parsed
    first.

    How can this be done with SolrJ?

    thanks for any tips.
    Darren

  • Lboutros at May 31, 2011 at 9:31 pm
    Hi Darren,

    I think that if I had to get the parsing result, I would create my own
    QueryComponent which would create the parser in the 'prepare' function (you
    can take a look to the actual QueryComponent class) and instead of resolving
    the query in the 'process' function, I would just parse the query and then
    it should be possible to serialize the returned Query object to the
    response.

    Then you could declare this new query component in the solr config file.
    And finally, with solrj, you should be able to get the parsed query in the
    response, unserialize it and do your stuff ;)

    The Query object could be considered as an AST, I think :).

    This is how I would start, if I had to do that.

    Ludovic.



    -----
    Jouve
    France.
    --
    View this message in context: http://lucene.472066.n3.nabble.com/Obtaining-query-AST-tp3007289p3008330.html
    Sent from the Solr - User mailing list archive at Nabble.com.
  • Lboutros at May 31, 2011 at 9:38 pm
    Darren,

    you can even take a look to the DebugComponent which returns the parsed
    query in a string form.
    It uses the QueryParsing class to parse the query, you could perhaps do the
    same.

    Ludovic.

    -----
    Jouve
    France.
    --
    View this message in context: http://lucene.472066.n3.nabble.com/Obtaining-query-AST-tp3007289p3008349.html
    Sent from the Solr - User mailing list archive at Nabble.com.
  • Darren Govoni at May 31, 2011 at 9:50 pm
    Ludovic,
    Thank you for this tip, it sounds useful.

    Darren
    On Tue, 2011-05-31 at 14:38 -0700, lboutros wrote:

    Darren,

    you can even take a look to the DebugComponent which returns the parsed
    query in a string form.
    It uses the QueryParsing class to parse the query, you could perhaps do the
    same.

    Ludovic.

    -----
    Jouve
    France.
    --
    View this message in context: http://lucene.472066.n3.nabble.com/Obtaining-query-AST-tp3007289p3008349.html
    Sent from the Solr - User mailing list archive at Nabble.com.
  • Renaud Delbru at May 31, 2011 at 9:56 pm
    Hi,

    have a look at the flexible query parser of lucene (contrib package)
    [1]. It provides a framework to easily create different parsing logic.
    You should be able to access the AST and to modify as you want how it
    can be translated into a Lucene query (look at processors and pipeline
    processors).
    One time you have your own query parser, then it is straightforward to
    plug it into Solr.

    [1] http://lucene.apache.org/java/3_1_0/api/contrib-queryparser/index.html
    --
    Renaud Delbru
    On 31/05/11 19:24, darren@ontrenet.com wrote:
    Hi,
    I want to write my own query expander. It needs to obtain the AST
    (abstract syntax tree) of an already parsed query string, navigate to
    certain parts of it (words) and make logical phrases of those words by
    adding to the AST - where necessary.

    This cannot be done to the string because the query logic cannot be
    semantically altered. (e.g. AND, OR, paren's etc) so it must be parsed
    first.

    How can this be done with SolrJ?

    thanks for any tips.
    Darren
  • Darren Govoni at Jun 1, 2011 at 11:40 am
    Thats pretty awesome. Thanks Renaud!
    On Tue, 2011-05-31 at 22:56 +0100, Renaud Delbru wrote:

    Hi,

    have a look at the flexible query parser of lucene (contrib package)
    [1]. It provides a framework to easily create different parsing logic.
    You should be able to access the AST and to modify as you want how it
    can be translated into a Lucene query (look at processors and pipeline
    processors).
    One time you have your own query parser, then it is straightforward to
    plug it into Solr.

    [1] http://lucene.apache.org/java/3_1_0/api/contrib-queryparser/index.html

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsolr-user @
categorieslucene
postedMay 31, '11 at 6:24p
activeJun 1, '11 at 11:40a
posts9
users5
websitelucene.apache.org...

People

Translate

site design / logo © 2022 Grokbase