From bbd02d1cf1aa26730035305acdcd8569d8c21d2c Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Wed, 24 Feb 2010 03:00:45 +0000 Subject: [PATCH] SOLR-1776: DismaxQParser and ExtendedDismaxQParser now use the schema.xml defaultSearchField as the default value for the qf param git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@915646 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ src/java/org/apache/solr/search/DisMaxQParser.java | 5 ++++- .../apache/solr/search/ExtendedDismaxQParserPlugin.java | 4 ++++ src/test/org/apache/solr/DisMaxRequestHandlerTest.java | 9 +++++++++ .../org/apache/solr/search/TestExtendedDismaxParser.java | 8 +++++++- src/test/test-files/solr/conf/solrconfig.xml | 2 ++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b5a5e7d0fd9..b5180645d70 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -249,6 +249,10 @@ Other Changes * SOLR-1695: Improved error messages when adding a document that does not contain exactly one value for the uniqueKey field (hossman) +* SOLR-1776: DismaxQParser and ExtendedDismaxQParser now use the schema.xml + "defaultSearchField" as the default value for the "qf" param instead of failing + with an error when "qf" is not specified. (hossman) + Build ---------------------- diff --git a/src/java/org/apache/solr/search/DisMaxQParser.java b/src/java/org/apache/solr/search/DisMaxQParser.java index 79b2516deb5..41c55a62b86 100644 --- a/src/java/org/apache/solr/search/DisMaxQParser.java +++ b/src/java/org/apache/solr/search/DisMaxQParser.java @@ -65,7 +65,10 @@ public class DisMaxQParser extends QParser { public Query parse() throws ParseException { SolrParams solrParams = localParams == null ? params : new DefaultSolrParams(localParams, params); queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.QF)); - + if (0 == queryFields.size()) { + queryFields.put(req.getSchema().getDefaultSearchFieldName(), 1.0f); + } + /* the main query we will execute. we disable the coord because * this query is an artificial construct */ diff --git a/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java b/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java index b6486f29a75..a5bdc263668 100755 --- a/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java +++ b/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java @@ -104,6 +104,10 @@ class ExtendedDismaxQParser extends QParser { SolrParams solrParams = localParams == null ? params : new DefaultSolrParams(localParams, params); queryFields = U.parseFieldBoosts(solrParams.getParams(DMP.QF)); + if (0 == queryFields.size()) { + queryFields.put(req.getSchema().getDefaultSearchFieldName(), 1.0f); + } + // Boosted phrase of the full query string Map phraseFields = U.parseFieldBoosts(solrParams.getParams(DMP.PF)); diff --git a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java b/src/test/org/apache/solr/DisMaxRequestHandlerTest.java index adc79bc6775..4921650db3d 100644 --- a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java +++ b/src/test/org/apache/solr/DisMaxRequestHandlerTest.java @@ -206,6 +206,15 @@ public class DisMaxRequestHandlerTest extends AbstractSolrTestCase { doTestSomeStuff("dismaxOldStyleDefaults"); } + public void testSimplestParams() throws Exception { + populate(); + assertQ("match w/o only q param", + req("qt", "dismaxNoDefaults", + "q","guide") + ,"//*[@numFound='2']" + ); + + } } diff --git a/src/test/org/apache/solr/search/TestExtendedDismaxParser.java b/src/test/org/apache/solr/search/TestExtendedDismaxParser.java index 90df12a05b1..30560c025a3 100755 --- a/src/test/org/apache/solr/search/TestExtendedDismaxParser.java +++ b/src/test/org/apache/solr/search/TestExtendedDismaxParser.java @@ -97,6 +97,12 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase { "q","100"), oner ); + assertQ("qf defaults to defaultSearchField" + , req( "defType", "edismax" + ,"q","op") + , twor + ); + assertQ(req("defType", "edismax", "qf", "name title subject text", "q","op"), twor ); @@ -167,4 +173,4 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase { } -} \ No newline at end of file +} diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xml index 7fb4fe375e6..10bf723afe1 100644 --- a/src/test/test-files/solr/conf/solrconfig.xml +++ b/src/test/test-files/solr/conf/solrconfig.xml @@ -293,6 +293,8 @@ 100 + + 1000 1.4142135