Examples of FacetResultNode


Examples of org.apache.lucene.facet.search.results.FacetResultNode

     
      HashMap<String,Integer> all = new HashMap<String,Integer>();
      int maxNumNodes = 0;
      int k = 0;
      for (FacetResult fr : allFacetResults) {
        FacetResultNode topResNode = fr.getFacetResultNode();
        maxNumNodes = Math.max(maxNumNodes, topResNode.getNumSubResults());
        int prevCount = Integer.MAX_VALUE;
        int pos = 0;
        for (FacetResultNode frn: topResNode.getSubResults()) {
          assertTrue("wrong counts order: prev="+prevCount+" curr="+frn.getValue(), prevCount>=frn.getValue());
          prevCount = (int) frn.getValue();
          String key = k+"--"+frn.getLabel()+"=="+frn.getValue();
          if (VERBOSE) {
            System.out.println(frn.getLabel() + " - " + frn.getValue() + "  "+key+"  "+pos);
          }
          all.put(key, pos++); // will use this later to verify order of sub-results
        }
        k++;
      }
     
      // verify that when asking for less results, they are always of highest counts
      // also verify that the order is stable
      for (int n=1; n<maxNumNodes; n++) {
        if (VERBOSE) {
          System.out.println("-------  verify for "+n+" top results");
        }
        List<FacetResult> someResults = countFacets(partitionSize, n, false);
        k = 0;
        for (FacetResult fr : someResults) {
          FacetResultNode topResNode = fr.getFacetResultNode();
          assertTrue("too many results: n="+n+" but got "+topResNode.getNumSubResults(), n>=topResNode.getNumSubResults());
          int pos = 0;
          for (FacetResultNode frn: topResNode.getSubResults()) {
            String key = k+"--"+frn.getLabel()+"=="+frn.getValue();
            if (VERBOSE) {
              System.out.println(frn.getLabel() + " - " + frn.getValue() + "  "+key+"  "+pos);
            }
            Integer origPos = all.get(key);
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

  private void assertCorrectResults(FacetsCollector facetsCollector)
  throws IOException, IllegalAccessException, InstantiationException {
    List<FacetResult> res = facetsCollector.getFacetResults();

    FacetResult results = res.get(0);
    FacetResultNode resNode = results.getFacetResultNode();
    Iterable<? extends FacetResultNode> subResults = resNode
    .getSubResults();
    Iterator<? extends FacetResultNode> subIter = subResults.iterator();

    checkResult(resNode, "Band", 5.0);
    checkResult(subIter.next(), "Band/Rock & Pop", 4.0);
    checkResult(subIter.next(), "Band/Punk", 1.0);

    results = res.get(1);
    resNode = results.getFacetResultNode();
    subResults = resNode.getSubResults();
    subIter = subResults.iterator();

    checkResult(resNode, "Band", 5.0);
    checkResult(subIter.next(), "Band/Rock & Pop", 4.0);
    checkResult(subIter.next(), "Band/Rock & Pop/Dave Matthews Band", 1.0);
    checkResult(subIter.next(), "Band/Rock & Pop/REM", 1.0);
    checkResult(subIter.next(), "Band/Rock & Pop/U2", 1.0);
    checkResult(subIter.next(), "Band/Punk/The Ramones", 1.0);
    checkResult(subIter.next(), "Band/Punk", 1.0);
    checkResult(subIter.next(), "Band/Rock & Pop/The Beatles", 1.0);

    results = res.get(2);
    resNode = results.getFacetResultNode();
    subResults = resNode.getSubResults();
    subIter = subResults.iterator();

    checkResult(resNode, "Author", 3.0);
    checkResult(subIter.next(), "Author/Kurt Vonnegut", 1.0);
    checkResult(subIter.next(), "Author/Stephen King", 1.0);
    checkResult(subIter.next(), "Author/Mark Twain", 1.0);

    results = res.get(3);
    resNode = results.getFacetResultNode();
    subResults = resNode.getSubResults();
    subIter = subResults.iterator();

    checkResult(resNode, "Band/Rock & Pop", 4.0);
    checkResult(subIter.next(), "Band/Rock & Pop/Dave Matthews Band", 1.0);
    checkResult(subIter.next(), "Band/Rock & Pop/REM", 1.0);
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

    List<FacetResult> scoreRes = findFacets(scoredDocIDs, sumScoreSearchParams());

    assertEquals("Wrong number of facet count results!", 1, countRes.size());
    assertEquals("Wrong number of facet score results!", 1, scoreRes.size());

    FacetResultNode parentCountRes = countRes.get(0).getFacetResultNode();
    FacetResultNode parentScoreRes = scoreRes.get(0).getFacetResultNode();

    assertEquals("Wrong number of top count aggregated categories!", 3,
        parentCountRes.getNumSubResults());
    assertEquals("Wrong number of top score aggregated categories!", 3,
        parentScoreRes.getNumSubResults());

    // rely on that facet value is computed as doc-score, and
    // accordingly compare values of the two top-category results.

    FacetResultNode[] countResNodes = resultNodesAsArray(parentCountRes);
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

      }
     
      FacetResult fr = facetResults.get(0); // a, depth=3, K=2
      boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(9, fr.getNumValidDescendants());
      FacetResultNode parentRes = fr.getFacetResultNode();
      assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      // two nodes sorted by descending values: a/b with 8  and a/c with 6
      // a/b has residue 2 and two children a/b/2 with value 3, and a/b/1 with value 2.
      // a/c has residue 0, and one child a/c/1 with value 1.
      double [] expectedValues0 = { 8.0, 2.0, 3.0, 0.0, 2.0, 0.0, 6.0, 0.0, 1.0, 0.0 };
      int i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues0[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(expectedValues0[i++], node.getResidue(), Double.MIN_VALUE);
        for (FacetResultNode node2 : node.getSubResults()) {
          assertEquals(expectedValues0[i++], node2.getValue(), Double.MIN_VALUE);
          assertEquals(expectedValues0[i++], node2.getResidue(), Double.MIN_VALUE);
        }
      }

      // now just change the value of the first child of the root to 5, and then rearrange
      // expected are: first a/c of value 6 and residue 0, and one child a/c/1 with value 1
      // then a/b with value 5 and residue 2, and both children: a/b/2 with value 3, and a/b/1 with value 2.
      for (FacetResultNode node : parentRes.getSubResults()) {
        node.setValue(5.0);
        break;
      }
      // now rearrange
      double [] expectedValues00 = { 6.0, 0.0, 1.0, 0.0, 5.0, 2.0, 3.0, 0.0, 2.0, 0.0 };
      fr = cfra23.createFacetResultsHandler(tr).rearrangeFacetResult(fr);
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues00[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(expectedValues00[i++], node.getResidue(), Double.MIN_VALUE);
        for (FacetResultNode node2 : node.getSubResults()) {
          assertEquals(expectedValues00[i++], node2.getValue(), Double.MIN_VALUE);
          assertEquals(expectedValues00[i++], node2.getResidue(), Double.MIN_VALUE);
        }
      }

      fr = facetResults.get(1); // a, depth=2, K=2. same result as before
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(9, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      // two nodes sorted by descending values: a/b with 8  and a/c with 6
      // a/b has residue 2 and two children a/b/2 with value 3, and a/b/1 with value 2.
      // a/c has residue 0, and one child a/c/1 with value 1.
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues0[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(expectedValues0[i++], node.getResidue(), Double.MIN_VALUE);
        for (FacetResultNode node2 : node.getSubResults()) {
          assertEquals(expectedValues0[i++], node2.getValue(), Double.MIN_VALUE);
          assertEquals(expectedValues0[i++], node2.getResidue(), Double.MIN_VALUE);
        }
      }

      fr = facetResults.get(2); // a, depth=1, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(4, fr.getNumValidDescendants(), 4);
      parentRes = fr.getFacetResultNode();
      assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      // two nodes sorted by descending values:
      // a/b with value 8 and residue 0 (because no children considered), 
      //  and a/c with value 6 and residue 0 (because no children considered)
      double [] expectedValues2 = { 8.0, 0.0, 6.0, 0.0 };
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues2[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(expectedValues2[i++], node.getResidue(), Double.MIN_VALUE);
        assertEquals(node.getNumSubResults(), 0);
      }
     
      fr = facetResults.get(3); // a/b, depth=3, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(4, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      double [] expectedValues3 = { 3.0, 2.0 };
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
        assertEquals(0, node.getNumSubResults());
      }

      fr = facetResults.get(4); // a/b, depth=2, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(4, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
        assertEquals(0, node.getNumSubResults());
      }

      fr = facetResults.get(5); // a/b, depth=1, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(4, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(2.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(2, parentRes.getNumSubResults());
      i = 0;
      for (FacetResultNode node : parentRes.getSubResults()) {
        assertEquals(expectedValues3[i++], node.getValue(), Double.MIN_VALUE);
        assertEquals(0.0, node.getResidue(), Double.MIN_VALUE);
        assertEquals(0, node.getNumSubResults());
      }
     
      fr = facetResults.get(6); // a/b, depth=0, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));
      assertEquals(0, fr.getNumValidDescendants()); // 0 descendants but rootnode
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
      assertEquals(0.0, parentRes.getResidue(), Double.MIN_VALUE);
      assertEquals(0, parentRes.getNumSubResults());
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().getComponent(0));

      // doctor, depth=1, K=2
      assertFalse("Shouldn't have found anything for a FacetRequest " +
          "of a facet that doesn't exist in the index.", hasDoctor);
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

      if (VERBOSE) {
        System.out.println("Time: " + (end - start));
      }

      FacetResult fr = facetResults.get(0);
      FacetResultNode parentRes = fr.getFacetResultNode();
      assertEquals(13.0, parentRes.getValue(), Double.MIN_VALUE);
      FacetResultNode[] frn = resultNodesAsArray(parentRes);
      assertEquals(7.0, frn[0].getValue(), Double.MIN_VALUE);
      assertEquals(6.0, frn[1].getValue(), Double.MIN_VALUE);

      fr = facetResults.get(1);
      parentRes = fr.getFacetResultNode();
      assertEquals(13.0, parentRes.getValue(), Double.MIN_VALUE);
      frn = resultNodesAsArray(parentRes);
      assertEquals(7.0, frn[0].getValue(), Double.MIN_VALUE);
      assertEquals(6.0, frn[1].getValue(), Double.MIN_VALUE);
      assertEquals(2.0, frn[2].getValue(), Double.MIN_VALUE);
      assertEquals(2.0, frn[3].getValue(), Double.MIN_VALUE);
      assertEquals(1.0, frn[4].getValue(), Double.MIN_VALUE);
      assertEquals(1.0, frn[5].getValue(), Double.MIN_VALUE);

      fr = facetResults.get(2);
      parentRes = fr.getFacetResultNode();
      assertEquals(7.0, parentRes.getValue(), Double.MIN_VALUE);
      frn = resultNodesAsArray(parentRes);
      assertEquals(2.0, frn[0].getValue(), Double.MIN_VALUE);
      assertEquals(2.0, frn[1].getValue(), Double.MIN_VALUE);
      assertEquals(1.0, frn[2].getValue(), Double.MIN_VALUE);
      assertEquals(1.0, frn[3].getValue(), Double.MIN_VALUE);

      fr = facetResults.get(3);
      parentRes = fr.getFacetResultNode();
      assertEquals(2.0, parentRes.getValue(), Double.MIN_VALUE);
      frn = resultNodesAsArray(parentRes);
      assertEquals(0, frn.length);

      fr = facetResults.get(4);
      parentRes = fr.getFacetResultNode();
      assertEquals(6.0, parentRes.getValue(), Double.MIN_VALUE);
      frn = resultNodesAsArray(parentRes);
      assertEquals(1.0, frn[0].getValue(), Double.MIN_VALUE);
      closeAll();
    }
  }
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

    String[] expLabels = new String[] { "5", "5/5", "6/2" };
    double[] expValues = new double[] { 0.0, 0.0, 1.0 };
    for (int i = 0; i < 3; i++) {
      FacetResult result = results.get(i);
      assertNotNull("Result should not be null", result);
      FacetResultNode resNode = result.getFacetResultNode();
      assertEquals("Invalid label", expLabels[i], resNode.getLabel().toString());
      assertEquals("Invalid value", expValues[i], resNode.getValue(), 0.0);
      assertEquals("Invalid number of subresults", 0, resNode.getNumSubResults());
    }
    // we're done, close the index reader and the taxonomy.
    slowIndexReader.close();
    slowTaxoReader.close();
    indexDir.close();
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

    List<FacetResult> countResNoComplement = findFacets(dCollector.getScoredDocIDs(), false);
   
    assertEquals("Wrong number of facet count results with complement!",1,countResWithComplement.size());
    assertEquals("Wrong number of facet count results no complement!",1,countResNoComplement.size());
   
    FacetResultNode parentResWithComp = countResWithComplement.get(0).getFacetResultNode();
    FacetResultNode parentResNoComp = countResWithComplement.get(0).getFacetResultNode();
   
    assertEquals("Wrong number of top count aggregated categories with complement!",3,parentResWithComp.getNumSubResults());
    assertEquals("Wrong number of top count aggregated categories no complement!",3,parentResNoComp.getNumSubResults());
   
  }
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

  }
 
  /** Validate counts for returned facets, and that there are not too many results */
  protected static void assertCountsAndCardinality(Map<CategoryPath, Integer> facetCountsTruth, List<FacetResult> facetResults) throws Exception {
    for (FacetResult fr : facetResults) {
      FacetResultNode topResNode = fr.getFacetResultNode();
      FacetRequest freq = fr.getFacetRequest();
      if (VERBOSE) {
        System.out.println(freq.getCategoryPath().toString()+ "\t\t" + topResNode);
      }
      assertCountsAndCardinality(facetCountsTruth, topResNode, freq.getNumResults());
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

        continue;
      }
      // bring sub results from heap of tmp res into result heap
      for (int i = tmpHeap.size(); i > 0; i--) {
       
        FacetResultNode a = heap.insertWithOverflow(tmpHeap.pop());
        if (a != null) {
          resNode.increaseResidue(a.getResidue());
        }
      }
    }
   
    TopKFacetResult res = new TopKFacetResult(facetRequest, resNode, totalFacets);
