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


Java FacetField类代码示例

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


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


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