You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2011/05/18 15:51:35 UTC

svn commit: r1124268 - in /lucene/dev/trunk/solr/src: java/org/apache/solr/search/JoinQParserPlugin.java java/org/apache/solr/search/SolrIndexSearcher.java test/org/apache/solr/TestJoin.java

Author: yonik
Date: Wed May 18 13:51:35 2011
New Revision: 1124268

URL: http://svn.apache.org/viewvc?rev=1124268&view=rev
Log:
SOLR-2521: TestJoin.testRandom fails, improve effective test coverage

Modified:
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/TestJoin.java

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java?rev=1124268&r1=1124267&r2=1124268&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/JoinQParserPlugin.java Wed May 18 13:51:35 2011
@@ -457,7 +457,7 @@ class JoinQuery extends Query {
         return resultList.get(0);
       }
 
-      int sz = resultList.size();
+      int sz = 0;
 
       for (DocSet set : resultList)
         sz += set.size();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1124268&r1=1124267&r2=1124268&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java Wed May 18 13:51:35 2011
@@ -811,7 +811,7 @@ public class SolrIndexSearcher extends I
       bitsSet += upto;
       result = new BitDocSet(obs, bitsSet);
     } else {
-      result = new SortedIntDocSet(Arrays.copyOf(docs, upto));
+      result = upto==0 ? DocSet.EMPTY : new SortedIntDocSet(Arrays.copyOf(docs, upto));
     }
 
     if (useCache) {

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/TestJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/TestJoin.java?rev=1124268&r1=1124267&r2=1124268&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/TestJoin.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/TestJoin.java Wed May 18 13:51:35 2011
@@ -101,6 +101,14 @@ public class TestJoin extends SolrTestCa
     int indexIter=50 * RANDOM_MULTIPLIER;
     int queryIter=50 * RANDOM_MULTIPLIER;
 
+    // groups of fields that have any chance of matching... used to
+    // increase test effectiveness by avoiding 0 resultsets much of the time.
+    String[][] compat = new String[][] {
+        {"small_s","small2_s","small2_ss","small3_ss"},
+        {"small_i","small2_i","small2_is","small3_is"}
+    };
+
+
     while (--indexIter >= 0) {
       int indexSize = random.nextInt(20 * RANDOM_MULTIPLIER);
 
@@ -121,8 +129,19 @@ public class TestJoin extends SolrTestCa
       Map<String, Map<Comparable, Set<Comparable>>> pivots = new HashMap<String, Map<Comparable, Set<Comparable>>>();
 
       for (int qiter=0; qiter<queryIter; qiter++) {
-        String fromField = types.get(random.nextInt(types.size())).fname;
-        String toField = types.get(random.nextInt(types.size())).fname;
+        String fromField;
+        String toField;
+        if (random.nextInt(100) < 5) {
+          // pick random fields 5% of the time
+          fromField = types.get(random.nextInt(types.size())).fname;
+          // pick the same field 50% of the time we pick a random field (since other fields won't match anything)
+          toField = (random.nextInt(100) < 50) ? fromField : types.get(random.nextInt(types.size())).fname;
+        } else {
+          // otherwise, pick compatible fields that have a chance of matching indexed tokens
+          String[] group = compat[random.nextInt(compat.length)];
+          fromField = group[random.nextInt(group.length)];
+          toField = group[random.nextInt(group.length)];
+        }
 
         Map<Comparable, Set<Comparable>> pivot = pivots.get(fromField+"/"+toField);
         if (pivot == null) {
@@ -146,7 +165,7 @@ public class TestJoin extends SolrTestCa
         resultSet.put("start", 0);
         resultSet.put("docs", sortedDocs);
 
-        // todo: use filters
+        // todo: use different join queries for better coverage
 
         SolrQueryRequest req = req("wt","json","indent","true", "echoParams","all",
             "q","{!join from="+fromField+" to="+toField
@@ -159,7 +178,7 @@ public class TestJoin extends SolrTestCa
         Object realResponse = ObjectBuilder.fromJSON(strResponse);
         String err = JSONTestUtil.matchObj("/response", realResponse, resultSet);
         if (err != null) {
-          log.error("GROUPING MISMATCH: " + err
+          log.error("JOIN MISMATCH: " + err
            + "\n\trequest="+req
            + "\n\tresult="+strResponse
            + "\n\texpected="+ JSONUtil.toJSON(resultSet)