Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-158: new qs (Query Slop) param for DisMaxRequestHandler

Chris M. Hostetter0aa2a95ee721
diff --git a/CHANGES.txt b/CHANGES.txt
index ebfcdfe3772..30324a17fa0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -115,6 +115,11 @@ New Features
using SolrQueryParser syntax as a mechanism for specifying what query
the dismax handler should execute if the main user query (q) is blank.
(Ryan McKinley via hossman)
+
+15. SOLR-158: new "qs" (Query Slop) param for DisMaxRequestHandler
+ allows for specifying the amount of default slop to use when parsing
+ explicit phrase queries from the user.
+ (Adam Hiatt via hossman)
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
diff --git a/src/java/org/apache/solr/request/DisMaxRequestHandler.java b/src/java/org/apache/solr/request/DisMaxRequestHandler.java
index 6a9dec4c2b0..d227526be12 100644
--- a/src/java/org/apache/solr/request/DisMaxRequestHandler.java
+++ b/src/java/org/apache/solr/request/DisMaxRequestHandler.java
@@ -85,6 +85,9 @@ import org.apache.solr.util.SolrPluginUtils;
* <li> ps - (Phrase Slop) amount of slop on phrase queries built for pf
* fields.
* </li>
+ * <li> ps - (Query Slop) amount of slop on phrase queries explicitly
+ * specified in the "q" for qf fields.
+ * </li>
* <li> bq - (Boost Query) a raw lucene query that will be included in the
* users query to influence the score. If this is a BooleanQuery
* with a default boost (1.0f), then the individual clauses will be
@@ -176,6 +179,7 @@ public class DisMaxRequestHandler extends RequestHandlerBase {
float tiebreaker = params.getFloat(DMP.TIE, 0.0f);
int pslop = params.getInt(DMP.PS, 0);
+ int qslop = params.getInt(DMP.QS, 0);
/* a generic parser for parsing regular lucene queries */
QueryParser p = new SolrQueryParser(schema, null);
@@ -187,7 +191,8 @@ public class DisMaxRequestHandler extends RequestHandlerBase {
new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
up.addAlias(IMPOSSIBLE_FIELD_NAME,
tiebreaker, queryFields);
-
+ up.setPhraseSlop(qslop);
+
/* for parsing slopy phrases using DisjunctionMaxQueries */
U.DisjunctionMaxQueryParser pp =
new U.DisjunctionMaxQueryParser(schema, IMPOSSIBLE_FIELD_NAME);
diff --git a/src/java/org/apache/solr/util/DisMaxParams.java b/src/java/org/apache/solr/util/DisMaxParams.java
index ff8427a2183..edadab54744 100755
--- a/src/java/org/apache/solr/util/DisMaxParams.java
+++ b/src/java/org/apache/solr/util/DisMaxParams.java
@@ -55,8 +55,16 @@ import java.io.IOException;
public static String PF = "pf";
/** query and init param for MinShouldMatch specification */
public static String MM = "mm";
- /** query and init param for Phrase Slop value */
+ /**
+ * query and init param for Phrase Slop value in phrase
+ * boost query (in pf fields)
+ */
public static String PS = "ps";
+ /**
+ * query and init param for phrase Slop value in phrases
+ * explicitly included in the user's query string ( in qf fields)
+ */
+ public static String QS = "qs";
/** query and init param for boosting query */
public static String BQ = "bq";
/** query and init param for boosting functions */
diff --git a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java b/src/test/org/apache/solr/DisMaxRequestHandlerTest.java
index 67976c379db..a9fc84cca29 100644
--- a/src/test/org/apache/solr/DisMaxRequestHandlerTest.java
+++ b/src/test/org/apache/solr/DisMaxRequestHandlerTest.java
@@ -121,6 +121,18 @@ public class DisMaxRequestHandlerTest extends AbstractSolrTestCase {
"facet", "false" )
,"//*[@numFound='0']"
);
+
+ assertQ("no query slop == no match",
+ req( "qt", "dismax",
+ "q", "\"cool chick\"" )
+ ,"//*[@numFound='0']"
+ );
+ assertQ("query slop == match",
+ req( "qt", "dismax",
+ "qs", "2",
+ "q", "\"cool chick\"" )
+ ,"//*[@numFound='1']"
+ );
}
public void testOldStyleDefaults() throws Exception {