From 52a77784c2d4ca8f72dab94df45b5d2e6cd22d2f Mon Sep 17 00:00:00 2001 From: Shawn Heisey Date: Sun, 20 Oct 2013 21:40:55 +0000 Subject: [PATCH] SOLR-5042 SOLR-5125 SOLR-5368: mlt.count used incorrectly in MoreLikeThisComponent. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1533995 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 7 ++++++- .../component/MoreLikeThisComponent.java | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 3dd199d5580..b9ec409f72a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -111,7 +111,12 @@ Bug Fixes * SOLR-5359: ZooKeeper client is not closed when it fails to connect to an ensemble. (Mark Miller, Klaus Herrmann) - + +* SOLR-5042: MoreLikeThisComponent was using the rows/count value in place of + flags, which caused a number of very strange issues, including NPEs and + ignoring requests for the results to include the score. + (Anshum Gupta, Mark Miller, Shawn Heisey) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java index 6ee73746f32..4764cff85c4 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java @@ -45,7 +45,9 @@ import org.apache.solr.schema.IndexSchema; import org.apache.solr.search.DocIterator; import org.apache.solr.search.DocList; import org.apache.solr.search.DocListAndSet; +import org.apache.solr.search.ReturnFields; import org.apache.solr.search.SolrIndexSearcher; +import org.apache.solr.search.SolrReturnFields; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,12 +72,20 @@ public class MoreLikeThisComponent extends SearchComponent { public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); + ReturnFields returnFields = new SolrReturnFields( rb.req ); + + int flags = 0; + if (returnFields.wantsScore()) { + flags |= SolrIndexSearcher.GET_SCORES; + } + + rb.setFieldFlags(flags); + if (params.getBool(MoreLikeThisParams.MLT, false)) { log.debug("Starting MoreLikeThis.Process. isShard: " + params.getBool(ShardParams.IS_SHARD)); SolrIndexSearcher searcher = rb.req.getSearcher(); - int mltcount = params.getInt(MoreLikeThisParams.DOC_COUNT, 5); if (params.getBool(ShardParams.IS_SHARD, false)) { if (params.get(MoreLikeThisComponent.DIST_DOC_ID) == null) { if (rb.getResults().docList.size() == 0) { @@ -86,7 +96,7 @@ public class MoreLikeThisComponent extends SearchComponent { MoreLikeThisHandler.MoreLikeThisHelper mlt = new MoreLikeThisHandler.MoreLikeThisHelper( params, searcher); - + NamedList bQuery = mlt.getMoreLikeTheseQuery(rb .getResults().docList); @@ -105,13 +115,13 @@ public class MoreLikeThisComponent extends SearchComponent { rb.rsp.add("moreLikeThis", temp); } else { NamedList sim = getMoreLikeThese(rb, rb.req.getSearcher(), - rb.getResults().docList, mltcount); + rb.getResults().docList, flags); rb.rsp.add("moreLikeThis", sim); } } else { // non distrib case NamedList sim = getMoreLikeThese(rb, rb.req.getSearcher(), rb.getResults().docList, - mltcount); + flags); rb.rsp.add("moreLikeThis", sim); } }