mirror of https://github.com/apache/lucene.git
SOLR-8418: Adapt to changes in LUCENE-6590 for use of boosts with MLTHandler and Simple/CloudMLTQParser
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1722478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f861ad6d50
commit
8127db872f
|
@ -322,6 +322,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-7462: AIOOBE in RecordingJSONParser (Scott Dawson, noble)
|
||||
|
||||
* SOLR-8418: Adapt to changes in LUCENE-6590 for use of boosts with MLTHandler and
|
||||
Simple/CloudMLTQParser (Jens Wille, Ramkumar Aiyengar)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
|
|
@ -37,11 +37,7 @@ import org.apache.solr.common.params.SolrParams;
|
|||
import org.apache.solr.common.util.ContentStream;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.apache.solr.handler.component.FacetComponent;
|
||||
import org.apache.solr.handler.component.SpatialHeatmapFacets;
|
||||
import org.apache.solr.handler.component.DateFacetProcessor;
|
||||
import org.apache.solr.handler.component.RangeFacetProcessor;
|
||||
import org.apache.solr.request.SimpleFacets;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
|
@ -148,7 +144,7 @@ public class MoreLikeThisHandler extends RequestHandlerBase
|
|||
// Hold on to the interesting terms if relevant
|
||||
TermStyle termStyle = TermStyle.get(params.get(MoreLikeThisParams.INTERESTING_TERMS));
|
||||
List<InterestingTerm> interesting = (termStyle == TermStyle.NONE)
|
||||
? null : new ArrayList<InterestingTerm>(mlt.mlt.getMaxQueryTerms());
|
||||
? null : new ArrayList<>(mlt.mlt.getMaxQueryTerms());
|
||||
|
||||
DocListAndSet mltDocs = null;
|
||||
|
||||
|
@ -246,10 +242,10 @@ public class MoreLikeThisHandler extends RequestHandlerBase
|
|||
if (dbg == false) {//if it's true, we are doing everything anyway.
|
||||
String[] dbgParams = req.getParams().getParams(CommonParams.DEBUG);
|
||||
if (dbgParams != null) {
|
||||
for (int i = 0; i < dbgParams.length; i++) {
|
||||
if (dbgParams[i].equals(CommonParams.QUERY)) {
|
||||
for (String dbgParam : dbgParams) {
|
||||
if (dbgParam.equals(CommonParams.QUERY)) {
|
||||
dbgQuery = true;
|
||||
} else if (dbgParams[i].equals(CommonParams.RESULTS)) {
|
||||
} else if (dbgParam.equals(CommonParams.RESULTS)) {
|
||||
dbgResults = true;
|
||||
}
|
||||
}
|
||||
|
@ -381,10 +377,14 @@ public class MoreLikeThisHandler extends RequestHandlerBase
|
|||
newQ.setMinimumNumberShouldMatch(boostedQuery.getMinimumNumberShouldMatch());
|
||||
for (BooleanClause clause : boostedQuery) {
|
||||
Query q = clause.getQuery();
|
||||
Float b = this.boostFields.get(((TermQuery) q).getTerm().field());
|
||||
if (b != null) {
|
||||
q = new BoostQuery(q, b);
|
||||
float originalBoost = 1f;
|
||||
if (q instanceof BoostQuery) {
|
||||
BoostQuery bq = (BoostQuery) q;
|
||||
q = bq.getQuery();
|
||||
originalBoost = bq.getBoost();
|
||||
}
|
||||
Float fieldBoost = boostFields.get(((TermQuery) q).getTerm().field());
|
||||
q = ((fieldBoost != null) ? new BoostQuery(q, fieldBoost * originalBoost) : clause.getQuery());
|
||||
newQ.add(q, clause.getOccur());
|
||||
}
|
||||
boostedQuery = newQ.build();
|
||||
|
@ -485,7 +485,7 @@ public class MoreLikeThisHandler extends RequestHandlerBase
|
|||
for( BooleanClause o : clauses ) {
|
||||
Query q = o.getQuery();
|
||||
float boost = 1f;
|
||||
if (query instanceof BoostQuery) {
|
||||
if (q instanceof BoostQuery) {
|
||||
BoostQuery bq = (BoostQuery) q;
|
||||
q = bq.getQuery();
|
||||
boost = bq.getBoost();
|
||||
|
|
|
@ -98,8 +98,8 @@ public class CloudMLTQParser extends QParser {
|
|||
|
||||
mlt.setAnalyzer(req.getSchema().getIndexAnalyzer());
|
||||
|
||||
Map<String, Collection<Object>> filteredDocument = new HashMap();
|
||||
ArrayList<String> fieldNames = new ArrayList();
|
||||
Map<String, Collection<Object>> filteredDocument = new HashMap<>();
|
||||
ArrayList<String> fieldNames = new ArrayList<>();
|
||||
|
||||
if (qf != null) {
|
||||
for (String fieldName : qf) {
|
||||
|
@ -146,12 +146,14 @@ public class CloudMLTQParser extends QParser {
|
|||
|
||||
for (BooleanClause clause : boostedMLTQuery) {
|
||||
Query q = clause.getQuery();
|
||||
Float b = boostFields.get(((TermQuery) q).getTerm().field());
|
||||
|
||||
if (b != null) {
|
||||
q = new BoostQuery(q, b);
|
||||
float originalBoost = 1f;
|
||||
if (q instanceof BoostQuery) {
|
||||
BoostQuery bq = (BoostQuery) q;
|
||||
q = bq.getQuery();
|
||||
originalBoost = bq.getBoost();
|
||||
}
|
||||
|
||||
Float fieldBoost = boostFields.get(((TermQuery) q).getTerm().field());
|
||||
q = ((fieldBoost != null) ? new BoostQuery(q, fieldBoost * originalBoost) : clause.getQuery());
|
||||
newQ.add(q, clause.getOccur());
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public class SimpleMLTQParser extends QParser {
|
|||
boostFields = SolrPluginUtils.parseFieldBoosts(qf);
|
||||
}
|
||||
|
||||
ArrayList<String> fields = new ArrayList();
|
||||
ArrayList<String> fields = new ArrayList<>();
|
||||
|
||||
if (qf != null) {
|
||||
for (String fieldName : qf) {
|
||||
|
@ -136,12 +136,14 @@ public class SimpleMLTQParser extends QParser {
|
|||
|
||||
for (BooleanClause clause : boostedMLTQuery) {
|
||||
Query q = clause.getQuery();
|
||||
Float b = boostFields.get(((TermQuery) q).getTerm().field());
|
||||
|
||||
if (b != null) {
|
||||
q = new BoostQuery(q, b);
|
||||
float originalBoost = 1f;
|
||||
if (q instanceof BoostQuery) {
|
||||
BoostQuery bq = (BoostQuery) q;
|
||||
q = bq.getQuery();
|
||||
originalBoost = bq.getBoost();
|
||||
}
|
||||
|
||||
Float fieldBoost = boostFields.get(((TermQuery) q).getTerm().field());
|
||||
q = ((fieldBoost != null) ? new BoostQuery(q, fieldBoost * originalBoost) : clause.getQuery());
|
||||
newQ.add(q, clause.getOccur());
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,12 @@ public class MoreLikeThisHandlerTest extends SolrTestCaseJ4 {
|
|||
assertQ("morelikethis - tom cruise",mltreq
|
||||
,"//result/doc[1]/int[@name='id'][.='46']"
|
||||
,"//result/doc[2]/int[@name='id'][.='43']");
|
||||
|
||||
params.set(MoreLikeThisParams.BOOST, "true");
|
||||
mltreq.close(); mltreq = new LocalSolrQueryRequest( core, params);
|
||||
assertQ("morelikethis - tom cruise",mltreq
|
||||
,"//result/doc[1]/int[@name='id'][.='46']"
|
||||
,"//result/doc[2]/int[@name='id'][.='43']");
|
||||
|
||||
params.set(CommonParams.Q, "id:44");
|
||||
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
|
||||
|
|
|
@ -111,6 +111,18 @@ public class CloudMLTQParserTest extends AbstractFullDistribZkTestBase {
|
|||
actualIds[i++] = Integer.valueOf(String.valueOf(solrDocument.getFieldValue("id")));
|
||||
}
|
||||
assertArrayEquals(expectedIds, actualIds);
|
||||
|
||||
params = new ModifiableSolrParams();
|
||||
params.set(CommonParams.Q, "{!mlt qf=lowerfilt boost=true}17");
|
||||
queryResponse = queryServer(params);
|
||||
solrDocuments = queryResponse.getResults();
|
||||
expectedIds = new int[]{7, 13, 14, 15, 16, 20, 22, 24, 32, 9};
|
||||
actualIds = new int[solrDocuments.size()];
|
||||
i = 0;
|
||||
for (SolrDocument solrDocument : solrDocuments) {
|
||||
actualIds[i++] = Integer.valueOf(String.valueOf(solrDocument.getFieldValue("id")));
|
||||
}
|
||||
assertArrayEquals(expectedIds, actualIds);
|
||||
|
||||
params = new ModifiableSolrParams();
|
||||
params.set(CommonParams.Q, "{!mlt qf=lowerfilt mindf=0 mintf=1}3");
|
||||
|
|
|
@ -97,6 +97,21 @@ public class SimpleMLTQParserTest extends SolrTestCaseJ4 {
|
|||
"//result/doc[10]/int[@name='id'][.='23']"
|
||||
);
|
||||
|
||||
params = new ModifiableSolrParams();
|
||||
params.set(CommonParams.Q, "{!mlt qf=lowerfilt boost=true}17");
|
||||
assertQ(req(params),
|
||||
"//result/doc[1]/int[@name='id'][.='13']",
|
||||
"//result/doc[2]/int[@name='id'][.='14']",
|
||||
"//result/doc[3]/int[@name='id'][.='15']",
|
||||
"//result/doc[4]/int[@name='id'][.='16']",
|
||||
"//result/doc[5]/int[@name='id'][.='18']",
|
||||
"//result/doc[6]/int[@name='id'][.='19']",
|
||||
"//result/doc[7]/int[@name='id'][.='20']",
|
||||
"//result/doc[8]/int[@name='id'][.='21']",
|
||||
"//result/doc[9]/int[@name='id'][.='22']",
|
||||
"//result/doc[10]/int[@name='id'][.='23']"
|
||||
);
|
||||
|
||||
params = new ModifiableSolrParams();
|
||||
params.set(CommonParams.Q, "{!mlt qf=lowerfilt mindf=0 mintf=1}26");
|
||||
params.set(CommonParams.DEBUG, "true");
|
||||
|
|
Loading…
Reference in New Issue