Package org.apache.lucene.facet.taxonomy

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


    }
  }
 
  @Test
  public void testTermNonDefault() {
    Term termA = DrillDownQuery.term(nonDefaultParams, new CategoryPath("a"));
    assertEquals(new Term("testing_facets_a", "a"), termA);
   
    Term termB = DrillDownQuery.term(nonDefaultParams, new CategoryPath("b"));
    assertEquals(new Term("testing_facets_b", "b"), termB);
  }
View Full Code Here


  }

  @Test
  public void testClone() throws Exception {
    DrillDownQuery q = new DrillDownQuery(defaultParams, new MatchAllDocsQuery());
    q.add(new CategoryPath("a"));
   
    DrillDownQuery clone = q.clone();
    clone.add(new CategoryPath("b"));
   
    assertFalse("query wasn't cloned: source=" + q + " clone=" + clone, q.toString().equals(clone.toString()));
  }
View Full Code Here

          public void run() {
            Random random = random();
            while (numCats.decrementAndGet() > 0) {
              String cat = Integer.toString(random.nextInt(range));
              try {
                tw.addCategory(new CategoryPath("a", cat));
              } catch (IOException e) {
                throw new RuntimeException(e);
              }
            }
          }
View Full Code Here

            destSize >= srcSize);
       
        // validate that all source categories exist in destination, and their
        // ordinals are as expected.
        for (int j = 1; j < srcSize; j++) {
          CategoryPath cp = srcTR.getPath(j);
          int destOrdinal = destTR.getOrdinal(cp);
          assertTrue(cp + " not found in destination", destOrdinal > 0);
          assertEquals(destOrdinal, map[j]);
        }
      } finally {
View Full Code Here

  }

  public void testAddEmpty() throws Exception {
    Directory dest = newDirectory();
    DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest);
    destTW.addCategory(new CategoryPath("Author", "Rob Pike"));
    destTW.addCategory(new CategoryPath("Aardvarks", "Bob"));
    destTW.commit();
   
    Directory src = newDirectory();
    new DirectoryTaxonomyWriter(src).close(); // create an empty taxonomy
   
View Full Code Here

  public void testAddToEmpty() throws Exception {
    Directory dest = newDirectory();
   
    Directory src = newDirectory();
    DirectoryTaxonomyWriter srcTW = new DirectoryTaxonomyWriter(src);
    srcTW.addCategory(new CategoryPath("Author", "Rob Pike"));
    srcTW.addCategory(new CategoryPath("Aardvarks", "Bob"));
    srcTW.close();
   
    DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest);
    OrdinalMap map = randomOrdinalMap();
    destTW.addTaxonomy(src, map);
View Full Code Here

  }
 
  public void testSimple() throws Exception {
    Directory dest = newDirectory();
    DirectoryTaxonomyWriter tw1 = new DirectoryTaxonomyWriter(dest);
    tw1.addCategory(new CategoryPath("Author", "Mark Twain"));
    tw1.addCategory(new CategoryPath("Animals", "Dog"));
    tw1.addCategory(new CategoryPath("Author", "Rob Pike"));
   
    Directory src = newDirectory();
    DirectoryTaxonomyWriter tw2 = new DirectoryTaxonomyWriter(src);
    tw2.addCategory(new CategoryPath("Author", "Rob Pike"));
    tw2.addCategory(new CategoryPath("Aardvarks", "Bob"));
    tw2.close();

    OrdinalMap map = randomOrdinalMap();

    tw1.addTaxonomy(src, map);
View Full Code Here

   
    // build an input taxonomy index
    Directory src = newDirectory();
    DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(src);
    for (int i = 0; i < numCategories; i++) {
      tw.addCategory(new CategoryPath("a", Integer.toString(i)));
    }
    tw.close();
   
    // now add the taxonomy to an empty taxonomy, while adding the categories
    // again, in parallel -- in the end, no duplicate categories should exist.
    Directory dest = newDirectory();
    final DirectoryTaxonomyWriter destTW = new DirectoryTaxonomyWriter(dest);
    Thread t = new Thread() {
      @Override
      public void run() {
        for (int i = 0; i < numCategories; i++) {
          try {
            destTW.addCategory(new CategoryPath("a", Integer.toString(i)));
          } catch (IOException e) {
            // shouldn't happen - if it does, let the test fail on uncaught exception.
            throw new RuntimeException(e);
          }
        }
      }
    };
    t.start();
   
    OrdinalMap map = new MemoryOrdinalMap();
    destTW.addTaxonomy(src, map);
    t.join();
    destTW.close();
   
    // now validate
   
    DirectoryTaxonomyReader dtr = new DirectoryTaxonomyReader(dest);
    // +2 to account for the root category + "a"
    assertEquals(numCategories + 2, dtr.getSize());
    HashSet<CategoryPath> categories = new HashSet<CategoryPath>();
    for (int i = 1; i < dtr.getSize(); i++) {
      CategoryPath cat = dtr.getPath(i);
      assertTrue("category " + cat + " already existed", categories.add(cat));
    }
    dtr.close();
   
    IOUtils.close(src, dest);
View Full Code Here

public class FacetRequestTest extends FacetTestCase {
 
  @Test(expected=IllegalArgumentException.class)
  public void testIllegalNumResults() throws Exception {
    assertNotNull(new CountFacetRequest(new CategoryPath("a", "b"), 0));
  }
View Full Code Here

    assertNotNull(new CountFacetRequest(null, 1));
  }
 
  @Test
  public void testHashAndEquals() {
    CountFacetRequest fr1 = new CountFacetRequest(new CategoryPath("a"), 8);
    CountFacetRequest fr2 = new CountFacetRequest(new CategoryPath("a"), 8);
    assertEquals("hashCode() should agree on both objects", fr1.hashCode(), fr2.hashCode());
    assertTrue("equals() should return true", fr1.equals(fr2));
    fr1.setDepth(10);
    assertFalse("equals() should return false as fr1.depth != fr2.depth", fr1.equals(fr2));
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.taxonomy.CategoryPath

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.