You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2015/01/14 15:35:03 UTC

svn commit: r1651685 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/search/CollapsingQParserPlugin.java test/org/apache/solr/handler/component/TestExpandComponent.java test/org/apache/solr/search/TestCollapseQParserPlugin.java

Author: jbernste
Date: Wed Jan 14 14:35:03 2015
New Revision: 1651685

URL: http://svn.apache.org/r1651685
Log:
SOLR-6581: Additional test for Collapse and fixed problem with Expand float tests

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java?rev=1651685&r1=1651684&r2=1651685&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java Wed Jan 14 14:35:03 2015
@@ -1993,7 +1993,7 @@ public class CollapsingQParserPlugin ext
     }
   }
 
-  private class MergeBoost {
+  static class MergeBoost {
 
     private int[] boostDocs;
     private int index = 0;

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java?rev=1651685&r1=1651684&r2=1651685&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java Wed Jan 14 14:35:03 2015
@@ -71,6 +71,8 @@ public class TestExpandComponent extends
     String floatAppend = "";
     if(groups.get(0).indexOf("f") > -1) {
       floatAppend = "."+random().nextInt(100);  //Append the float
+      floatAppend = Float.toString(Float.parseFloat(floatAppend)); //Create a proper float out of the string.
+      floatAppend = floatAppend.substring(1);  //Drop off the leading 0, leaving just the decimal
     }
 
     String hint = "";
@@ -80,7 +82,13 @@ public class TestExpandComponent extends
 
   private void _testExpand(String group, String floatAppend, String hint) throws Exception {
 
-    String[] doc = {"id","1", "term_s", "YYYY", group, "1"+floatAppend, "test_ti", "5", "test_tl", "10", "test_tf", "2000", "type_s", "parent"};
+    String[] doc = {"id","1", "term_s", "YYYY", group, "1"+floatAppend, "test_ti", "5",
+
+
+
+
+
+        "test_tl", "10", "test_tf", "2000", "type_s", "parent"};
     assertU(adoc(doc));
     assertU(commit());
     String[] doc1 = {"id","2", "term_s","YYYY", group, "1"+floatAppend, "test_ti", "50", "test_tl", "100", "test_tf", "200", "type_s", "child"};

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java?rev=1651685&r1=1651684&r2=1651685&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java Wed Jan 14 14:35:03 2015
@@ -20,7 +20,10 @@ package org.apache.solr.search;
 import java.util.Collections;
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Random;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
 
 import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
 import org.apache.solr.SolrTestCaseJ4;
@@ -74,6 +77,70 @@ public class TestCollapseQParserPlugin e
     testCollapseQueries(group, hint, true);
   }
 
+  @Test
+
+  public void testMergeBoost() throws Exception {
+
+    Set<Integer> boosted = new HashSet();
+    Set<Integer> results = new HashSet();
+
+    for(int i=0; i<200; i++) {
+      boosted.add(random().nextInt(1000));
+    }
+
+    for(int i=0; i<200; i++) {
+      results.add(random().nextInt(1000));
+    }
+
+    int[] boostedArray = new int[boosted.size()];
+    int[] resultsArray = new int[results.size()];
+
+    Iterator<Integer> boostIt = boosted.iterator();
+    int index = 0;
+    while(boostIt.hasNext()) {
+      boostedArray[index++] = boostIt.next();
+    }
+
+    Iterator<Integer> resultsIt = results.iterator();
+    index = 0;
+    while(resultsIt.hasNext()) {
+      resultsArray[index++] = resultsIt.next();
+    }
+
+    Arrays.sort(boostedArray);
+    Arrays.sort(resultsArray);
+
+    CollapsingQParserPlugin.MergeBoost mergeBoost = new CollapsingQParserPlugin.MergeBoost(boostedArray);
+
+    List<Integer> boostedResults = new ArrayList();
+
+    for(int i=0; i<resultsArray.length; i++) {
+      int result = resultsArray[i];
+      if(mergeBoost.boost(result)) {
+        boostedResults.add(result);
+      }
+    }
+
+    List<Integer> controlResults = new ArrayList();
+
+    for(int i=0; i<resultsArray.length; i++) {
+      int result = resultsArray[i];
+      if(Arrays.binarySearch(boostedArray, result) > -1) {
+        controlResults.add(result);
+      }
+    }
+
+    if(boostedResults.size() == controlResults.size()) {
+      for(int i=0; i<boostedResults.size(); i++) {
+        if(!boostedResults.get(i).equals(controlResults.get(i).intValue())) {
+          throw new Exception("boosted results do not match control results, boostedResults size:"+boostedResults.toString()+", controlResults size:"+controlResults.toString());
+        }
+      }
+    } else {
+      throw new Exception("boosted results do not match control results, boostedResults size:"+boostedResults.toString()+", controlResults size:"+controlResults.toString());
+    }
+  }
+
 
 
   private void testCollapseQueries(String group, String hint, boolean numeric) throws Exception {
@@ -428,4 +495,5 @@ public class TestCollapseQParserPlugin e
     assertQ(req(params), "*[count(//doc)=0]");
   }
 
+
 }