lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maciej Pestka" <maciej.pes...@wp.pl>
Subject Re: PrecedenceQueryParser usage
Date Wed, 12 Sep 2012 17:26:49 GMT
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




Mime
View raw message