当前位置: 首页>>代码示例>>Java>>正文


Java TaxonomyWriter类代码示例

本文整理汇总了Java中org.apache.lucene.facet.taxonomy.TaxonomyWriter的典型用法代码示例。如果您正苦于以下问题:Java TaxonomyWriter类的具体用法?Java TaxonomyWriter怎么用?Java TaxonomyWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TaxonomyWriter类属于org.apache.lucene.facet.taxonomy包,在下文中一共展示了TaxonomyWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMixedTypesInSameIndexField

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
public void testMixedTypesInSameIndexField() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  FacetsConfig config = new FacetsConfig();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);

  Document doc = new Document();
  doc.add(new IntAssociationFacetField(14, "a", "x"));
  doc.add(new FloatAssociationFacetField(55.0f, "b", "y"));
  try {
    writer.addDocument(config.build(taxoWriter, doc));
    fail("did not hit expected exception");
  } catch (IllegalArgumentException exc) {
    // expected
  }
  IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestTaxonomyFacetAssociations.java

示例2: testNoHierarchy

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
public void testNoHierarchy() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  FacetsConfig config = new FacetsConfig();
  config.setHierarchical("a", true);
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);

  Document doc = new Document();
  doc.add(new IntAssociationFacetField(14, "a", "x"));
  try {
    writer.addDocument(config.build(taxoWriter, doc));
    fail("did not hit expected exception");
  } catch (IllegalArgumentException exc) {
    // expected
  }
  IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestTaxonomyFacetAssociations.java

示例3: testRequireDimCount

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
public void testRequireDimCount() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
  FacetsConfig config = new FacetsConfig();
  config.setRequireDimCount("a", true);
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);

  Document doc = new Document();
  doc.add(new IntAssociationFacetField(14, "a", "x"));
  try {
    writer.addDocument(config.build(taxoWriter, doc));
    fail("did not hit expected exception");
  } catch (IllegalArgumentException exc) {
    // expected
  }
  IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestTaxonomyFacetAssociations.java

