mirror of https://github.com/apache/lucene.git
SOLR-3351: eDismax: ps2 and ps3 params
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1352726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a2e8a95f6a
commit
59313cd115
|
@ -366,6 +366,8 @@ New Features
|
||||||
to schema.xml's <copyField/> declaration but as an update processor that can
|
to schema.xml's <copyField/> declaration but as an update processor that can
|
||||||
be combined with other processors in any order. (Jan Høydahl & hossman)
|
be combined with other processors in any order. (Jan Høydahl & hossman)
|
||||||
|
|
||||||
|
* SOLR-3351: eDismax: ps2 and ps3 params (janhoy)
|
||||||
|
|
||||||
* SOLR-3542: Add WeightedFragListBuilder for FVH and set it to default fragListBuilder
|
* SOLR-3542: Add WeightedFragListBuilder for FVH and set it to default fragListBuilder
|
||||||
in example solrconfig.xml. (Sebastian Lutze, koji)
|
in example solrconfig.xml. (Sebastian Lutze, koji)
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* This parser was originally derived from DismaxQParser from Solr.
|
|
||||||
* All changes are Copyright 2008, Lucid Imagination, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.solr.search;
|
package org.apache.solr.search;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -52,7 +47,8 @@ import org.apache.solr.schema.FieldType;
|
||||||
import org.apache.solr.util.SolrPluginUtils;
|
import org.apache.solr.util.SolrPluginUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An advanced multi-field query parser.
|
* An advanced multi-field query parser based on the DisMax parser.
|
||||||
|
* See Wiki page http://wiki.apache.org/solr/ExtendedDisMax
|
||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
*/
|
*/
|
||||||
public class ExtendedDismaxQParserPlugin extends QParserPlugin {
|
public class ExtendedDismaxQParserPlugin extends QParserPlugin {
|
||||||
|
@ -135,20 +131,25 @@ class ExtendedDismaxQParser extends QParser {
|
||||||
|
|
||||||
queryFields = DisMaxQParser.parseQueryFields(req.getSchema(), solrParams);
|
queryFields = DisMaxQParser.parseQueryFields(req.getSchema(), solrParams);
|
||||||
|
|
||||||
|
// Phrase slop array
|
||||||
|
int pslop[] = new int[4];
|
||||||
|
pslop[0] = solrParams.getInt(DisMaxParams.PS, 0);
|
||||||
|
pslop[2] = solrParams.getInt(DisMaxParams.PS2, pslop[0]);
|
||||||
|
pslop[3] = solrParams.getInt(DisMaxParams.PS3, pslop[0]);
|
||||||
|
|
||||||
|
|
||||||
// Boosted phrase of the full query string
|
// Boosted phrase of the full query string
|
||||||
List<FieldParams> phraseFields =
|
List<FieldParams> phraseFields =
|
||||||
U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF),0);
|
U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF),0,pslop[0]);
|
||||||
// Boosted Bi-Term Shingles from the query string
|
// Boosted Bi-Term Shingles from the query string
|
||||||
List<FieldParams> phraseFields2 =
|
List<FieldParams> phraseFields2 =
|
||||||
U.parseFieldBoostsAndSlop(solrParams.getParams("pf2"),2);
|
U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF2),2,pslop[2]);
|
||||||
// Boosted Tri-Term Shingles from the query string
|
// Boosted Tri-Term Shingles from the query string
|
||||||
List<FieldParams> phraseFields3 =
|
List<FieldParams> phraseFields3 =
|
||||||
U.parseFieldBoostsAndSlop(solrParams.getParams("pf3"),3);
|
U.parseFieldBoostsAndSlop(solrParams.getParams(DMP.PF3),3,pslop[3]);
|
||||||
|
|
||||||
|
|
||||||
float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);
|
float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);
|
||||||
|
|
||||||
int pslop = solrParams.getInt(DisMaxParams.PS, 0);
|
|
||||||
int qslop = solrParams.getInt(DisMaxParams.QS, 0);
|
int qslop = solrParams.getInt(DisMaxParams.QS, 0);
|
||||||
|
|
||||||
// remove stopwords from mandatory "matching" component?
|
// remove stopwords from mandatory "matching" component?
|
||||||
|
@ -332,11 +333,10 @@ class ExtendedDismaxQParser extends QParser {
|
||||||
|
|
||||||
// full phrase and shingles
|
// full phrase and shingles
|
||||||
for (FieldParams phraseField: allPhraseFields) {
|
for (FieldParams phraseField: allPhraseFields) {
|
||||||
int slop = (phraseField.getSlop() == 0) ? pslop : phraseField.getSlop();
|
|
||||||
Map<String,Float> pf = new HashMap<String,Float>(1);
|
Map<String,Float> pf = new HashMap<String,Float>(1);
|
||||||
pf.put(phraseField.getField(),phraseField.getBoost());
|
pf.put(phraseField.getField(),phraseField.getBoost());
|
||||||
addShingledPhraseQueries(query, normalClauses, pf,
|
addShingledPhraseQueries(query, normalClauses, pf,
|
||||||
phraseField.getWordGrams(),tiebreaker, slop);
|
phraseField.getWordGrams(),tiebreaker, phraseField.getSlop());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.solr.search;
|
||||||
**/
|
**/
|
||||||
public class FieldParams {
|
public class FieldParams {
|
||||||
private final int wordGrams; // make bigrams if 2, trigrams if 3, or all if 0
|
private final int wordGrams; // make bigrams if 2, trigrams if 3, or all if 0
|
||||||
private final int slop; // null defaults to ps parameter
|
private final int slop;
|
||||||
private final float boost;
|
private final float boost;
|
||||||
private final String field;
|
private final String field;
|
||||||
public FieldParams(String field, int wordGrams, int slop, float boost) {
|
public FieldParams(String field, int wordGrams, int slop, float boost) {
|
||||||
|
|
|
@ -434,9 +434,10 @@ public class SolrPluginUtils {
|
||||||
*
|
*
|
||||||
* @param fieldLists - an array of Strings eg. <code>{"fieldOne^2.3", "fieldTwo", fieldThree~5^-0.4}</code>
|
* @param fieldLists - an array of Strings eg. <code>{"fieldOne^2.3", "fieldTwo", fieldThree~5^-0.4}</code>
|
||||||
* @param wordGrams - (0=all words, 2,3 = shingle size)
|
* @param wordGrams - (0=all words, 2,3 = shingle size)
|
||||||
|
* @param defaultSlop - the default slop for this param
|
||||||
* @return - FieldParams containing the fieldname,boost,slop,and shingle size
|
* @return - FieldParams containing the fieldname,boost,slop,and shingle size
|
||||||
*/
|
*/
|
||||||
public static List<FieldParams> parseFieldBoostsAndSlop(String[] fieldLists,int wordGrams) {
|
public static List<FieldParams> parseFieldBoostsAndSlop(String[] fieldLists,int wordGrams,int defaultSlop) {
|
||||||
if (null == fieldLists || 0 == fieldLists.length) {
|
if (null == fieldLists || 0 == fieldLists.length) {
|
||||||
return new ArrayList<FieldParams>();
|
return new ArrayList<FieldParams>();
|
||||||
}
|
}
|
||||||
|
@ -454,7 +455,7 @@ public class SolrPluginUtils {
|
||||||
String[] fieldAndSlopVsBoost = caratPattern.split(s);
|
String[] fieldAndSlopVsBoost = caratPattern.split(s);
|
||||||
String[] fieldVsSlop = tildePattern.split(fieldAndSlopVsBoost[0]);
|
String[] fieldVsSlop = tildePattern.split(fieldAndSlopVsBoost[0]);
|
||||||
String field = fieldVsSlop[0];
|
String field = fieldVsSlop[0];
|
||||||
int slop = (2 == fieldVsSlop.length) ? Integer.valueOf(fieldVsSlop[1]) : 0;
|
int slop = (2 == fieldVsSlop.length) ? Integer.valueOf(fieldVsSlop[1]) : defaultSlop;
|
||||||
Float boost = (1 == fieldAndSlopVsBoost.length) ? 1 : Float.valueOf(fieldAndSlopVsBoost[1]);
|
Float boost = (1 == fieldAndSlopVsBoost.length) ? 1 : Float.valueOf(fieldAndSlopVsBoost[1]);
|
||||||
FieldParams fp = new FieldParams(field,wordGrams,slop,boost);
|
FieldParams fp = new FieldParams(field,wordGrams,slop,boost);
|
||||||
out.add(fp);
|
out.add(fp);
|
||||||
|
|
|
@ -659,5 +659,46 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase {
|
||||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc\"~3^333.0')]",
|
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx cccc\"~3^333.0')]",
|
||||||
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc vvvv\"~3^333.0')]"
|
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"xxxx cccc vvvv\"~3^333.0')]"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assertQ(
|
||||||
|
"ps2 not working",
|
||||||
|
req("q", "bar foo", "qf", "phrase_sw", "pf2", "phrase_sw^10", "ps2",
|
||||||
|
"2", "bf", "boost_d", "fl", "score,*", "defType", "edismax"),
|
||||||
|
"//doc[1]/str[@name='id'][.='s0']");
|
||||||
|
|
||||||
|
assertQ(
|
||||||
|
"Specifying slop in pf2 param not working",
|
||||||
|
req("q", "bar foo", "qf", "phrase_sw", "pf2", "phrase_sw~2^10", "bf",
|
||||||
|
"boost_d", "fl", "score,*", "defType", "edismax"),
|
||||||
|
"//doc[1]/str[@name='id'][.='s0']");
|
||||||
|
|
||||||
|
assertQ(
|
||||||
|
"Slop in ps2 parameter should override ps",
|
||||||
|
req("q", "bar foo", "qf", "phrase_sw", "pf2", "phrase_sw^10", "ps",
|
||||||
|
"0", "ps2", "2", "bf", "boost_d", "fl", "score,*", "defType",
|
||||||
|
"edismax"), "//doc[1]/str[@name='id'][.='s0']");
|
||||||
|
|
||||||
|
assertQ(
|
||||||
|
"ps3 not working",
|
||||||
|
req("q", "a bar foo", "qf", "phrase_sw", "pf3", "phrase_sw^10", "ps3",
|
||||||
|
"3", "bf", "boost_d", "fl", "score,*", "defType", "edismax"),
|
||||||
|
"//doc[1]/str[@name='id'][.='s1']");
|
||||||
|
|
||||||
|
assertQ(
|
||||||
|
"Specifying slop in pf3 param not working",
|
||||||
|
req("q", "a bar foo", "qf", "phrase_sw", "pf3", "phrase_sw~3^10", "bf",
|
||||||
|
"boost_d", "fl", "score,*", "defType", "edismax"),
|
||||||
|
"//doc[1]/str[@name='id'][.='s1']");
|
||||||
|
|
||||||
|
assertQ("ps2 should not override slop specified inline in pf2",
|
||||||
|
req("q", "zzzz xxxx cccc vvvv",
|
||||||
|
"qf", "phrase_sw",
|
||||||
|
"pf2", "phrase_sw~2^22",
|
||||||
|
"ps2", "4",
|
||||||
|
"defType", "edismax",
|
||||||
|
"debugQuery", "true"),
|
||||||
|
"//str[@name='parsedquery'][contains(.,'phrase_sw:\"zzzz xxxx\"~2^22.0')]"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,12 @@ public interface DisMaxParams {
|
||||||
/** query and init param for phrase boost fields */
|
/** query and init param for phrase boost fields */
|
||||||
public static String PF = "pf";
|
public static String PF = "pf";
|
||||||
|
|
||||||
|
/** query and init param for bigram phrase boost fields */
|
||||||
|
public static String PF2 = "pf2";
|
||||||
|
|
||||||
|
/** query and init param for trigram phrase boost fields */
|
||||||
|
public static String PF3 = "pf3";
|
||||||
|
|
||||||
/** query and init param for MinShouldMatch specification */
|
/** query and init param for MinShouldMatch specification */
|
||||||
public static String MM = "mm";
|
public static String MM = "mm";
|
||||||
|
|
||||||
|
@ -43,6 +49,12 @@ public interface DisMaxParams {
|
||||||
*/
|
*/
|
||||||
public static String PS = "ps";
|
public static String PS = "ps";
|
||||||
|
|
||||||
|
/** default phrase slop for bigram phrases (pf2) */
|
||||||
|
public static String PS2 = "ps2";
|
||||||
|
|
||||||
|
/** default phrase slop for bigram phrases (pf3) */
|
||||||
|
public static String PS3 = "ps3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query and init param for phrase Slop value in phrases
|
* query and init param for phrase Slop value in phrases
|
||||||
* explicitly included in the user's query string ( in qf fields)
|
* explicitly included in the user's query string ( in qf fields)
|
||||||
|
|
Loading…
Reference in New Issue