本文整理汇总了Java中org.apache.lucene.facet.taxonomy.TaxonomyWriter类的典型用法代码示例。如果您正苦于以下问题:Java TaxonomyWriter类的具体用法?Java TaxonomyWriter怎么用?Java TaxonomyWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TaxonomyWriter类属于org.apache.lucene.facet.taxonomy包,在下文中一共展示了TaxonomyWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: indexDocsWithFacetsAndTerms
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private static void indexDocsWithFacetsAndTerms(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, true);
addField(doc);
indexWriter.addDocument(config.build(taxoWriter, doc));
}
indexWriter.commit(); // flush a segment
}
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:TestTaxonomyFacetCounts2.java
示例17: beforeClassCountingFacetsAggregatorTest
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
@BeforeClass
public static void beforeClassCountingFacetsAggregatorTest() throws Exception {
indexDir = newDirectory();
taxoDir = newDirectory();
// create an index which has:
// 1. Segment with no categories, but matching results
// 2. Segment w/ categories, but no results
// 3. Segment w/ categories and results
// 4. Segment w/ categories, but only some results
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
conf.setMergePolicy(NoMergePolicy.INSTANCE); // prevent merges, so we can control the index segments
IndexWriter indexWriter = new IndexWriter(indexDir, conf);
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
allExpectedCounts = newCounts();
termExpectedCounts = newCounts();
// segment w/ no categories
indexDocsNoFacets(indexWriter);
// segment w/ categories, no content
indexDocsWithFacetsNoTerms(indexWriter, taxoWriter, allExpectedCounts);
// segment w/ categories and content
indexDocsWithFacetsAndTerms(indexWriter, taxoWriter, allExpectedCounts);
// segment w/ categories and some content
indexDocsWithFacetsAndSomeTerms(indexWriter, taxoWriter, allExpectedCounts);
IOUtils.close(indexWriter, taxoWriter);
}
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:TestTaxonomyFacetCounts2.java
示例18: createIndex
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
private static void createIndex() throws IOException {
try (Analyzer analyzer = new WhitespaceAnalyzer();
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(analyzer));
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir)) {
for (final String author : new String[] { "Bob", "Lisa" }) {
final Document doc = new Document();
doc.add(new FacetField(AUTHOR_FACET, author));
doc.add(new StoredField(AUTHOR_FACET, author));
indexWriter.addDocument(config.build(taxoWriter, doc));
}
}
}
开发者ID:shaie,项目名称:lucenelab,代码行数:13,代码来源:NotDrillDownExample.java
示例19: CountingListBuilder
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
public CountingListBuilder(CategoryListParams categoryListParams, FacetIndexingParams indexingParams,
TaxonomyWriter taxoWriter) {
this.taxoWriter = taxoWriter;
this.clp = categoryListParams;
if (indexingParams.getPartitionSize() == Integer.MAX_VALUE) {
ordinalsEncoder = new NoPartitionsOrdinalsEncoder(categoryListParams);
} else {
ordinalsEncoder = new PerPartitionOrdinalsEncoder(indexingParams, categoryListParams);
}
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:11,代码来源:CountingListBuilder.java
示例20: initIndex
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; //导入依赖的package包/类
/** Prepare index (in RAM/Disk) with some documents and some facets. */
protected final void initIndex(boolean forceDisk, FacetIndexingParams fip) throws Exception {
int partitionSize = fip.getPartitionSize();
if (VERBOSE) {
System.out.println("Partition Size: " + partitionSize + " forceDisk: "+forceDisk);
}
SearchTaxoDirPair pair = dirsPerPartitionSize.get(Integer.valueOf(partitionSize));
if (pair == null) {
pair = new SearchTaxoDirPair();
if (forceDisk) {
pair.searchDir = newFSDirectory(new File(TEST_DIR, "index"));
pair.taxoDir = newFSDirectory(new File(TEST_DIR, "taxo"));
} else {
pair.searchDir = newDirectory();
pair.taxoDir = newDirectory();
}
RandomIndexWriter iw = new RandomIndexWriter(random(), pair.searchDir, getIndexWriterConfig(getAnalyzer()));
TaxonomyWriter taxo = new DirectoryTaxonomyWriter(pair.taxoDir, OpenMode.CREATE);
populateIndex(iw, taxo, fip);
// commit changes (taxonomy prior to search index for consistency)
taxo.commit();
iw.commit();
taxo.close();
iw.close();
dirsPerPartitionSize.put(Integer.valueOf(partitionSize), pair);
}
// prepare for searching
taxoReader = new DirectoryTaxonomyReader(pair.taxoDir);
indexReader = DirectoryReader.open(pair.searchDir);
searcher = newSearcher(indexReader);
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:38,代码来源:FacetTestBase.java
注:本文中的org.apache.lucene.facet.taxonomy.TaxonomyWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论