Examples of LuceneTaxonomyReader


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

  /** Search an index with a sum of int-association. */
  public static List<FacetResult> searchSumIntAssociation(Directory indexDir,
      Directory taxoDir) throws Exception {
    // prepare index reader
    IndexReader indexReader = IndexReader.open(indexDir);
    TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
   
    AssociationIntSumFacetRequest facetRequest = new AssociationIntSumFacetRequest(
        new CategoryPath("tags"), 10);
   
    List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
        AssociationUtils.assocIndexingParams, facetRequest);
   
    // close readers
    taxo.close();
    indexReader.close();
   
    return res;
  }
View Full Code Here

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

  /** Search an index with a sum of float-association. */
  public static List<FacetResult> searchSumFloatAssociation(Directory indexDir,
      Directory taxoDir) throws Exception {
    // prepare index reader
    IndexReader indexReader = IndexReader.open(indexDir);
    TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
   
    AssociationFloatSumFacetRequest facetRequest = new AssociationFloatSumFacetRequest(
        new CategoryPath("genre"), 10);
   
    List<FacetResult> res = SimpleSearcher.searchWithRequest(indexReader, taxo,
        AssociationUtils.assocIndexingParams, facetRequest);
   
    // close readers
    taxo.close();
    indexReader.close();
   
    return res;
  }
View Full Code Here

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

    // index the sample documents
    ExampleUtils.log("index the sample documents...");
    SimpleIndexer.index(indexDir, taxoDir);

    // open readers
    TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
    IndexReader indexReader = IndexReader.open(indexDir, true);

    ExampleUtils.log("search the sample documents...");
    List<FacetResult> facetRes = SimpleSearcher.searchWithFacets(indexReader, taxo);

    // close readers
    taxo.close();
    indexReader.close();
   
    ExampleResult res = new ExampleResult();
    res.setFacetResults(facetRes);
    return res;
View Full Code Here

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

    // index the sample documents
    ExampleUtils.log("index the sample documents...");
    SimpleIndexer.index(indexDir, taxoDir);

    // open readers
    TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir);
    IndexReader indexReader = IndexReader.open(indexDir, true);

    ExampleUtils.log("search the sample documents...");
    List<FacetResult> facetRes = SimpleSearcher.searchWithDrillDown(indexReader, taxo);
   
    // close readers
    taxo.close();
    indexReader.close();
   
    ExampleResult res = new ExampleResult();
    res.setFacetResults(facetRes);
    return res;
View Full Code Here

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

    w.addDocument(builder.build(new Document()));
    taxoW.close();
    IndexReader reader = w.getReader();
    w.close();
   
    LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(tDir);
    String field = iParams.getCategoryListParams(new CategoryPath("0")).getTerm().field();
    AssociationsPayloadIterator api = new AssociationsPayloadIterator(reader, field);

    api.setNextDoc(0);

    boolean flag = false;
    for (int i = 1; i <= NUM_CATEGORIES; i++) {
      int ordinal = taxo.getOrdinal(new CategoryPath(Integer.toString(i)));
      flag = true;
      long association = api.getAssociation(ordinal);
      assertTrue("Association expected for ordinal "+ordinal+" but none was found",
          association <= Integer.MAX_VALUE);
     
      assertEquals("Wrong association value for category '"+ i+"'", i, (int)association);
    }
   
    assertTrue("No categories found for doc #0", flag);
   
    reader.close();
    taxo.close();
    iDir.close();
    tDir.close();
  }
View Full Code Here

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

    TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir);
    // right after opening the index, it should already contain the
    // root, so have size 1:
    assertEquals(1, tw.getSize());
    tw.close();
    TaxonomyReader tr = new LuceneTaxonomyReader(indexDir);
    assertEquals(1, tr.getSize());
    assertEquals(0, tr.getPath(0).length());
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));
    assertEquals(0, tr.getOrdinal(new CategoryPath()));
    tr.close();
    indexDir.close();
  }
View Full Code Here

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

  @Test
  public void testRootOnly2() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir);
    tw.commit();
    TaxonomyReader tr = new LuceneTaxonomyReader(indexDir);
    assertEquals(1, tr.getSize());
    assertEquals(0, tr.getPath(0).length());
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));
    assertEquals(0, tr.getOrdinal(new CategoryPath()));
    tw.close();
    tr.close();
    indexDir.close();
  }
