Package org.apache.lucene.facet.taxonomy.directory

Examples of org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader


      iw.close();
      tw.commit();
      tw.close();

      IndexSearcher is = newSearcher(ir);
      DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(tDir);

      // Get all of the documents and run the query, then do different
      // facet counts and compare to control
      Query q = new TermQuery(new Term("content", "alpha"));

      CountFacetRequest cfra23 = new CountFacetRequest(new CategoryPath("a"), 2);
      cfra23.setDepth(3);
      cfra23.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfra22 = new CountFacetRequest(new CategoryPath("a"), 2);
      cfra22.setDepth(2);
      cfra22.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfra21 = new CountFacetRequest(new CategoryPath("a"), 2);
      cfra21.setDepth(1);
      cfra21.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfrb22 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
      cfrb22.setDepth(2);
      cfrb22.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfrb23 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
      cfrb23.setDepth(3);
      cfrb23.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfrb21 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
      cfrb21.setDepth(1);
      cfrb21.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest doctor = new CountFacetRequest(new CategoryPath("Doctor"), 2);
      doctor.setDepth(1);
      doctor.setResultMode(ResultMode.PER_NODE_IN_TREE);

      CountFacetRequest cfrb20 = new CountFacetRequest(new CategoryPath("a", "b"), 2);
      cfrb20.setDepth(0);
      cfrb20.setResultMode(ResultMode.PER_NODE_IN_TREE);

      List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
      facetRequests.add(cfra23);
      facetRequests.add(cfra22);
      facetRequests.add(cfra21);
      facetRequests.add(cfrb23);
      facetRequests.add(cfrb22);
      facetRequests.add(cfrb21);
      facetRequests.add(doctor);
      facetRequests.add(cfrb20);
      FacetSearchParams facetSearchParams = new FacetSearchParams(iParams, facetRequests);
     
      FacetArrays facetArrays = new FacetArrays(PartitionsUtils.partitionSize(facetSearchParams.indexingParams, tr));
      OldFacetsAccumulator sfa = new OldFacetsAccumulator(facetSearchParams, is.getIndexReader(), tr, facetArrays);
      sfa.setComplementThreshold(OldFacetsAccumulator.DISABLE_COMPLEMENT);
      FacetsCollector fc = FacetsCollector.create(sfa);
     
      is.search(q, fc);
      List<FacetResult> facetResults = fc.getFacetResults();

      FacetResult fr = facetResults.get(0); // a, depth=3, K=2
      boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
      assertEquals(9, fr.getNumValidDescendants());
      FacetResultNode parentRes = fr.getFacetResultNode();
      assertEquals(2, parentRes.subResults.size());
      // two nodes sorted by descending values: a/b with 8  and a/c with 6
      // a/b has two children a/b/2 with value 3, and a/b/1 with value 2.
      // a/c has one child a/c/1 with value 1.
      double [] expectedValues0 = { 8.0, 3.0, 2.0, 6.0, 1.0 };
      int i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues0[i++], node.value, Double.MIN_VALUE);
        for (FacetResultNode node2 : node.subResults) {
          assertEquals(expectedValues0[i++], node2.value, 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 one child a/c/1 with value 1
      // then a/b with value 5, and both children: a/b/2 with value 3, and a/b/1 with value 2.
      for (FacetResultNode node : parentRes.subResults) {
        node.value = 5.0;
        break;
      }
      // now rearrange
      double [] expectedValues00 = { 6.0, 1.0, 5.0, 3.0, 2.0 };
      fr = sfa.createFacetResultsHandler(cfra23, sfa.createOrdinalValueResolver(cfra23)).rearrangeFacetResult(fr);
      i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues00[i++], node.value, Double.MIN_VALUE);
        for (FacetResultNode node2 : node.subResults) {
          assertEquals(expectedValues00[i++], node2.value, Double.MIN_VALUE);
        }
      }

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

      fr = facetResults.get(2); // a, depth=1, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
      assertEquals(4, fr.getNumValidDescendants(), 4);
      parentRes = fr.getFacetResultNode();
      assertEquals(2, parentRes.subResults.size());
      // two nodes sorted by descending values:
      // a/b with value 8 and a/c with value 6
      double [] expectedValues2 = { 8.0, 6.0, 0.0};
      i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues2[i++], node.value, Double.MIN_VALUE);
        assertEquals(node.subResults.size(), 0);
      }
     
      fr = facetResults.get(3); // a/b, depth=3, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
      assertEquals(4, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.value, Double.MIN_VALUE);
      assertEquals(2, parentRes.subResults.size());
      double [] expectedValues3 = { 3.0, 2.0 };
      i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues3[i++], node.value, Double.MIN_VALUE);
        assertEquals(0, node.subResults.size());
      }

      fr = facetResults.get(4); // a/b, depth=2, K=2
      hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
      assertEquals(4, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.value, Double.MIN_VALUE);
      assertEquals(2, parentRes.subResults.size());
      i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues3[i++], node.value, Double.MIN_VALUE);
        assertEquals(0, node.subResults.size());
      }

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

      // doctor, depth=1, K=2
      assertTrue("Should have found an empty FacetResult " +
          "for a facet that doesn't exist in the index.", hasDoctor);
      assertEquals("Shouldn't have found more than 8 request.", 8, facetResults.size());

      fr = facetResults.get(7); // a/b, depth=0, K=2
      assertEquals(0, fr.getNumValidDescendants());
      parentRes = fr.getFacetResultNode();
      assertEquals(8.0, parentRes.value, Double.MIN_VALUE);
      assertEquals(0, parentRes.subResults.size());
      i = 0;
      for (FacetResultNode node : parentRes.subResults) {
        assertEquals(expectedValues3[i++], node.value, Double.MIN_VALUE);
        assertEquals(0, node.subResults.size());
      }

      ir.close();
      tr.close();
      iDir.close();
      tDir.close();
    }

  }
