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 Chris Hostetter <ho...@fucit.org> on 2011/11/02 00:28:51 UTC
Re: Lucene queries to Solr requestHandler
: I have these queries in Lucene 2.9.4, is there a way to convert these
: exactly to Solr 3.4 but using only the solrconfig.xml? I will figure out the
: queries but I wanted to know if it is even possible to go from here to
: having something like this:
:
: <requestHandler name="/custom" class="solr.SearchHandler">
: ... queries
: </requestHandler>
:
: So the front end just calls /custom?q=what and the requestHandler will build
: the queries accordingly.
the simplest way to go about something like this is to implement a
QParserPlugin for each little bit of custom logic you have for building a
query from user input. then register each QParserPlugin with a name, and
configure a handler instance with an invariant "defType" set to that name.
so for example: assume all the java code you mentioned in your email to
build up a query was implemented in a method you had with a signature that
looked like this...
public static Query myQueryParserHelper(final String userInput)
...you would wrap that method in a QParserPlugin like so...
public class FieldQParserPlugin extends QParserPlugin {
public void init(NamedList args) {
}
@Override
public QParser createParser(String qstr, SolrParams localParams,
SolrParams params, SolrQueryRequest req) {
return new QParser(qstr, localParams, params, req) {
@Override
public Query parse() throws ParseException {
String queryText = localParams.get(QueryParsing.V);
return myQueryParserHelper(queryText);
}
};
}
}
...and then your configuration would look something like...
<queryParser name="customQP" class="com.mycompany.MyQParserPlugin"/>
<requestHandler name="/custom" class="solr.SearchHandler">
<lst name="invariants">
<str name="defType">customQP</str>
</lst>
</requestHandler
-Hoss
Re: Lucene queries to Solr requestHandler
Posted by Chris Hostetter <ho...@fucit.org>.
Grrr.... cut/paste mistake.
This...
: public class FieldQParserPlugin extends QParserPlugin {
...should have been something like...
public class MyQParserPlugin extends QParserPlugin {
...to match the configuration example...
<queryParser name="customQP" class="com.mycompany.MyQParserPlugin"/>
-Hoss