SOLR-1067: further progress on the problem with null qparser

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@802424 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2009-08-08 17:20:43 +00:00
parent af828c575d
commit b4acfc32df
9 changed files with 14 additions and 10 deletions

View File

@ -143,7 +143,7 @@ public class FieldAnalysisRequestHandler extends AnalysisRequestHandlerBase {
useDefaultSearchField = false; useDefaultSearchField = false;
} }
if (useDefaultSearchField) { if (useDefaultSearchField) {
analysisRequest.addFieldName(req.getSchema().getSolrQueryParser(null).getField()); analysisRequest.addFieldName(req.getSchema().getDefaultSearchFieldName());
} }
analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q))); analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q)));
analysisRequest.setFieldValue(solrParams.get(AnalysisParams.FIELD_VALUE)); analysisRequest.setFieldValue(solrParams.get(AnalysisParams.FIELD_VALUE));

View File

@ -371,7 +371,7 @@ public class LukeRequestHandler extends RequestHandlerBase
finfo.add("fields", fields); finfo.add("fields", fields);
finfo.add("dynamicFields", dynamicFields); finfo.add("dynamicFields", dynamicFields);
finfo.add("uniqueKeyField", uniqueField.getName()); finfo.add("uniqueKeyField", uniqueField.getName());
finfo.add("defaultSearchField", schema.getSolrQueryParser(null).getField()); finfo.add("defaultSearchField", schema.getDefaultSearchFieldName());
finfo.add("types", types); finfo.add("types", types);
return finfo; return finfo;
} }

View File