View Full Code Here


  public void testChildrenArraysInvariants() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    fillTaxonomy(tw);
    tw.close();
    TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    ParallelTaxonomyArrays ca = tr.getParallelTaxonomyArrays();
    int[] children = ca.children();
    assertEquals(tr.getSize(), children.length);
    int[] olderSiblingArray = ca.siblings();
    assertEquals(tr.getSize(), olderSiblingArray.length);
       
    // test that the "youngest child" of every category is indeed a child:
    int[] parents = tr.getParallelTaxonomyArrays().parents();
    for (int i=0; i<tr.getSize(); i++) {
      int youngestChild = children[i];
      if (youngestChild != TaxonomyReader.INVALID_ORDINAL) {
        assertEquals(i, parents[youngestChild]);
      }
    }
       
    // test that the "older sibling" of every category is indeed older (lower)
    // (it can also be INVALID_ORDINAL, which is lower than any ordinal)
    for (int i=0; i<tr.getSize(); i++) {
      assertTrue("olderSiblingArray["+i+"] should be <"+i, olderSiblingArray[i] < i);
    }
   
    // test that the "older sibling" of every category is indeed a sibling
    // (they share the same parent)
    for (int i=0; i<tr.getSize(); i++) {
      int sibling = olderSiblingArray[i];
      if (sibling == TaxonomyReader.INVALID_ORDINAL) {
        continue;
      }
      assertEquals(parents[i], parents[sibling]);
    }
   
    // And now for slightly more complex (and less "invariant-like"...)
    // tests:
   
    // test that the "youngest child" is indeed the youngest (so we don't
    // miss the first children in the chain)
    for (int i=0; i<tr.getSize(); i++) {
      // Find the really youngest child:
      int j;
      for (j=tr.getSize()-1; j>i; j--) {
        if (parents[j]==i) {
          break; // found youngest child
        }
      }
      if (j==i) { // no child found
        j=TaxonomyReader.INVALID_ORDINAL;
      }
      assertEquals(j, children[i]);
    }

    // test that the "older sibling" is indeed the least oldest one - and
    // not a too old one or -1 (so we didn't miss some children in the
    // middle or the end of the chain).
    for (int i=0; i<tr.getSize(); i++) {
      // Find the youngest older sibling:
      int j;
      for (j=i-1; j>=0; j--) {
        if (parents[j]==parents[i]) {
          break; // found youngest older sibling
        }
      }
      if (j<0) { // no sibling found
        j=TaxonomyReader.INVALID_ORDINAL;
      }
      assertEquals(j, olderSiblingArray[i]);
    }
 
    tr.close();
    indexDir.close();
  }