View Full Code Here

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

  public void testReaderBasic() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir);
    fillTaxonomy(tw);
    tw.close();
    TaxonomyReader tr = new LuceneTaxonomyReader(indexDir);

    // test TaxonomyReader.getSize():
    assertEquals(expectedCategories.length, tr.getSize());

    // test round trips of ordinal => category => ordinal
    for (int i=0; i<tr.getSize(); i++) {
      assertEquals(i, tr.getOrdinal(tr.getPath(i)));
    }

    // test TaxonomyReader.getCategory():
    for (int i=0; i<tr.getSize(); i++) {
      CategoryPath expectedCategory = new CategoryPath(expectedCategories[i]);
      CategoryPath category = tr.getPath(i);
      if (!expectedCategory.equals(category)) {
        fail("For ordinal "+i+" expected category "+
            showcat(expectedCategory)+", but got "+showcat(category));
      }
    }
    //  (also test invalid ordinals:)
    assertNull(tr.getPath(-1));
    assertNull(tr.getPath(tr.getSize()));
    assertNull(tr.getPath(TaxonomyReader.INVALID_ORDINAL));

    // test TaxonomyReader.getOrdinal():
    for (int i=0; i<expectedCategories.length; i++) {
      int expectedOrdinal = i;
      int ordinal = tr.getOrdinal(new CategoryPath(expectedCategories[i]));
      if (expectedOrdinal != ordinal) {
        fail("For category "+showcat(expectedCategories[i])+" expected ordinal "+
            expectedOrdinal+", but got "+ordinal);
      }
    }
    // (also test invalid categories:)
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(new CategoryPath("non-existant")));
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(new CategoryPath("Author", "Jules Verne")));

    tr.close();
    indexDir.close();
  }
View Full Code Here

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

  public void testReaderParent() throws Exception {
    Directory indexDir = newDirectory();
    TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir);
    fillTaxonomy(tw);
    tw.close();
    TaxonomyReader tr = new LuceneTaxonomyReader(indexDir);

    // check that the parent of the root ordinal is the invalid ordinal:
    assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));

    // check parent of non-root ordinals:
    for (int ordinal=1; ordinal<tr.getSize(); ordinal++) {
      CategoryPath me = tr.getPath(ordinal);
      int parentOrdinal = tr.getParent(ordinal);
      CategoryPath parent = tr.getPath(parentOrdinal);
      if (parent==null) {
        fail("Parent of "+ordinal+" is "+parentOrdinal+
        ", but this is not a valid category.");
      }
      // verify that the parent is indeed my parent, according to the strings
      if (!new CategoryPath(me, me.length()-1).equals(parent)) {
        fail("Got parent "+parentOrdinal+" for ordinal "+ordinal+
            " but categories are "+showcat(parent)+" and "+showcat(me)+
            " respectively.");
      }
    }

    // check parent of of invalid ordinals:
    try {
      tr.getParent(-1);
      fail("getParent for -1 should throw exception");
    } catch (ArrayIndexOutOfBoundsException e) {
      // ok
    }
    try {
      tr.getParent(TaxonomyReader.INVALID_ORDINAL);
      fail("getParent for INVALID_ORDINAL should throw exception");
    } catch (ArrayIndexOutOfBoundsException e) {
      // ok
    }
    try {
      int parent = tr.getParent(tr.getSize());
      fail("getParent for getSize() should throw exception, but returned "+parent);
    } catch (ArrayIndexOutOfBoundsException e) {
      // ok
    }

    tr.close();
    indexDir.close();
  }
View Full Code Here

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

    taxDir.close();
  }

  private void verifyResults(Directory dir, Directory taxDir) throws IOException {
    IndexReader reader1 = IndexReader.open(dir);
    LuceneTaxonomyReader taxReader = new LuceneTaxonomyReader(taxDir);
    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) {
        System.out.println(label + ": " + weight);
      }
      assertEquals(NUM_DOCS ,weight);
    }
    reader1.close();
    taxReader.close();
  }
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.