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 Anirudha Jadhav <an...@nyu.edu> on 2012/11/29 22:35:36 UTC
surround parser not working for span queries
I was trying to port surround parer in 4.0 to 3.5
After getting the plugin to work I am not able to get the following results:
http://localhost:8983/solr/collection1/select?q=_query_:{!surround}features:(document3w
shiny)
this works on 4.0 but not on 3.5 with the plugin installed
3.5 query
http://localhost:8983/solr/select?q=_query_:{!surround}features:(document3w
shiny)
queries with and/or/not work correctly.
any suggestion as to what might be the problem ?
thanks,
code
-------------
import org.apache.lucene.queryParser.surround.query.SrndQuery;
import org.apache.lucene.queryParser.ParseException;//import
org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Query;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.SnapPuller;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.IndexSchema;
import org.apache.lucene.queryParser.surround.parser.*;
import org.apache.lucene.queryParser.surround.query.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* porting solr 4.0 surround parser to 3.5
*/
public class SurroundQParserPlugin extends QParserPlugin {
public static String NAME = "surround";
@Override
public void init(NamedList args) {
}
@Override
public QParser createParser(String qstr, SolrParams localParams,
SolrParams params, SolrQueryRequest req) {
return new SurroundQParser(qstr, localParams, params, req);
}
}
class SurroundQParser extends QParser {
protected static final Logger LOG = LoggerFactory
.getLogger(SurroundQParser.class);
static final int DEFMAXBASICQUERIES = 1000;
static final String MBQParam = "maxBasicQueries";
String sortStr;
SolrQueryParser lparser;
int maxBasicQueries;
public SurroundQParser(String qstr, SolrParams localParams,
SolrParams params, SolrQueryRequest req) {
super(qstr, localParams, params, req);
}
@Override
public Query parse()
throws org.apache.lucene.queryParser.ParseException {
SrndQuery sq;
String qstr = getString();
if (qstr == null)
return null;
String mbqparam = getParam(MBQParam);
if (mbqparam == null) {
this.maxBasicQueries = DEFMAXBASICQUERIES;
} else {
try {
this.maxBasicQueries = Integer.parseInt(mbqparam);
} catch (Exception e) {
LOG.warn("Couldn't parse maxBasicQueries value " + mbqparam +",
using default of 1000");
this.maxBasicQueries = DEFMAXBASICQUERIES;
}
}
// ugh .. colliding ParseExceptions
try {
sq = org.apache.lucene.queryParser.surround.parser.QueryParser
.parse(qstr);
} catch (org.apache.lucene.queryParser.surround.parser.ParseException
pe) {
throw new org.apache.lucene.queryParser.ParseException(
pe.getMessage());
}
// so what do we do with the SrndQuery ??
// processing based on example in LIA Ch 9
BasicQueryFactory bqFactory = new
BasicQueryFactory(this.maxBasicQueries);
String defaultField =
getDefaultField(getReq().getSchema(),getParam(CommonParams.DF));
Query lquery = sq.makeLuceneQueryField(defaultField, bqFactory);
return lquery;
}
public static String getDefaultField(final IndexSchema s, final String
df) {
return df != null ? df : s.getDefaultSearchFieldName();
}
}
--
Anirudha P. Jadhav