View Full Code Here

  public void testChildrenArraysGrowth() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.addCategory(new CategoryPath("hi", "there"));
    tw.commit();
    TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    ParallelTaxonomyArrays ca = tr.getParallelTaxonomyArrays();
    assertEquals(3, tr.getSize());
    assertEquals(3, ca.siblings().length);
    assertEquals(3, ca.children().length);
    assertTrue(Arrays.equals(new int[] { 1, 2, -1 }, ca.children()));
    assertTrue(Arrays.equals(new int[] { -1, -1, -1 }, ca.siblings()));
    tw.addCategory(new CategoryPath("hi", "ho"));
    tw.addCategory(new CategoryPath("hello"));
    tw.commit();
    // Before refresh, nothing changed..
    ParallelTaxonomyArrays newca = tr.getParallelTaxonomyArrays();
    assertSame(newca, ca); // we got exactly the same object
    assertEquals(3, tr.getSize());
    assertEquals(3, ca.siblings().length);
    assertEquals(3, ca.children().length);
    // After the refresh, things change:
    TaxonomyReader newtr = TaxonomyReader.openIfChanged(tr);
    assertNotNull(newtr);
    tr.close();
    tr = newtr;
    ca = tr.getParallelTaxonomyArrays();
    assertEquals(5, tr.getSize());
    assertEquals(5, ca.siblings().length);
    assertEquals(5, ca.children().length);
    assertTrue(Arrays.equals(new int[] { 4, 3, -1, -1, -1 }, ca.children()));
    assertTrue(Arrays.equals(new int[] { -1, -1, -1, 2, 1 }, ca.siblings()));
    tw.close();
    tr.close();
    indexDir.close();
  }
View Full Code Here

    TaxonomyWriter twBase = new DirectoryTaxonomyWriter(indexDirBase);
    twBase.addCategory(new CategoryPath("a", "0"));
    final CategoryPath abPath = new CategoryPath("a", "b");
    twBase.addCategory(abPath);
    twBase.commit();
    TaxonomyReader trBase = new DirectoryTaxonomyReader(indexDirBase);

    final ParallelTaxonomyArrays ca1 = trBase.getParallelTaxonomyArrays();
   
    final int abOrd = trBase.getOrdinal(abPath);
    final int abYoungChildBase1 = ca1.children()[abOrd];
   
    final int numCategories = atLeast(800);
    for (int i = 0; i < numCategories; i++) {
      twBase.addCategory(new CategoryPath("a", "b", Integer.toString(i)));
    }
    twBase.close();
   
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(trBase);
    assertNotNull(newTaxoReader);
    trBase.close();
    trBase = newTaxoReader;
   
    final ParallelTaxonomyArrays ca2 = trBase.getParallelTaxonomyArrays();
    final int abYoungChildBase2 = ca2.children()[abOrd];
   
    int numRetries = atLeast(50);
    for (int retry = 0; retry < numRetries; retry++) {
      assertConsistentYoungestChild(abPath, abOrd, abYoungChildBase1, abYoungChildBase2, retry, numCategories);
    }
   
    trBase.close();
    indexDirBase.close();
  }
