Examples of LuceneTaxonomyReader


Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    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 LuceneTaxonomyReader(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 {
      new LuceneTaxonomyWriter(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.
    LuceneTaxonomyWriter.unlock(indexDir);
    TaxonomyWriter tw2 = new LuceneTaxonomyWriter(indexDir);
    tw2.addCategory(new CategoryPath("hey"));
    tw2.close();
    // See that the writer indeed wrote:
    tr.refresh();
    assertEquals(3, tr.getOrdinal(new CategoryPath("hey")));
    tr.close();
    tw.close();
    indexDir.close();
  }
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    taxoDir = null;
  }
 
  @Test
  public void testIntSumAssociation() throws Exception {
    LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);

    // facet requests for two facets
    FacetSearchParams fsp = new FacetSearchParams();
    fsp.addFacetRequest(new AssociationIntSumFacetRequest(aint, 10));
    fsp.addFacetRequest(new AssociationIntSumFacetRequest(bint, 10));
   
    Query q = new MatchAllDocsQuery();

    FacetsCollector fc = new FacetsCollector(fsp, reader, taxo);
   
    IndexSearcher searcher = newSearcher(reader);
    searcher.search(q, fc);
    List<FacetResult> res = fc.getFacetResults();
   
    assertNotNull("No results!",res);
    assertEquals("Wrong number of results!",2, res.size());
    assertEquals("Wrong count for category 'a'!",200, (int) res.get(0).getFacetResultNode().getValue());
    assertEquals("Wrong count for category 'b'!",150, (int) res.get(1).getFacetResultNode().getValue());
   
    searcher.close();
    taxo.close();
  }
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    taxo.close();
  }
 
  @Test
  public void testFloatSumAssociation() throws Exception {
    LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);

    // facet requests for two facets
    FacetSearchParams fsp = new FacetSearchParams();
    fsp.addFacetRequest(new AssociationFloatSumFacetRequest(afloat, 10));
    fsp.addFacetRequest(new AssociationFloatSumFacetRequest(bfloat, 10));
   
    Query q = new MatchAllDocsQuery();

    FacetsCollector fc = new FacetsCollector(fsp, reader, taxo);
   
    IndexSearcher searcher = newSearcher(reader);
    searcher.search(q, fc);
    List<FacetResult> res = fc.getFacetResults();
   
    assertNotNull("No results!",res);
    assertEquals("Wrong number of results!",2, res.size());
    assertEquals("Wrong count for category 'a'!",50f, (float) res.get(0).getFacetResultNode().getValue(), 0.00001);
    assertEquals("Wrong count for category 'b'!",10f, (float) res.get(1).getFacetResultNode().getValue(), 0.00001);
   
    searcher.close();
    taxo.close();
 
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

  @Test
  public void testDifferentAggregatorsSameCategoryList() throws Exception {
    // Same category list cannot be aggregated by two different aggregators. If
    // you want to do that, you need to separate the categories into two
    // category list (you'll still have one association list).
    LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);

    // facet requests for two facets
    FacetSearchParams fsp = new FacetSearchParams();
    fsp.addFacetRequest(new AssociationIntSumFacetRequest(aint, 10));
    fsp.addFacetRequest(new AssociationIntSumFacetRequest(bint, 10));
    fsp.addFacetRequest(new AssociationFloatSumFacetRequest(afloat, 10));
    fsp.addFacetRequest(new AssociationFloatSumFacetRequest(bfloat, 10));
   
    Query q = new MatchAllDocsQuery();

    FacetsCollector fc = new FacetsCollector(fsp, reader, taxo);
   
    IndexSearcher searcher = newSearcher(reader);
    searcher.search(q, fc);
    try {
      fc.getFacetResults();
      fail("different aggregators for same category list should not be supported");
    } catch (RuntimeException e) {
      // ok - expected
    }
    searcher.close();
    taxo.close();
 
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    FacetIndexingParams iParams = new DefaultFacetIndexingParams(clp);
    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();
    populateIndex(iParams, indexDir, taxoDir);

    TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
    IndexReader reader = IndexReader.open(indexDir);

    CategoryListCache clCache = null;
    if (cacheCLI) {
      // caching the iteratorr, so:
      // 1: create the cached iterator, using original params
      clCache = new CategoryListCache();
      clCache.loadAndRegister(clp, reader, taxo, iParams);
    }
   
    ScoredDocIDs allDocs = ScoredDocIdsUtils
        .createAllDocsScoredDocIDs(reader);

    // Search index with 'author' should filter ONLY ordinals whose parent
    // is 'author'
    countForbiddenDimension = "date";
    validateFacetedSearch(iParams, taxo, reader, clCache, allDocs, "author", 5, 5);

    // Search index with 'date' should filter ONLY ordinals whose parent is
    // 'date'
    countForbiddenDimension = "author";
    validateFacetedSearch(iParams, taxo, reader, clCache, allDocs, "date", 5, 2);

    // Search index with both 'date' and 'author'
    countForbiddenDimension = null;
    validateFacetedSearch(iParams, taxo, reader, clCache, allDocs, new String[] {
            "author", "date" }, new int[] { 5, 5 }, new int[] { 5, 2 });
    taxo.close();
    reader.close();
    indexDir.close();
    taxoDir.close();
  }
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

   
    taxoWriter.close();
    reader = writer.getReader();
    writer.close();
   
    taxo = new LuceneTaxonomyReader(taxoDir);
  }
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    IndexReader ir = iw.getReader();
    tw.commit();

    // prepare index reader and taxonomy.
    TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]);

    // prepare searcher to search against
    IndexSearcher searcher = newSearcher(ir);

    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
        searcher);

    // Obtain facets results and hand-test them
    assertCorrectResults(facetsCollector);

    TermDocs td = ir.termDocs(new Term("$facets", "$fulltree$"));
    assertTrue(td.next());

    tr.close();
    ir.close();
    searcher.close();
    iw.close();
    tw.close();
    IOUtils.close(dirs[0]);
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    IndexReader ir = iw.getReader();
    tw.commit();

    // prepare index reader and taxonomy.
    TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]);

    // prepare searcher to search against
    IndexSearcher searcher = newSearcher(ir);

    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
        searcher);

    // Obtain facets results and hand-test them
    assertCorrectResults(facetsCollector);

    assertPostingListExists("$facets", "$fulltree$", ir);
    assertPostingListExists("$author", "Authors", ir);

    tr.close();
    ir.close();
    searcher.close();
    iw.close();
    tw.close();
    IOUtils.close(dirs[0]);
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    IndexReader ir = iw.getReader();
    tw.commit();

    // prepare index reader and taxonomy.
    TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]);

    // prepare searcher to search against
    IndexSearcher searcher = newSearcher(ir);

    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
        searcher);

    // Obtain facets results and hand-test them
    assertCorrectResults(facetsCollector);

    assertPostingListExists("$facets", "$fulltree$", ir);
    assertPostingListExists("$music", "Bands", ir);
    assertPostingListExists("$music", "Composers", ir);

    tr.close();
    ir.close();
    searcher.close();
    iw.close();
    tw.close();
    IOUtils.close(dirs[0]);
View Full Code Here

Examples of org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader

    IndexReader ir = iw.getReader();
    tw.commit();

    // prepare index reader and taxonomy.
    TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]);

    // prepare searcher to search against
    IndexSearcher searcher = newSearcher(ir);

    FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
        searcher);

    // Obtain facets results and hand-test them
    assertCorrectResults(facetsCollector);
    assertPostingListExists("$facets", "$fulltree$", ir);
    assertPostingListExists("$bands", "Bands", ir);
    assertPostingListExists("$composers", "Composers", ir);
    tr.close();
    ir.close();
    searcher.close();
    iw.close();
    tw.close();
    IOUtils.close(dirs[0]);
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.