@ -73,7 +73,7 @@ public abstract class SolrHighlighter
if(emptyArray(fields)) { if(emptyArray(fields)) {
// use default search field if highlight fieldlist not specified. // use default search field if highlight fieldlist not specified.
if (emptyArray(defaultFields)) { if (emptyArray(defaultFields)) {
String defaultSearchField = request.getSchema().getSolrQueryParser(null).getField(); String defaultSearchField = request.getSchema().getDefaultSearchFieldName();
fields = null == defaultSearchField ? new String[]{} : new String[]{defaultSearchField}; fields = null == defaultSearchField ? new String[]{} : new String[]{defaultSearchField};
} }
else { else {

View File

@ -251,6 +251,7 @@ public final class IndexSchema {
* <solrQueryParser> configuration for this IndexSchema. * <solrQueryParser> configuration for this IndexSchema.
* *
* @param defaultField if non-null overrides the schema default * @param defaultField if non-null overrides the schema default
* @deprecated
*/ */
public SolrQueryParser getSolrQueryParser(String defaultField) { public SolrQueryParser getSolrQueryParser(String defaultField) {
SolrQueryParser qp = new SolrQueryParser(this,defaultField); SolrQueryParser qp = new SolrQueryParser(this,defaultField);
@ -262,9 +263,7 @@ public final class IndexSchema {
/** /**
* Name of the default search field specified in the schema file * Name of the default search field specified in the schema file
* @deprecated use getSolrQueryParser().getField()
*/ */
@Deprecated
public String getDefaultSearchFieldName() { public String getDefaultSearchFieldName() {
return defaultSearchFieldName; return defaultSearchFieldName;
} }

View File

@ -207,7 +207,7 @@ public class DisMaxQParser extends QParser {
protected SolrPluginUtils.DisjunctionMaxQueryParser getParser(Map<String, Float> fields, String paramName, protected SolrPluginUtils.DisjunctionMaxQueryParser getParser(Map<String, Float> fields, String paramName,
SolrParams solrParams, float tiebreaker) { SolrParams solrParams, float tiebreaker) {
int slop = solrParams.getInt(paramName, 0); int slop = solrParams.getInt(paramName, 0);
SolrPluginUtils.DisjunctionMaxQueryParser parser = new SolrPluginUtils.DisjunctionMaxQueryParser(req.getSchema(), SolrPluginUtils.DisjunctionMaxQueryParser parser = new SolrPluginUtils.DisjunctionMaxQueryParser(this,
IMPOSSIBLE_FIELD_NAME); IMPOSSIBLE_FIELD_NAME);
parser.addAlias(IMPOSSIBLE_FIELD_NAME, tiebreaker, fields); parser.addAlias(IMPOSSIBLE_FIELD_NAME, tiebreaker, fields);
parser.setPhraseSlop(slop); parser.setPhraseSlop(slop);

View File

@ -61,7 +61,7 @@ class LuceneQParser extends QParser {
String defaultField = getParam(CommonParams.DF); String defaultField = getParam(CommonParams.DF);
if (defaultField==null) { if (defaultField==null) {
defaultField = getReq().getSchema().getSolrQueryParser(null).getField(); defaultField = getReq().getSchema().getDefaultSearchFieldName();
} }
lparser = new SolrQueryParser(this, defaultField); lparser = new SolrQueryParser(this, defaultField);

View File

@ -64,7 +64,7 @@ public class SolrQueryParser extends QueryParser {
* *
* @param schema Used for default search field name if defaultField is null and field information is used for analysis * @param schema Used for default search field name if defaultField is null and field information is used for analysis
* @param defaultField default field used for unspecified search terms. if null, the schema default field is used * @param defaultField default field used for unspecified search terms. if null, the schema default field is used
* @see IndexSchema#getSolrQueryParser(String defaultField) * @see IndexSchema#getDefaultSearchFieldName()
*/ */
public SolrQueryParser(IndexSchema schema, String defaultField) { public SolrQueryParser(IndexSchema schema, String defaultField) {
super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer()); super(defaultField == null ? schema.getDefaultSearchFieldName() : defaultField, schema.getQueryAnalyzer());

View File

@ -523,6 +523,7 @@ public class SolrPluginUtils {
* NOTE: intra-function whitespace is not allowed. * NOTE: intra-function whitespace is not allowed.
* </p> * </p>
* @see #parseFieldBoosts * @see #parseFieldBoosts
* @deprecated
*/ */
public static List<Query> parseFuncs(IndexSchema s, String in) public static List<Query> parseFuncs(IndexSchema s, String in)
throws ParseException { throws ParseException {
@ -731,7 +732,11 @@ public class SolrPluginUtils {
* DisjunctionMaxQuery and the tiebreaker to use. * DisjunctionMaxQuery and the tiebreaker to use.
*/ */
protected Map<String,Alias> aliases = new HashMap<String,Alias>(3); protected Map<String,Alias> aliases = new HashMap<String,Alias>(3);
public DisjunctionMaxQueryParser(QParser qp, String defaultField) {
super(qp,defaultField);
// don't trust that our parent class won't ever change it's default
setDefaultOperator(QueryParser.Operator.OR);
}
public DisjunctionMaxQueryParser(IndexSchema s, String defaultField) { public DisjunctionMaxQueryParser(IndexSchema s, String defaultField) {
super(s,defaultField); super(s,defaultField);
// don't trust that our parent class won't ever change it's default // don't trust that our parent class won't ever change it's default

View File

@ -133,7 +133,7 @@ public class SolrPluginUtilsTest extends AbstractSolrTestCase {
assertTrue(t+" sanity test isn't TermQuery: " + out.getClass(), assertTrue(t+" sanity test isn't TermQuery: " + out.getClass(),
out instanceof TermQuery); out instanceof TermQuery);
assertEquals(t+" sanity test is wrong field", assertEquals(t+" sanity test is wrong field",
h.getCore().getSchema().getSolrQueryParser(null).getField(), h.getCore().getSchema().getDefaultSearchFieldName(),
((TermQuery)out).getTerm().field()); ((TermQuery)out).getTerm().field());
t = "subject:XXXXXXXX"; t = "subject:XXXXXXXX";