View Full Code Here

Examples of org.apache.lucene.facet.search.results.FacetResultNode

    int partitionSize = facetArrays.getArraysLength();
    int endOffset = offset + partitionSize;
    ChildrenArrays childrenArray = taxonomyReader.getChildrenArrays();
    int[] youngestChild = childrenArray.getYoungestChildArray();
    int[] olderSibling = childrenArray.getOlderSiblingArray();
    FacetResultNode reusable = null;
    int localDepth = 0;
    int depth = facetRequest.getDepth();
    int[] ordinalStack = new int[2+Math.min(Short.MAX_VALUE, depth)];
    int childrenCounter = 0;
   
    int tosOrdinal; // top of stack element
   
    int yc = youngestChild[ordinal];
    while (yc >= endOffset) {
      yc = olderSibling[yc];
    }
    // make use of the fact that TaxonomyReader.INVALID_ORDINAL == -1, < endOffset
    // and it, too, can stop the loop.
    ordinalStack[++localDepth] = yc;
   
    /*
     * stack holds input parameter ordinal in position 0.
     * Other elements are < endoffset.
     * Only top of stack can be TaxonomyReader.INVALID_ORDINAL, and this if and only if
     * the element below it exhausted all its children: has them all processed.
     *
     * stack elements are processed (counted and accumulated) only if they
     * belong to current partition (between offset and endoffset) and first time
     * they are on top of stack
     *
     * loop as long as stack is not empty of elements other than input ordinal, or for a little while -- it sibling
     */
    while (localDepth > 0) {
      tosOrdinal = ordinalStack[localDepth];
      if (tosOrdinal == TaxonomyReader.INVALID_ORDINAL) {
        // element below tos has all its children, and itself, all processed
        // need to proceed to its sibling
        localDepth--;
        // change element now on top of stack to its sibling.
        ordinalStack[localDepth] = olderSibling[ordinalStack[localDepth]];
        continue;
      }
      // top of stack is not invalid, this is the first time we see it on top of stack.
      // collect it, if belongs to current partition, and then push its kids on itself, if applicable
      if (tosOrdinal >= offset) { // tosOrdinal resides in current partition
        int relativeOrdinal = tosOrdinal % partitionSize;
        double value = facetRequest.getValueOf(facetArrays, relativeOrdinal);
        if (value != 0 && !Double.isNaN(value)) {
          // Count current ordinal -- the TOS
          if (reusable == null) {
            reusable = new MutableFacetResultNode(tosOrdinal, value);
          } else {
            // it is safe to cast since reusable was created here.
            ((MutableFacetResultNode)reusable).reset(tosOrdinal, value);
          }
          ++childrenCounter;
          reusable = pq.insertWithOverflow(reusable);
          if (reusable != null) {
            // TODO (Facet): is other logic (not add) needed, per aggregator?
            parentResultNode.increaseResidue(reusable.getValue());
          }
        }
      }
      if (localDepth < depth) {
        // push kid of current tos
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.