View Full Code Here

    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.addCategory(new CategoryPath("a", "0"));
    tw.addCategory(abPath);
    tw.commit();
   
    final DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    for (int i = 0; i < numCategories; i++) {
      final CategoryPath cp = new CategoryPath("a", "b", Integer.toString(i));
      tw.addCategory(cp);
      assertEquals("Ordinal of "+cp+" must be invalid until Taxonomy Reader was refreshed", TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(cp));
    }
    tw.close();
   
    final AtomicBoolean stop = new AtomicBoolean(false);
    final Throwable[] error = new Throwable[] { null };
    final int retrieval[] = { 0 };
   
    Thread thread = new Thread("Child Arrays Verifier") {
      @Override
      public void run() {
        setPriority(1 + getPriority());
        try {
          while (!stop.get()) {
            int lastOrd = tr.getParallelTaxonomyArrays().parents().length - 1;
            assertNotNull("path of last-ord " + lastOrd + " is not found!", tr.getPath(lastOrd));
            assertChildrenArrays(tr.getParallelTaxonomyArrays(), retry, retrieval[0]++);
            sleep(10); // don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
          }
        } catch (Throwable e) {
          error[0] = e;
          stop.set(true);
        }
      }

      private void assertChildrenArrays(ParallelTaxonomyArrays ca, int retry, int retrieval) {
        final int abYoungChild = ca.children()[abOrd];
        assertTrue(
            "Retry "+retry+": retrieval: "+retrieval+": wrong youngest child for category "+abPath+" (ord="+abOrd+
            ") - must be either "+abYoungChildBase1+" or "+abYoungChildBase2+" but was: "+abYoungChild,
            abYoungChildBase1==abYoungChild ||
            abYoungChildBase2==ca.children()[abOrd]);
      }
    };
    thread.start();
   
    indexDir.setSleepMillis(1); // some delay for refresh
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    if (newTaxoReader != null) {
      newTaxoReader.close();
    }
   
    stop.set(true);
    thread.join();
    assertNull("Unexpcted exception at retry "+retry+" retrieval "+retrieval[0]+": \n"+stackTraceStr(error[0]), error[0]);
   
    tr.close();
  }
View Full Code Here

  @Test
  public void testSeparateReaderAndWriter() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.commit();
    TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);

    assertEquals(1, tr.getSize()); // the empty taxonomy has size 1 (the root)
    tw.addCategory(new CategoryPath("Author"));
    assertEquals(1, tr.getSize()); // still root only...
    assertNull(TaxonomyReader.openIfChanged(tr)); // this is not enough, because tw.commit() hasn't been done yet
    assertEquals(1, tr.getSize()); // still root only...
    tw.commit();
    assertEquals(1, tr.getSize()); // still root only...
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    assertNotNull(newTaxoReader);
    tr.close();
    tr = newTaxoReader;
   
    int author = 1;
    try {
      assertEquals(TaxonomyReader.ROOT_ORDINAL, tr.getParallelTaxonomyArrays().parents()[author]);
      // ok
    } catch (ArrayIndexOutOfBoundsException e) {
      fail("After category addition, commit() and refresh(), getParent for "+author+" should NOT throw exception");
    }
    assertEquals(2, tr.getSize()); // finally, see there are two categories

    // now, add another category, and verify that after commit and refresh
    // the parent of this category is correct (this requires the reader
    // to correctly update its prefetched parent vector), and that the
    // old information also wasn't ruined:
    tw.addCategory(new CategoryPath("Author", "Richard Dawkins"));
    int dawkins = 2;
    tw.commit();
    newTaxoReader = TaxonomyReader.openIfChanged(tr);
    assertNotNull(newTaxoReader);
    tr.close();
    tr = newTaxoReader;
    int[] parents = tr.getParallelTaxonomyArrays().parents();
    assertEquals(author, parents[dawkins]);
    assertEquals(TaxonomyReader.ROOT_ORDINAL, parents[author]);
    assertEquals(TaxonomyReader.INVALID_ORDINAL, parents[TaxonomyReader.ROOT_ORDINAL]);
    assertEquals(3, tr.getSize());
    tw.close();
    tr.close();
    indexDir.close();
  }
