本文整理汇总了Java中org.apache.lucene.facet.FacetField类的典型用法代码示例。如果您正苦于以下问题:Java FacetField类的具体用法?Java FacetField怎么用?Java FacetField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FacetField类属于org.apache.lucene.facet包,在下文中一共展示了FacetField类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: forEach
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@Override
public void forEach(BiConsumer<String, Object> each) {
document.forEach(f -> {
if (f instanceof SortedSetDocValuesFacetField || f instanceof FacetField)
return;
String k = f.name();
switch (k) {
case NObject.ID:
break; //filtered
case NObject.BOUND:
break; //filtered
default:
each.accept(k, value(f));
break;
}
});
}
开发者ID:automenta,项目名称:spimedb,代码行数:20,代码来源:DObject.java
示例2: store
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@Override
public final void store(JsonNode entity) {
try {
verifyNotClosed();
Pair<Document, List<FacetField>> pair = this.transformer.entityToDocument(entity);
Document doc = pair.getElement1();
List<FacetField> facetFields = pair.getElement2();
if (facetFields != null) {
for (int i = 0; i < facetFields.size(); i++) {
String facetName = facetFields.get(i).dim;
boolean multievaluated = facetName.contains("[*]") || facetName.contains("[#]");
if (multievaluated) {
facetsConfig.setMultiValued(facetName, multievaluated);
}
doc.add(facetFields.get(i));
}
}
this.getIndexWriter().addDocument(this.facetsConfig.build(getTaxonomyWriter(), doc));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
开发者ID:brutusin,项目名称:flea-db,代码行数:23,代码来源:GenericFleaDB.java
示例3: entityToDocument
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public Pair<Document, List<FacetField>> entityToDocument(JsonNode jsonNode) {
if (jsonNode == null) {
return null;
}
try {
jsonSchema.validate(jsonNode);
} catch (ValidationException e) {
throw new RuntimeException("Error transforming entity: " + jsonNode, e);
}
Document doc = new Document();
doc.add(new Field(OBJECT_FIELD_NAME, jsonNode.toString(), NON_INDEXED_TYPE));
Pair<Document, List<FacetField>> ret = new Pair<Document, List<FacetField>>();
ret.setElement1(doc);
Pair<List<IndexableField>, List<FacetField>> indexTerms = getIndexTerms(jsonNode);
ret.setElement2(indexTerms.getElement2());
List<IndexableField> indexFields = indexTerms.getElement1();
for (IndexableField field : indexFields) {
doc.add(field);
}
return ret;
}
开发者ID:brutusin,项目名称:flea-db,代码行数:23,代码来源:JsonTransformer.java
示例4: addLuceneFacets
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
private void addLuceneFacets(String facetField, List<FacetField> list, JsonNode node) {
JsonNode.Type type = node.getNodeType();
if (type == JsonNode.Type.ARRAY) {
for (int i = 0; i < node.getSize(); i++) {
addLuceneFacets(facetField, list, node.get(i));
}
} else if (type == JsonNode.Type.OBJECT) {
Iterator<String> properties = node.getProperties();
while (properties.hasNext()) {
String propName = properties.next();
list.add(new FacetField(facetField, propName));
}
} else if (type == JsonNode.Type.STRING) {
list.add(new FacetField(facetField, node.asString()));
} else if (type == JsonNode.Type.BOOLEAN) {
list.add(new FacetField(facetField, node.asString()));
} else {
throw new UnsupportedOperationException("Node type " + type + " not supported for facet field " + facetField);
}
}
开发者ID:brutusin,项目名称:flea-db,代码行数:21,代码来源:JsonTransformer.java
示例5: getNextFacets
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@Override
public void getNextFacets(List<FacetField> facets) throws NoMoreDataException, IOException {
facets.clear();
int numFacets = 1 + random.nextInt(maxDocFacets); // at least one facet to each doc
for (int i = 0; i < numFacets; i++) {
int depth;
if (maxFacetDepth == 2) {
depth = 2;
} else {
depth = 2 + random.nextInt(maxFacetDepth-2); // depth < 2 is not useful
}
String dim = Integer.toString(random.nextInt(maxDims));
String[] components = new String[depth-1];
for (int k = 0; k < depth-1; k++) {
components[k] = Integer.toString(random.nextInt(maxValue));
addItem();
}
FacetField ff = new FacetField(dim, components);
facets.add(ff);
addBytes(ff.toString().length()); // very rough approximation
}
}
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:RandomFacetSource.java
示例6: index
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
/** Build the example index. */
private void index() throws IOException {
IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER,
new WhitespaceAnalyzer()));
// Writes facet ords to a separate directory from the main index
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
Document doc = new Document();
doc.add(new TextField("c", "foo bar", Store.NO));
doc.add(new NumericDocValuesField("popularity", 5L));
doc.add(new FacetField("A", "B"));
indexWriter.addDocument(config.build(taxoWriter, doc));
doc = new Document();
doc.add(new TextField("c", "foo foo bar", Store.NO));
doc.add(new NumericDocValuesField("popularity", 3L));
doc.add(new FacetField("A", "C"));
indexWriter.addDocument(config.build(taxoWriter, doc));
indexWriter.close();
taxoWriter.close();
}
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ExpressionAggregationFacetsExample.java
示例7: testReallyNoNormsForDrillDown
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public void testReallyNoNormsForDrillDown() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setSimilarity(new PerFieldSimilarityWrapper() {
final Similarity sim = new DefaultSimilarity();
@Override
public Similarity get(String name) {
assertEquals("field", name);
return sim;
}
});
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
FacetsConfig config = new FacetsConfig();
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
doc.add(new FacetField("a", "path"));
writer.addDocument(config.build(taxoWriter, doc));
IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestTaxonomyFacetCounts.java
示例8: testDetectHierarchicalField
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public void testDetectHierarchicalField() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
FacetsConfig config = new FacetsConfig();
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
doc.add(new FacetField("a", "path", "other"));
try {
config.build(taxoWriter, doc);
fail("did not hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestTaxonomyFacetCounts.java
示例9: testDetectMultiValuedField
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public void testDetectMultiValuedField() throws Exception {
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
FacetsConfig config = new FacetsConfig();
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
doc.add(new FacetField("a", "path"));
doc.add(new FacetField("a", "path2"));
try {
config.build(taxoWriter, doc);
fail("did not hit expected exception");
} catch (IllegalArgumentException iae) {
// expected
}
IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestTaxonomyFacetCounts.java
示例10: testChildCount
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public void testChildCount() throws Exception {
// LUCENE-4885: FacetResult.numValidDescendants was not set properly by FacetsAccumulator
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
FacetsConfig config = new FacetsConfig();
for (int i = 0; i < 10; i++) {
Document doc = new Document();
doc.add(new FacetField("a", Integer.toString(i)));
iw.addDocument(config.build(taxoWriter, doc));
}
DirectoryReader r = DirectoryReader.open(iw, true);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
FacetsCollector sfc = new FacetsCollector();
newSearcher(r).search(new MatchAllDocsQuery(), sfc);
Facets facets = getTaxonomyFacetCounts(taxoReader, config, sfc);
assertEquals(10, facets.getTopChildren(2, "a").childCount);
IOUtils.close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir);
}
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestTaxonomyFacetCounts.java
示例11: indexTwoDocs
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
private void indexTwoDocs(TaxonomyWriter taxoWriter, IndexWriter indexWriter, FacetsConfig config, boolean withContent) throws Exception {
for (int i = 0; i < 2; i++) {
Document doc = new Document();
if (withContent) {
doc.add(new StringField("f", "a", Field.Store.NO));
}
if (config != null) {
doc.add(new FacetField("A", Integer.toString(i)));
indexWriter.addDocument(config.build(taxoWriter, doc));
} else {
indexWriter.addDocument(doc);
}
}
indexWriter.commit();
}
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TestTaxonomyFacetCounts.java
示例12: buildIndexWithFacets
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
private void buildIndexWithFacets(Directory indexDir, Directory taxoDir, boolean asc) throws IOException {
IndexWriterConfig config = newIndexWriterConfig(null);
RandomIndexWriter writer = new RandomIndexWriter(random(), indexDir, config);
DirectoryTaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxoDir);
for (int i = 1; i <= NUM_DOCS; i++) {
Document doc = new Document();
for (int j = i; j <= NUM_DOCS; j++) {
int facetValue = asc ? j: NUM_DOCS - j;
doc.add(new FacetField("tag", Integer.toString(facetValue)));
}
// add a facet under default dim config
doc.add(new FacetField("id", Integer.toString(i)));
// make sure OrdinalMappingAtomicReader ignores non-facet BinaryDocValues fields
doc.add(new BinaryDocValuesField("bdv", new BytesRef(Integer.toString(i))));
doc.add(new BinaryDocValuesField("cbdv", new BytesRef(Integer.toString(i*2))));
writer.addDocument(facetConfig.build(taxonomyWriter, doc));
}
taxonomyWriter.commit();
taxonomyWriter.close();
writer.commit();
writer.close();
}
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestOrdinalMappingAtomicReader.java
示例13: randomCategories
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
private static List<FacetField> randomCategories(Random random) {
// add random categories from the two dimensions, ensuring that the same
// category is not added twice.
int numFacetsA = random.nextInt(3) + 1; // 1-3
int numFacetsB = random.nextInt(2) + 1; // 1-2
ArrayList<FacetField> categories_a = new ArrayList<>();
categories_a.addAll(Arrays.asList(CATEGORIES_A));
ArrayList<FacetField> categories_b = new ArrayList<>();
categories_b.addAll(Arrays.asList(CATEGORIES_B));
Collections.shuffle(categories_a, random);
Collections.shuffle(categories_b, random);
ArrayList<FacetField> categories = new ArrayList<>();
categories.addAll(categories_a.subList(0, numFacetsA));
categories.addAll(categories_b.subList(0, numFacetsB));
// add the NO_PARENT categories
categories.add(CATEGORIES_C[random().nextInt(NUM_CHILDREN_CP_C)]);
categories.add(CATEGORIES_D[random().nextInt(NUM_CHILDREN_CP_D)]);
return categories;
}
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:TestTaxonomyFacetCounts2.java
示例14: addFacets
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
private static void addFacets(Document doc, FacetsConfig config, boolean updateTermExpectedCounts)
throws IOException {
List<FacetField> docCategories = randomCategories(random());
for (FacetField ff : docCategories) {
doc.add(ff);
String cp = ff.dim + "/" + ff.path[0];
allExpectedCounts.put(cp, allExpectedCounts.get(cp) + 1);
if (updateTermExpectedCounts) {
termExpectedCounts.put(cp, termExpectedCounts.get(cp) + 1);
}
}
// add 1 to each NO_PARENTS dimension
allExpectedCounts.put(CP_B, allExpectedCounts.get(CP_B) + 1);
allExpectedCounts.put(CP_C, allExpectedCounts.get(CP_C) + 1);
allExpectedCounts.put(CP_D, allExpectedCounts.get(CP_D) + 1);
if (updateTermExpectedCounts) {
termExpectedCounts.put(CP_B, termExpectedCounts.get(CP_B) + 1);
termExpectedCounts.put(CP_C, termExpectedCounts.get(CP_C) + 1);
termExpectedCounts.put(CP_D, termExpectedCounts.get(CP_D) + 1);
}
}
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TestTaxonomyFacetCounts2.java
示例15: testNoScore
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public void testNoScore() throws Exception {
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
FacetsConfig config = new FacetsConfig();
for (int i = 0; i < 4; i++) {
Document doc = new Document();
doc.add(new NumericDocValuesField("price", (i+1)));
doc.add(new FacetField("a", Integer.toString(i % 2)));
iw.addDocument(config.build(taxoWriter, doc));
}
DirectoryReader r = DirectoryReader.open(iw, true);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
FacetsCollector sfc = new FacetsCollector();
newSearcher(r).search(new MatchAllDocsQuery(), sfc);
Facets facets = new TaxonomyFacetSumValueSource(taxoReader, config, sfc, new LongFieldSource("price"));
assertEquals("dim=a path=[] value=10.0 childCount=2\n 1 (6.0)\n 0 (4.0)\n", facets.getTopChildren(10, "a").toString());
IOUtils.close(taxoWriter, iw, taxoReader, taxoDir, r, indexDir);
}
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestTaxonomyFacetSumValueSource.java
示例16: buildFacetField
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
protected IndexableField buildFacetField(String f, Object val) {
String[] path = null;
if (val instanceof String) {
path = ((String) val).split("/");
// path = new String[1];
// path[0] = (String) val;
} else if (val instanceof Iterable) {
Iterable iterable = (Iterable) val;
List<String> values = new ArrayList<String>();
for (Object s : iterable) {
if (s instanceof String) {
values.add((String) s);
} else {
throw new OIndexEngineException("Cannot facet value " + val + " because it is not a string", null);
}
}
path = values.toArray(new String[values.size()]);
}
return new FacetField(f, path);
}
开发者ID:orientechnologies,项目名称:orientdb-lucene,代码行数:22,代码来源:OLuceneFacetManager.java
示例17: testHierarchicalFacets
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@Test
public void testHierarchicalFacets() throws Throwable {
Document doc1 = new Document();
doc1.add(new StringField("field1", "id0", Store.NO));
doc1.add(new FacetField("facet-field", "first", "second"));
doc1.add(new FacetField("facet-field", "subfirst", "subsecond"));
this.lucene.getSettings().facetsConfig.setHierarchical("facet-field", true);
this.lucene.getSettings().facetsConfig.setMultiValued("facet-field", true);
this.lucene.addDocument("id1", doc1);
ArrayList<FacetRequest> facets = new ArrayList<FacetRequest>();
FacetRequest facet = new FacetRequest("facet-field", 10);
facet.path = new String[] {"first"};
facets.add(facet);
LuceneResponse result = lucene.executeQuery(new MatchAllDocsQuery(), facets);
assertEquals(1, result.total);
assertEquals(1, result.drilldownData.size());
assertEquals("facet-field", result.drilldownData.get(0).fieldname);
assertEquals(1, result.drilldownData.get(0).terms.size());
assertEquals("second", result.drilldownData.get(0).terms.get(0).label);
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:23,代码来源:LuceneTest.java
示例18: testFacetsInDifferentIndexFieldName
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@Test
public void testFacetsInDifferentIndexFieldName() throws Throwable {
FacetsConfig facetsConfig = lucene.getSettings().facetsConfig;
facetsConfig.setIndexFieldName("field0", "$facets_1");
facetsConfig.setIndexFieldName("field2", "$facets_1");
Document doc1 = new Document();
doc1.add(new FacetField("field0", "value0"));
doc1.add(new FacetField("field1", "value1"));
doc1.add(new FacetField("field2", "value2"));
lucene.addDocument("id0", doc1);
ArrayList<FacetRequest> facets = new ArrayList<FacetRequest>();
facets.add(new FacetRequest("field0", 10));
facets.add(new FacetRequest("field1", 10));
facets.add(new FacetRequest("field2", 10));
LuceneResponse result = lucene.executeQuery(new MatchAllDocsQuery(), facets);
assertEquals(3, result.drilldownData.size());
assertEquals("field0", result.drilldownData.get(0).fieldname);
assertEquals(1, result.drilldownData.get(0).terms.size());
assertEquals("field1", result.drilldownData.get(1).fieldname);
assertEquals(1, result.drilldownData.get(1).terms.size());
assertEquals("field2", result.drilldownData.get(2).fieldname);
assertEquals(1, result.drilldownData.get(2).terms.size());
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:26,代码来源:LuceneTest.java
示例19: testDrilldownFieldname
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testDrilldownFieldname() throws Throwable {
Document doc1 = new Document();
doc1.add(new FacetField("cat", "cat 1"));
lucene.addDocument("id1", doc1);
Document doc2 = new Document();
doc2.add(new FacetField("cat", "cat 2"));
lucene.addDocument("id2", doc2);
List<String> fieldnames = lucene.drilldownFieldnames(50, null);
assertEquals(1, fieldnames.size());
assertEquals(new ArrayList<String>() {{ add("cat"); }}, fieldnames);
fieldnames = lucene.drilldownFieldnames(50, "cat");
assertEquals(2, fieldnames.size());
assertEquals(new ArrayList<String>() {{ add("cat 2"); add("cat 1");}}, fieldnames);
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:20,代码来源:LuceneTest.java
示例20: addDocument
import org.apache.lucene.facet.FacetField; //导入依赖的package包/类
public static void addDocument(Lucene lucene, String identifier, Map<String, Integer> keys, Map<String, String> fields) throws Exception {
Document doc = new Document();
if (keys != null)
for (String keyField : keys.keySet())
doc.add(new NumericDocValuesField(keyField, keys.get(keyField)));
if (fields != null) {
for (String fieldname : fields.keySet())
if (fieldname.equals("intField"))
doc.add(new IntPoint(fieldname, Integer.parseInt(fields.get(fieldname))));
else {
doc.add(new StringField(fieldname, fields.get(fieldname), Store.NO));
doc.add(new SortedDocValuesField(fieldname, new BytesRef(fields.get(fieldname))));
doc.add(new FacetField("cat_" + fieldname, fields.get(fieldname)));
}
}
lucene.addDocument(identifier, doc);
lucene.maybeCommitAfterUpdate();
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:19,代码来源:LuceneTest.java
注:本文中的org.apache.lucene.facet.FacetField类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论