Package org.apache.lucene.facet.search.results

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


    assertEquals("Invalid # of subresults", 3, result.getFacetResultNode()
        .getNumSubResults());

    Iterator<? extends FacetResultNode> subResults = result
        .getFacetResultNode().getSubResults().iterator();
    FacetResultNode sub = subResults.next();
    assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
    assertEquals("Invalid subresult label", "5/2", sub.getLabel()
        .toString());
    sub = subResults.next();
    assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
    assertEquals("Invalid subresult label", "5/7", sub.getLabel()
        .toString());
    sub = subResults.next();
    assertEquals("Invalid subresult value", 1.0, sub.getValue(), 0.0);
    assertEquals("Invalid subresult label", "5/5", sub.getLabel()
        .toString());

    result = results.get(1);
    assertNotNull("Result should not be null", result);
    assertEquals("Invalid label", "5/5", result.getFacetResultNode()
View Full Code Here


    FacetSearchParams fsp = new FacetSearchParams();
    fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS));
    FacetsCollector collector = new FacetsCollector(fsp, reader1, taxReader);
    searcher.search(new MatchAllDocsQuery(), collector);
    FacetResult result = collector.getFacetResults().get(0);
    FacetResultNode node = result.getFacetResultNode();
    for (FacetResultNode facet: node.getSubResults()) {
      int weight = (int)facet.getValue();
      int label = Integer.parseInt(facet.getLabel().getComponent(1));
      //System.out.println(label + ": " + weight);
      if (VERBOSE) {
        System.out.println(label + ": " + weight);
View Full Code Here

    this.searchParams = searchParams;
  }

  public void fixResult(ScoredDocIDs origDocIds, FacetResult fres)
      throws IOException {
    FacetResultNode topRes = fres.getFacetResultNode();
    fixResultNode(topRes, origDocIds);
  }
View Full Code Here

   */
  public void labelResult(FacetResult facetResult) throws IOException {
    if (facetResult == null) {
      return; // any result to label?
    }
    FacetResultNode rootNode = facetResult.getFacetResultNode();
    recursivelyLabel(rootNode, facetRequest.getNumLabel());
  }
View Full Code Here

    for (int i = 0; i < results.size(); i++) {
      FacetResult res = results.get(i);
      assertEquals("wrong num-descendants for dimension " + dimension[i],
          expectedNumDescendants[i], res.getNumValidDescendants());
      FacetResultNode resNode = res.getFacetResultNode();
      assertEquals("wrong value for dimension " + dimension[i],
          expectedValue[i], (int) resNode.getValue());
    }
  }
View Full Code Here

     
      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

  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

    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

      }
     
      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

      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

TOP

Related Classes of org.apache.lucene.facet.search.results.FacetResultNode

Copyright © 2018 www.massapicom. 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.