You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2015/02/05 09:37:21 UTC
svn commit: r1657494 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/handler/
solr/core/src/test/org/apache/solr/handler/component/ solr/solrj/
solr/solrj/src/test/org/apache/solr/client/solrj/
Author: shalin
Date: Thu Feb 5 08:37:20 2015
New Revision: 1657494
URL: http://svn.apache.org/r1657494
Log:
SOLR-7072: Multiple mlt.fl does not work
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java
lucene/dev/branches/branch_5x/solr/solrj/ (props changed)
lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1657494&r1=1657493&r2=1657494&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Thu Feb 5 08:37:20 2015
@@ -51,6 +51,8 @@ Bug Fixes
* SOLR-7046: NullPointerException when group.function uses query() function.
(Jim Musil via Erick Erickson)
+* SOLR-7072: Multiple mlt.fl does not work. (Constantin Mitocaru, shalin)
+
Optimizations
----------------------
* SOLR-7049: Move work done by the LIST Collections API call to the Collections
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java?rev=1657494&r1=1657493&r2=1657494&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java Thu Feb 5 08:37:20 2015
@@ -27,6 +27,7 @@ import org.apache.lucene.search.BooleanQ
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.params.MoreLikeThisParams;
@@ -314,7 +315,19 @@ public class MoreLikeThisHandler extends
this.needDocSet = params.getBool(FacetParams.FACET,false);
SolrParams required = params.required();
- String[] fields = splitList.split( required.get(MoreLikeThisParams.SIMILARITY_FIELDS) );
+ String[] fl = required.getParams(MoreLikeThisParams.SIMILARITY_FIELDS);
+ List<String> list = new ArrayList<>();
+ for (String f : fl) {
+ if (!StringUtils.isEmpty(f)) {
+ String[] strings = splitList.split(f);
+ for (String string : strings) {
+ if (!StringUtils.isEmpty(string)) {
+ list.add(string);
+ }
+ }
+ }
+ }
+ String[] fields = list.toArray(new String[list.size()]);
if( fields.length < 1 ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"MoreLikeThis requires at least one similarity field: "+MoreLikeThisParams.SIMILARITY_FIELDS );
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java?rev=1657494&r1=1657493&r2=1657494&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java Thu Feb 5 08:37:20 2015
@@ -17,9 +17,15 @@ package org.apache.solr.handler.componen
* limitations under the License.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.BaseDistributedSearchTestCase;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.MoreLikeThisParams;
+import org.apache.solr.common.util.NamedList;
import org.junit.Ignore;
import org.junit.Test;
@@ -31,7 +37,6 @@ import org.junit.Test;
* @see org.apache.solr.handler.component.MoreLikeThisComponent
*/
@Slow
-@Ignore("fails on freebsd")
public class DistributedMLTComponentTest extends BaseDistributedSearchTestCase {
private String requestHandlerName;
@@ -51,30 +56,30 @@ public class DistributedMLTComponentTest
@ShardsFixed(num = 3)
public void test() throws Exception {
del("*:*");
- index(id, "1", "lowerfilt", "toyota");
- index(id, "2", "lowerfilt", "chevrolet");
- index(id, "3", "lowerfilt", "suzuki");
- index(id, "4", "lowerfilt", "ford");
- index(id, "5", "lowerfilt", "ferrari");
- index(id, "6", "lowerfilt", "jaguar");
- index(id, "7", "lowerfilt", "mclaren moon or the moon and moon moon shine and the moon but moon was good foxes too");
- index(id, "8", "lowerfilt", "sonata");
- index(id, "9", "lowerfilt", "The quick red fox jumped over the lazy big and large brown dogs.");
- index(id, "10", "lowerfilt", "blue");
- index(id, "12", "lowerfilt", "glue");
- index(id, "13", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "14", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "15", "lowerfilt", "The fat red fox jumped over the lazy brown dogs.");
- index(id, "16", "lowerfilt", "The slim red fox jumped over the lazy brown dogs.");
- index(id, "17", "lowerfilt", "The quote red fox jumped moon over the lazy brown dogs moon. Of course moon. Foxes and moon come back to the foxes and moon");
- index(id, "18", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "19", "lowerfilt", "The hose red fox jumped over the lazy brown dogs.");
- index(id, "20", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "21", "lowerfilt", "The court red fox jumped over the lazy brown dogs.");
- index(id, "22", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "23", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.");
- index(id, "24", "lowerfilt", "The file red fox jumped over the lazy brown dogs.");
- index(id, "25", "lowerfilt", "rod fix");
+ index(id, "1", "lowerfilt", "toyota", "lowerfilt1", "x");
+ index(id, "2", "lowerfilt", "chevrolet", "lowerfilt1", "x");
+ index(id, "3", "lowerfilt", "suzuki", "lowerfilt1", "x");
+ index(id, "4", "lowerfilt", "ford", "lowerfilt1", "x");
+ index(id, "5", "lowerfilt", "ferrari", "lowerfilt1", "x");
+ index(id, "6", "lowerfilt", "jaguar", "lowerfilt1", "x");
+ index(id, "7", "lowerfilt", "mclaren moon or the moon and moon moon shine and the moon but moon was good foxes too", "lowerfilt1", "x");
+ index(id, "8", "lowerfilt", "sonata", "lowerfilt1", "x");
+ index(id, "9", "lowerfilt", "The quick red fox jumped over the lazy big and large brown dogs.", "lowerfilt1", "x");
+ index(id, "10", "lowerfilt", "blue", "lowerfilt1", "x");
+ index(id, "12", "lowerfilt", "glue", "lowerfilt1", "x");
+ index(id, "13", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "14", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "15", "lowerfilt", "The fat red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "16", "lowerfilt", "The slim red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "17", "lowerfilt", "The quote red fox jumped moon over the lazy brown dogs moon. Of course moon. Foxes and moon come back to the foxes and moon", "lowerfilt1", "y");
+ index(id, "18", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "19", "lowerfilt", "The hose red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "20", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "21", "lowerfilt", "The court red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "22", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "23", "lowerfilt", "The quote red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "24", "lowerfilt", "The file red fox jumped over the lazy brown dogs.", "lowerfilt1", "y");
+ index(id, "25", "lowerfilt", "rod fix", "lowerfilt1", "y");
commit();
@@ -132,5 +137,30 @@ public class DistributedMLTComponentTest
MoreLikeThisParams.MIN_DOC_FREQ, 1, "sort", "id desc", "mlt", "true",
"mlt.fl", "lowerfilt", "qt", requestHandlerName, "shards.qt",
requestHandlerName, "mlt.count", "20");
+
+ // let's query by specifying multiple mlt.fl as comma-separated values
+ QueryResponse response = query("q", "lowerfilt:moon", "fl", id, MoreLikeThisParams.MIN_TERM_FREQ, 2,
+ MoreLikeThisParams.MIN_DOC_FREQ, 1, "sort", "id desc", "mlt", "true",
+ "mlt.fl", "lowerfilt1,lowerfilt", "qt", requestHandlerName, "shards.qt",
+ requestHandlerName, "mlt.count", "20");
+ NamedList<Object> moreLikeThis = (NamedList<Object>) response.getResponse().get("moreLikeThis");
+ Map<String, Long> idVsMLTCount = new HashMap<>();
+ for (Map.Entry<String, Object> entry : moreLikeThis) {
+ SolrDocumentList docList = (SolrDocumentList) entry.getValue();
+ idVsMLTCount.put(entry.getKey(), docList.getNumFound());
+ }
+
+ // let's query by specifying multiple mlt.fl as multiple request parameters
+ response = query("q", "lowerfilt:moon", "fl", id, MoreLikeThisParams.MIN_TERM_FREQ, 2,
+ MoreLikeThisParams.MIN_DOC_FREQ, 1, "sort", "id desc", "mlt", "true",
+ "mlt.fl", "lowerfilt1", "mlt.fl", "lowerfilt", "qt", requestHandlerName, "shards.qt",
+ requestHandlerName, "mlt.count", "20");
+ moreLikeThis = (NamedList<Object>) response.getResponse().get("moreLikeThis");
+ for (Map.Entry<String, Object> entry : moreLikeThis) {
+ String key = entry.getKey();
+ Long expected = idVsMLTCount.get(key);
+ Long actual = ((SolrDocumentList) entry.getValue()).getNumFound();
+ assertEquals("MLT mismatch for id=" + key, expected, actual);
+ }
}
}
Modified: lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1657494&r1=1657493&r2=1657494&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Thu Feb 5 08:37:20 2015
@@ -1644,6 +1644,59 @@ abstract public class SolrExampleTests e
assertEquals("All requested fields were not returned", 4, response.getResults().get(0).getFieldNames().size());
}
+ @Test
+ public void testMoreLikeThis() throws Exception {
+ SolrClient client = getSolrClient();
+ client.deleteByQuery("*:*");
+ for (int i=0; i<20; i++) {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", "testMoreLikeThis" + i);
+ doc.addField("x_s", "x_" + i);
+ doc.addField("y_s", "y_" + (i % 3));
+ doc.addField("z_s", "z_" + i);
+ client.add(doc);
+ }
+ client.commit();
+
+ // test with mlt.fl having comma separated values
+ SolrQuery q = new SolrQuery("*:*");
+ q.setRows(20);
+ q.setParam("mlt", "true");
+ q.setParam("mlt.mintf", "0");
+ q.setParam("mlt.count", "2");
+ q.setParam("mlt.fl", "x_s,y_s,z_s");
+ QueryResponse response = client.query(q);
+ System.out.printf("Results: " + response.getResponse());
+ assertEquals(20, response.getResults().getNumFound());
+ NamedList<Object> moreLikeThis = (NamedList<Object>) response.getResponse().get("moreLikeThis");
+ assertNotNull("MoreLikeThis response should not have been null", moreLikeThis);
+ for (int i=0; i<20; i++) {
+ String id = "testMoreLikeThis" + i;
+ SolrDocumentList mltResp = (SolrDocumentList) moreLikeThis.get(id);
+ assertNotNull("MoreLikeThis response for id=" + id + " should not be null", mltResp);
+ assertTrue("MoreLikeThis response for id=" + id + " had numFound=0", mltResp.getNumFound() > 0);
+ }
+
+ // now test with multiple mlt.fl parameters
+ q = new SolrQuery("*:*");
+ q.setRows(20);
+ q.setParam("mlt", "true");
+ q.setParam("mlt.mintf", "0");
+ q.setParam("mlt.count", "2");
+ q.setParam("mlt.fl", "x_s", "y_s", "z_s");
+ response = client.query(q);
+ System.out.printf("Results: " + response.getResponse());
+ assertEquals(20, response.getResults().getNumFound());
+ moreLikeThis = (NamedList<Object>) response.getResponse().get("moreLikeThis");
+ assertNotNull("MoreLikeThis response should not have been null", moreLikeThis);
+ for (int i=0; i<20; i++) {
+ String id = "testMoreLikeThis" + i;
+ SolrDocumentList mltResp = (SolrDocumentList) moreLikeThis.get(id);
+ assertNotNull("MoreLikeThis response for id=" + id + " should not be null", mltResp);
+ assertTrue("MoreLikeThis response for id=" + id + " had numFound=0", mltResp.getNumFound() > 0);
+ }
+ }
+
/**
* Depth first search of a SolrInputDocument looking for a decendent by id,
* returns null if it's not a decendent