示例4: indexDocsWithFacetsAndSomeTerms

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private static void indexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, 
                                                    Map<String,Integer> expectedCounts) throws IOException {
  Random random = random();
  int numDocs = atLeast(random, 2);
  FacetsConfig config = getConfig();
  for (int i = 0; i < numDocs; i++) {
    Document doc = new Document();
    boolean hasContent = random.nextBoolean();
    if (hasContent) {
      addField(doc);
    }
    addFacets(doc, config, hasContent);
    indexWriter.addDocument(config.build(taxoWriter, doc));
  }
  indexWriter.commit(); // flush a segment
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestTaxonomyFacetCounts2.java

示例5: indexDocsWithFacetsAndSomeTerms

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private static void indexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, 
    ObjectToIntMap<CategoryPath> expectedCounts) throws IOException {
  Random random = random();
  int numDocs = atLeast(random, 2);
  FacetFields facetFields = new FacetFields(taxoWriter, fip);
  for (int i = 0; i < numDocs; i++) {
    Document doc = new Document();
    boolean hasContent = random.nextBoolean();
    if (hasContent) {
      addField(doc);
    }
    addFacets(doc, facetFields, hasContent);
    indexWriter.addDocument(doc);
  }
  indexWriter.commit(); // flush a segment
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:CountingFacetsAggregatorTest.java

示例6: testReallyNoNormsForDrillDown

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
public void testReallyNoNormsForDrillDown() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  iwc.setSimilarity(new PerFieldSimilarityWrapper() {
      final Similarity sim = new DefaultSimilarity();

      @Override
      public Similarity get(String name) {
        assertEquals("field", name);
        return sim;
      }
    });
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  FacetFields facetFields = new FacetFields(taxoWriter);      

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a/path", '/')));
  writer.addDocument(doc);
  writer.close();
  taxoWriter.close();
  dir.close();
  taxoDir.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:TestDemoFacets.java

示例7: addEntry

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private void addEntry(final IndexWriter indexWriter, final TaxonomyWriter taxonomyWriter, final RpslObject rpslObject) throws IOException {
    final Document document = new Document();
    document.add(new Field(PRIMARY_KEY_FIELD_NAME, Integer.toString(rpslObject.getObjectId()), INDEXED_NOT_TOKENIZED));
    document.add(new Field(OBJECT_TYPE_FIELD_NAME, rpslObject.getType().getName(), INDEXED_AND_TOKENIZED));
    document.add(new Field(LOOKUP_KEY_FIELD_NAME, rpslObject.getKey().toString(), INDEXED_NOT_TOKENIZED));

    for (final RpslAttribute attribute : rpslObject.getAttributes()) {
        if (FILTERED_ATTRIBUTES.contains(attribute.getType())){
          document.add(new Field(attribute.getKey(), sanitise(filterAttribute(attribute.getValue().trim())), NOT_INDEXED_NOT_TOKENIZED));
        } else if (!SKIPPED_ATTRIBUTES.contains(attribute.getType())) {
            document.add(new Field(attribute.getKey(), sanitise(attribute.getValue().trim()), INDEXED_AND_TOKENIZED));
        }
    }

    document.add(new FacetField(OBJECT_TYPE_FIELD_NAME, rpslObject.getType().getName()));

    indexWriter.addDocument(facetsConfig.build(taxonomyWriter, document));
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:19,代码来源:FullTextIndex.java

示例8: doLogic

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@Override
public int doLogic() throws Exception {
  TaxonomyWriter taxonomyWriter = getRunData().getTaxonomyWriter();
  if (taxonomyWriter != null) {
    taxonomyWriter.commit();
  } else {
    throw new IllegalStateException("TaxonomyWriter is not currently open");
  }
  
  return 1;
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:CommitTaxonomyIndexTask.java

示例9: processAssocFacetFields

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private void processAssocFacetFields(TaxonomyWriter taxoWriter,
    Map<String,List<AssociationFacetField>> byField, Document doc)
    throws IOException {
  for (Map.Entry<String,List<AssociationFacetField>> ent : byField.entrySet()) {
    byte[] bytes = new byte[16];
    int upto = 0;
    String indexFieldName = ent.getKey();
    for(AssociationFacetField field : ent.getValue()) {
      // NOTE: we don't add parents for associations
      checkTaxoWriter(taxoWriter);
      FacetLabel label = new FacetLabel(field.dim, field.path);
      int ordinal = taxoWriter.addCategory(label);
      if (upto + 4 > bytes.length) {
        bytes = ArrayUtil.grow(bytes, upto+4);
      }
      // big-endian:
      bytes[upto++] = (byte) (ordinal >> 24);
      bytes[upto++] = (byte) (ordinal >> 16);
      bytes[upto++] = (byte) (ordinal >> 8);
      bytes[upto++] = (byte) ordinal;
      if (upto + field.assoc.length > bytes.length) {
        bytes = ArrayUtil.grow(bytes, upto+field.assoc.length);
      }
      System.arraycopy(field.assoc.bytes, field.assoc.offset, bytes, upto, field.assoc.length);
      upto += field.assoc.length;
      
      // Drill down:
      for (int i = 1; i <= label.length; i++) {
        doc.add(new StringField(indexFieldName, pathToString(label.components, i), Field.Store.NO));
      }
    }
    doc.add(new BinaryDocValuesField(indexFieldName, new BytesRef(bytes, 0, upto)));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:FacetsConfig.java

示例10: testDefault

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@Test
public void testDefault() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();
  
  // create and open an index writer
  RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
      new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
  // create and open a taxonomy writer
  TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
  FacetsConfig config = getConfig();

  seedIndex(tw, iw, config);

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

  // prepare index reader and taxonomy.
  TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

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

  FacetsCollector sfc = performSearch(tr, ir, searcher);

  // Obtain facets results and hand-test them
  assertCorrectResults(getTaxonomyFacetCounts(tr, config, sfc));

  assertOrdinalsExist("$facets", ir);

  IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:33,代码来源:TestMultipleIndexFields.java

示例11: testCustom

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@Test
public void testCustom() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();
  
  // create and open an index writer
  RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
      new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
  // create and open a taxonomy writer
  TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);

  FacetsConfig config = getConfig();
  config.setIndexFieldName("Author", "$author");
  seedIndex(tw, iw, config);

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

  // prepare index reader and taxonomy.
  TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

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

  FacetsCollector sfc = performSearch(tr, ir, searcher);

  Map<String,Facets> facetsMap = new HashMap<>();
  facetsMap.put("Author", getTaxonomyFacetCounts(tr, config, sfc, "$author"));
  Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));

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

  assertOrdinalsExist("$facets", ir);
  assertOrdinalsExist("$author", ir);

  IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestMultipleIndexFields.java

示例12: testDifferentFieldsAndText

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@Test
public void testDifferentFieldsAndText() throws Exception {
  Directory indexDir = newDirectory();
  Directory taxoDir = newDirectory();

  // create and open an index writer
  RandomIndexWriter iw = new RandomIndexWriter(random(), indexDir, newIndexWriterConfig(
      new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
  // create and open a taxonomy writer
  TaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);

  FacetsConfig config = getConfig();
  config.setIndexFieldName("Band", "$bands");
  config.setIndexFieldName("Composer", "$composers");
  seedIndex(tw, iw, config);

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

  // prepare index reader and taxonomy.
  TaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

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

  FacetsCollector sfc = performSearch(tr, ir, searcher);

  Map<String,Facets> facetsMap = new HashMap<>();
  facetsMap.put("Band", getTaxonomyFacetCounts(tr, config, sfc, "$bands"));
  facetsMap.put("Composer", getTaxonomyFacetCounts(tr, config, sfc, "$composers"));
  Facets facets = new MultiFacets(facetsMap, getTaxonomyFacetCounts(tr, config, sfc));

  // Obtain facets results and hand-test them
  assertCorrectResults(facets);
  assertOrdinalsExist("$facets", ir);
  assertOrdinalsExist("$bands", ir);
  assertOrdinalsExist("$composers", ir);

  IOUtils.close(tr, ir, iw, tw, indexDir, taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:TestMultipleIndexFields.java

示例13: seedIndex

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private void seedIndex(TaxonomyWriter tw, RandomIndexWriter iw, FacetsConfig config) throws IOException {
  for (FacetField ff : CATEGORIES) {
    Document doc = new Document();
    doc.add(ff);
    doc.add(new TextField("content", "alpha", Field.Store.YES));
    iw.addDocument(config.build(tw, doc));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:TestMultipleIndexFields.java

示例14: beforeClass

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
  dir = newDirectory();
  taxoDir = newDirectory();
  // preparations - index, taxonomy, content
  
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

  // Cannot mix ints & floats in the same indexed field:
  config = new FacetsConfig();
  config.setIndexFieldName("int", "$facets.int");
  config.setMultiValued("int", true);
  config.setIndexFieldName("float", "$facets.float");
  config.setMultiValued("float", true);

  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);

  // index documents, 50% have only 'b' and all have 'a'
  for (int i = 0; i < 110; i++) {
    Document doc = new Document();
    // every 11th document is added empty, this used to cause the association
    // aggregators to go into an infinite loop
    if (i % 11 != 0) {
      doc.add(new IntAssociationFacetField(2, "int", "a"));
      doc.add(new FloatAssociationFacetField(0.5f, "float", "a"));
      if (i % 2 == 0) { // 50
        doc.add(new IntAssociationFacetField(3, "int", "b"));
        doc.add(new FloatAssociationFacetField(0.2f, "float", "b"));
      }
    }
    writer.addDocument(config.build(taxoWriter, doc));
  }
  
  taxoWriter.close();
  reader = writer.getReader();
  writer.close();
  taxoReader = new DirectoryTaxonomyReader(taxoDir);
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestTaxonomyFacetAssociations.java

示例15: indexDocsWithFacetsNoTerms

import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private static void indexDocsWithFacetsNoTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter, 
                                               Map<String,Integer> expectedCounts) throws IOException {
  Random random = random();
  int numDocs = atLeast(random, 2);
  FacetsConfig config = getConfig();
  for (int i = 0; i < numDocs; i++) {
    Document doc = new Document();
    addFacets(doc, config, false);
    indexWriter.addDocument(config.build(taxoWriter, doc));
  }
  indexWriter.commit(); // flush a segment
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:TestTaxonomyFacetCounts2.java


注:本文中的org.apache.lucene.facet.taxonomy.TaxonomyWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。