Package org.apache.lucene.facet.taxonomy

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


 
  @Test
  public void testPartitionSizeWithCategories() throws Exception {
    FacetSearchParams fsp = new FacetSearchParams();
    Directory dir = newDirectory();
    TaxonomyWriter tw = new LuceneTaxonomyWriter(dir);
    tw.addCategory(new CategoryPath("a"));
    tw.commit();
    tw.close();
    TaxonomyReader tr = new LuceneTaxonomyReader(dir);
    assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr));
    assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr));
    tr.close();
    dir.close();
View Full Code Here


      };

      RandomIndexWriter iw = new RandomIndexWriter(random, iDir,
          newIndexWriterConfig(TEST_VERSION_CURRENT,
              new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
      TaxonomyWriter tw = new LuceneTaxonomyWriter(tDir);
      prvt_add(iParams, iw, tw, "a", "b");
      prvt_add(iParams, iw, tw, "a", "b", "1");
      prvt_add(iParams, iw, tw, "a", "b", "1");
      prvt_add(iParams, iw, tw, "a", "b", "2");
      prvt_add(iParams, iw, tw, "a", "b", "2");
      prvt_add(iParams, iw, tw, "a", "b", "2");
      prvt_add(iParams, iw, tw, "a", "b", "3");
      prvt_add(iParams, iw, tw, "a", "b", "4");
      prvt_add(iParams, iw, tw, "a", "c");
      prvt_add(iParams, iw, tw, "a", "c");
      prvt_add(iParams, iw, tw, "a", "c");
      prvt_add(iParams, iw, tw, "a", "c");
      prvt_add(iParams, iw, tw, "a", "c");
      prvt_add(iParams, iw, tw, "a", "c", "1");
      prvt_add(iParams, iw, tw, "a", "d");
      prvt_add(iParams, iw, tw, "a", "e");

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

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

      // Get all of the documents and run the query, then do different
View Full Code Here

      indexDir = newDirectory();
      taxoDir = newDirectory();
    }
   
    RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, getIndexWriterConfig(getAnalyzer()));
    TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE);
   
    populateIndex(iw, taxo, getFacetIndexingParams(partitionSize));
   
    // commit changes (taxonomy prior to search index for consistency)
    taxo.commit();
    iw.commit();
    taxo.close();
    iw.close();
   
    // prepare for searching
    taxoReader = new LuceneTaxonomyReader(taxoDir);
    indexReader = IndexReader.open(indexDir);
View Full Code Here

    // 4. Segment w/ categories, but only some results
   
    IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
    conf.setMergePolicy(NoMergePolicy.COMPOUND_FILES); // prevent merges, so we can control the index segments
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

    Map<String,OrdinalPolicy> policies = new HashMap<String,CategoryListParams.OrdinalPolicy>();
    policies.put(CP_B.components[0], OrdinalPolicy.ALL_PARENTS);
    policies.put(CP_C.components[0], OrdinalPolicy.NO_PARENTS);
    policies.put(CP_D.components[0], OrdinalPolicy.NO_PARENTS);
View Full Code Here

      @Override
      public CategoryListIterator createCategoryListIterator(int partition) throws IOException {
        return new AssertingCategoryListIterator(super.createCategoryListIterator(partition));
      }
    });
    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
    FacetFields facetFields = new FacetFields(taxoWriter, fip);
    indexTwoDocs(indexWriter, facetFields, false); // 1st segment, no content, with categories
    indexTwoDocs(indexWriter, null, true);         // 2nd segment, with content, no categories
    indexTwoDocs(indexWriter, facetFields, true)// 3rd segment ok
    indexTwoDocs(indexWriter, null, false);        // 4th segment, no content, or categories
View Full Code Here

  }

  private void index100Docs(Directory indexDir, Directory taxoDir, FacetIndexingParams fip) throws IOException {
    IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, null);
    IndexWriter w = new IndexWriter(indexDir, iwc);
    TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
   
    FacetFields facetFields = new FacetFields(tw, fip);
    for (int i = 0; i < 100; i++) {
      Document doc = new Document();
      CategoryPath cp = new CategoryPath("root",Integer.toString(i / 10), Integer.toString(i));
View Full Code Here

  @Test
  public void testSumScoreAggregator() throws Exception {
    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();

    TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));

    FacetFields facetFields = new FacetFields(taxonomyWriter);
    for(int i = atLeast(30); i > 0; --i) {
      Document doc = new Document();
      doc.add(new StringField("f", "v", Store.NO));
      facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
      iw.addDocument(doc);
    }
   
    taxonomyWriter.close();
    iw.close();
   
    DirectoryReader r = DirectoryReader.open(indexDir);
    DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
   
View Full Code Here

  @Test
  public void testMultiCountingLists() throws Exception {
    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();
   
    TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
   
    FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
    for(int i = atLeast(30); i > 0; --i) {
      Document doc = new Document();
      doc.add(new StringField("f", "v", Store.NO));
      List<CategoryPath> cats = new ArrayList<CategoryPath>();
      cats.add(new CategoryPath("a"));
      cats.add(new CategoryPath("b"));
      facetFields.addFields(doc, cats);
      iw.addDocument(doc);
    }
   
    taxonomyWriter.close();
    iw.close();
   
    DirectoryReader r = DirectoryReader.open(indexDir);
    DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
   
View Full Code Here

  @Test
  public void testCountAndSumScore() throws Exception {
    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();
   
    TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
    IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    FacetIndexingParams fip = new PerDimensionIndexingParams(Collections.singletonMap(new CategoryPath("b"), new CategoryListParams("$b")));
   
    FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
    for(int i = atLeast(30); i > 0; --i) {
      Document doc = new Document();
      doc.add(new StringField("f", "v", Store.NO));
      List<CategoryPath> cats = new ArrayList<CategoryPath>();
      cats.add(new CategoryPath("a"));
      cats.add(new CategoryPath("b"));
      facetFields.addFields(doc, cats);
      iw.addDocument(doc);
    }
   
    taxonomyWriter.close();
    iw.close();
   
    DirectoryReader r = DirectoryReader.open(indexDir);
    DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
   
View Full Code Here

    Random r = random();
    RandomIndexWriter writer = new RandomIndexWriter(r, dir,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(r, MockTokenizer.KEYWORD, false)));
   
    taxoDir = newDirectory();
    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
   
    for (int i = 0; i < 100; i++) {
      ArrayList<CategoryPath> paths = new ArrayList<CategoryPath>();
      Document doc = new Document();
      if (i % 2 == 0) { // 50
        doc.add(new TextField("content", "foo", Field.Store.NO));
      }
      if (i % 3 == 0) { // 33
        doc.add(new TextField("content", "bar", Field.Store.NO));
      }
      if (i % 4 == 0) { // 25
        if (r.nextBoolean()) {
          paths.add(new CategoryPath("a/1", '/'));
        } else {
          paths.add(new CategoryPath("a/2", '/'));
        }
      }
      if (i % 5 == 0) { // 20
        paths.add(new CategoryPath("b"));
      }
      FacetFields facetFields = new FacetFields(taxoWriter);
      if (paths.size() > 0) {
        facetFields.addFields(doc, paths);
      }
      writer.addDocument(doc);
    }
   
    taxoWriter.close();
    reader = writer.getReader();
    writer.close();
   
    taxo = new DirectoryTaxonomyReader(taxoDir);
  }
View Full Code Here

TOP

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

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.