View Full Code Here

  @Test
  public void testSeparateReaderAndWriter2() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
    tw.commit();
    TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);

    // Test getOrdinal():
    CategoryPath author = new CategoryPath("Author");

    assertEquals(1, tr.getSize()); // the empty taxonomy has size 1 (the root)
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(author));
    tw.addCategory(author);
    // before commit and refresh, no change:
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(author));
    assertEquals(1, tr.getSize()); // still root only...
    assertNull(TaxonomyReader.openIfChanged(tr)); // this is not enough, because tw.commit() hasn't been done yet
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(author));
    assertEquals(1, tr.getSize()); // still root only...
    tw.commit();
    // still not enough before refresh:
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(author));
    assertEquals(1, tr.getSize()); // still root only...
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(tr);
    assertNotNull(newTaxoReader);
    tr.close();
    tr = newTaxoReader;
    assertEquals(1, tr.getOrdinal(author));
    assertEquals(2, tr.getSize());
    tw.close();
    tr.close();
    indexDir.close();
  }
View Full Code Here

    tw.addCategory(new CategoryPath("hi", "there"));
    tw.commit();
    // we deliberately not close the write now, and keep it open and
    // locked.
    // Verify that the writer worked:
    TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
    assertEquals(2, tr.getOrdinal(new CategoryPath("hi", "there")));
    // Try to open a second writer, with the first one locking the directory.
    // We expect to get a LockObtainFailedException.
    try {
      assertNull(new DirectoryTaxonomyWriter(indexDir));
      fail("should have failed to write in locked directory");
    } catch (LockObtainFailedException e) {
      // this is what we expect to happen.
    }
    // Remove the lock, and now the open should succeed, and we can
    // write to the new writer.
    DirectoryTaxonomyWriter.unlock(indexDir);
    TaxonomyWriter tw2 = new DirectoryTaxonomyWriter(indexDir);
    tw2.addCategory(new CategoryPath("hey"));
    tw2.close();
    // See that the writer indeed wrote:
    TaxonomyReader newtr = TaxonomyReader.openIfChanged(tr);
    assertNotNull(newtr);
    tr.close();
    tr = newtr;
    assertEquals(3, tr.getOrdinal(new CategoryPath("hey")));
    tr.close();
    tw.close();
    indexDir.close();
  }
View Full Code Here

  @Test
  public void testNRT() throws Exception {
    Directory dir = newDirectory();
    DirectoryTaxonomyWriter writer = new DirectoryTaxonomyWriter(dir);
    TaxonomyReader reader = new DirectoryTaxonomyReader(writer);
   
    CategoryPath cp = new CategoryPath("a");
    writer.addCategory(cp);
    TaxonomyReader newReader = TaxonomyReader.openIfChanged(reader);
    assertNotNull("expected a new instance", newReader);
    assertEquals(2, newReader.getSize());
    assertNotSame(TaxonomyReader.INVALID_ORDINAL, newReader.getOrdinal(cp));
    reader.close();
    reader = newReader;
   
    writer.close();
    reader.close();
   
    dir.close();
  }
View Full Code Here

  /** User runs a query and aggregates facets. */
  private List<FacetResult> search() throws IOException, ParseException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Aggregate categories by an expression that combines the document's score
    // and its popularity field
    Expression expr = JavascriptCompiler.compile("_score * sqrt(popularity)");
    SimpleBindings bindings = new SimpleBindings();
    bindings.add(new SortField("_score", SortField.Type.SCORE)); // the score of the document
    bindings.add(new SortField("popularity", SortField.Type.LONG)); // the value of the 'popularity' field

    FacetSearchParams fsp = new FacetSearchParams(
        new SumValueSourceFacetRequest(new CategoryPath("A"), 10, expr.getValueSource(bindings), true));

    // Aggregates the facet values
    FacetsCollector fc = FacetsCollector.create(fsp, searcher.getIndexReader(), taxoReader);

    // MatchAllDocsQuery is for "browsing" (counts facets
    // for all non-deleted docs in the index); normally
    // you'd use a "normal" query, and use MultiCollector to
    // wrap collecting the "normal" hits and also facets:
    searcher.search(new MatchAllDocsQuery(), fc);

    // Retrieve results
    List<FacetResult> facetResults = fc.getFacetResults();
   
    indexReader.close();
    taxoReader.close();
   
    return facetResults;
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader

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.