You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Maciej Pestka <ma...@wp.pl> on 2012/09/10 15:47:54 UTC
PrecedenceQueryParser usage
Hi,
I noticed there is class
http://lucene.apache.org/core/4_0_0-BETA/queryparser/org/apache/lucene/queryparser/flexible/precedence/PrecedenceQueryParser.html
it says that:
This query parser works exactly as the standard query parser ( StandardQueryParser ), except that it respect the boolean precedence, so <a AND b OR c AND d> is parsed to <(+a +b) (+c +d)> instead of <+a +b +c +d>.
This is exactly feature that I need.
Could anyone give me example how to configure my SOLR instance to use this parser?
Regards
Maciej Pestka
Re: PrecedenceQueryParser usage
Posted by Maciej Pestka <ma...@wp.pl>.
Thank you!
It seems to me that I managed to get it work.
Just for future reference short I attach source code. The jar should be placed under core/lib folder:
Please let me know if you have any comments or if I got sth incorrect...
public class PrecedenceQParserPlugin extends QParserPlugin {
private static final Logger LOG = LoggerFactory.getLogger(PrecedenceQParserPlugin.class);
@Override
public void init(NamedList list) {
}
@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
LOG.debug("creating new PrecedenceQParser:", new Object[] {qstr, localParams, params, req});
return new PrecedenceQParser(qstr, localParams, params, req);
}
}
class PrecedenceQParser extends QParser {
private static final Logger LOG = LoggerFactory.getLogger(PrecedenceQParser.class);
private final PrecedenceQueryParser parser;
public PrecedenceQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
super(qstr, localParams, params, req);
this.parser = new PrecedenceQueryParser();
}
@Override
public Query parse() throws ParseException {
LOG.debug("parse(): ", qstr);
if (null==qstr) {
return null;
}
final String defaultField = QueryParsing.getDefaultField(getReq().getSchema(),getParam(CommonParams.DF));
try {
return parser.parse(qstr, defaultField);
} catch (QueryNodeException e) {
throw new ParseException(e.getMessage(), e);
}
}
}
Best Regards
Maciej Pestka
Dnia 10-09-2012 o godz. 17:46 Ahmet Arslan napisał(a):
> > In order for Solr to use this parser,
> > you'll need to wrap it with a QParser and QParserPlugin
> > implementations, then wire your implementation into
> > solrconfig.xml.
>
> SurroundQParserPlugin.java (api-4_0_0-BETA) can be an example of such
> implementation.
>
> http://lucene.apache.org/solr/api-4_0_0-BETA/org/apache/solr/search/SurroundQParserPlugin.html
Re: PrecedenceQueryParser usage
Posted by Ahmet Arslan <io...@yahoo.com>.
> In order for Solr to use this parser,
> you'll need to wrap it with a QParser and QParserPlugin
> implementations, then wire your implementation into
> solrconfig.xml.
SurroundQParserPlugin.java (api-4_0_0-BETA) can be an example of such implementation.
http://lucene.apache.org/solr/api-4_0_0-BETA/org/apache/solr/search/SurroundQParserPlugin.html
Re: PrecedenceQueryParser usage
Posted by Erik Hatcher <er...@gmail.com>.
In order for Solr to use this parser, you'll need to wrap it with a QParser and QParserPlugin implementations, then wire your implementation into solrconfig.xml. There is no current built in support for this parser in Solr at the moment.
Erik
On Sep 10, 2012, at 09:47 , Maciej Pestka wrote:
> Hi,
>
> I noticed there is class
> http://lucene.apache.org/core/4_0_0-BETA/queryparser/org/apache/lucene/queryparser/flexible/precedence/PrecedenceQueryParser.html
>
> it says that:
> This query parser works exactly as the standard query parser ( StandardQueryParser ), except that it respect the boolean precedence, so <a AND b OR c AND d> is parsed to <(+a +b) (+c +d)> instead of <+a +b +c +d>.
>
> This is exactly feature that I need.
> Could anyone give me example how to configure my SOLR instance to use this parser?
>
> Regards
> Maciej Pestka
>
>