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 2013/01/24 07:38:02 UTC

svn commit: r1437868 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java

Author: shaie
Date: Thu Jan 24 06:38:01 2013
New Revision: 1437868

URL: http://svn.apache.org/viewvc?rev=1437868&view=rev
Log:
CountingFacetsCollector did not sort the nodes when FacetRequest.getNumResults was > taxoReader.getSize()

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java
    lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java?rev=1437868&r1=1437867&r2=1437868&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/search/CountingFacetsCollector.java Thu Jan 24 06:38:01 2013
@@ -3,6 +3,8 @@ package org.apache.lucene.facet.search;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map.Entry;
@@ -265,6 +267,17 @@ public class CountingFacetsCollector ext
             }
             child = siblings[child];
           }
+          Collections.sort(nodes, new Comparator<FacetResultNode>() {
+            @Override
+            public int compare(FacetResultNode o1, FacetResultNode o2) {
+              int value = (int) (o2.value - o1.value);
+              if (value == 0) {
+                value = o2.ordinal - o1.ordinal;
+              }
+              return value;
+            }
+          });
+          
           root.subResults = nodes;
           res.add(new FacetResult(fr, root, nodes.size()));
           continue;

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java?rev=1437868&r1=1437867&r2=1437868&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/search/CountingFacetsCollectorTest.java Thu Jan 24 06:38:01 2013
@@ -353,8 +353,16 @@ public class CountingFacetsCollectorTest
     for (FacetResult res : facetResults) {
       FacetResultNode root = res.getFacetResultNode();
       assertEquals("wrong count for " + root.label, allExpectedCounts.get(root.label), (int) root.value);
+      int prevValue = Integer.MAX_VALUE;
+      int prevOrdinal = Integer.MAX_VALUE;
       for (FacetResultNode child : root.subResults) {
         assertEquals("wrong count for " + child.label, allExpectedCounts.get(child.label), (int) child.value);
+        assertTrue("wrong sort order of sub results: child.value=" + child.value + " prevValue=" + prevValue, child.value <= prevValue);
+        if (child.value == prevValue) {
+          assertTrue("wrong sort order of sub results", child.ordinal < prevOrdinal);
+        }
+        prevValue = (int) child.value;
+        prevOrdinal = child.ordinal;
       }
     }