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

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


    assertNotNull("Null result!", res);
    assertNotNull("Null facet result!", res.getFacetResults());
    assertEquals("Wrong number of results!",1, res.getFacetResults().size());
   
    // drill down facet appears in only 1 doc, and that doc has only 2 facets 
    FacetResult facetResult = res.getFacetResults().get(0);
    assertEquals("Wrong number of facets!",2, facetResult.getNumValidDescendants());
   
    Iterator<? extends FacetResultNode> resIterator = facetResult.getFacetResultNode().getSubResults().iterator();
    assertTrue("Too few results", resIterator.hasNext());
    assertEquals("wrong count for first result out of 2", 1, (int)resIterator.next().getValue());
    assertTrue("Too few results", resIterator.hasNext());
    assertEquals("wrong count for second result out of 2", 1, (int)resIterator.next().getValue());
    assertFalse("Too many results!", resIterator.hasNext());
View Full Code Here


  }

  public static void assertCorrectMultiResults(ExampleResult exampleResults)
      throws Exception {
    List<FacetResult> results = exampleResults.getFacetResults();
    FacetResult result = results.get(0);
    assertNotNull("Result should not be null", result);
    assertEquals("Invalid label", "5", result.getFacetResultNode()
        .getLabel().toString());
    assertEquals("Invalid value", 2.0, result.getFacetResultNode()
        .getValue(), 0.0);
    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()
        .getLabel().toString());
    assertEquals("Invalid value", 1,
        result.getFacetResultNode().getValue(), 0.0);
    assertEquals("Invalid number of subresults", 0, result
        .getFacetResultNode().getNumSubResults());

    result = results.get(2);
    assertNotNull("Result should not be null", result);
    assertEquals("Invalid label", "6/2", result.getFacetResultNode()
        .getLabel().toString());
    assertEquals("Invalid value", 1,
        result.getFacetResultNode().getValue(), 0.0);
    assertEquals("Invalid number of subresults", 0, result
        .getFacetResultNode().getNumSubResults());

  }
View Full Code Here

    IndexSearcher searcher = newSearcher(reader1);
    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) {
View Full Code Here

    FacetRequest origFrq = sampledFreq.orig;

    MutableFacetResultNode trimmedRootNode = MutableFacetResultNode.toImpl(facetResult.getFacetResultNode());
    trimmedRootNode.trimSubResults(origFrq.getNumResults());
   
    return new FacetResult(origFrq, trimmedRootNode, facetResult.getNumValidDescendants());
  }
View Full Code Here

    double value = Double.NaN;
    if (tmp.isRootNodeIncluded) {
      value = tmp.rootNodeValue;
    }
    MutableFacetResultNode root = generateNode (ordinal, value, tmp.mapToAACOs);
    return new FacetResult (tmp.facetRequest, root, tmp.totalNumOfFacetsConsidered);

  }
View Full Code Here

    List<FacetResult> results = acc.accumulate(allDocs);
    assertEquals("Wrong #results", dimension.length, results.size());

    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

  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);
View Full Code Here

      long end = System.currentTimeMillis();
      if (VERBOSE) {
        System.out.println("Time: " + (end - start));
      }
     
      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);
      assertEquals("Shouldn't have found more than seven request.", 7, facetResults.size());
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

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

      assertEquals("Should only be one result as there's only one request", 1, results.size());
      FacetResult res = results.get(0);
      assertEquals(path + " should only have 4 desendants", 4, res.getNumValidDescendants());

      // As a control base results, ask for top-1000 results
      FacetSearchParams sParams2 = getFacetedSearchParams(partitionSize);
      sParams2.addFacetRequest(new CountFacetRequest(path, Integer.MAX_VALUE));

      FacetsCollector fc2 = new FacetsCollector(sParams2, indexReader, taxoReader) {
        @Override
        protected FacetsAccumulator initFacetsAccumulator(FacetSearchParams facetSearchParams, IndexReader indexReader, TaxonomyReader taxonomyReader) {
          FacetsAccumulator fa = new StandardFacetsAccumulator(facetSearchParams, indexReader, taxonomyReader);
          fa.setComplementThreshold(FacetsAccumulator.DISABLE_COMPLEMENT);
          return fa;
        }
      };
     
      searcher.search(new MatchAllDocsQuery(), fc2);
      List<FacetResult> baseResults = fc2.getFacetResults();
      FacetResult baseRes = baseResults.get(0);

      // Removing the first line which holds the REQUEST and this is surly different between the two
      String baseResultString = baseRes.toString();
      baseResultString = baseResultString.substring(baseResultString.indexOf('\n'));
     
      // Removing the first line
      String resultString = res.toString();
      resultString = resultString.substring(resultString.indexOf('\n'));
View Full Code Here

TOP

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

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.