本文整理汇总了Java中org.apache.lucene.facet.LabelAndValue类的典型用法代码示例。如果您正苦于以下问题:Java LabelAndValue类的具体用法?Java LabelAndValue怎么用?Java LabelAndValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LabelAndValue类属于org.apache.lucene.facet包,在下文中一共展示了LabelAndValue类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: drilldownDataFromFacetResult
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
public List<DrilldownData.Term> drilldownDataFromFacetResult(FacetSuperCollector facetCollector, FacetRequest facet, String[] path, boolean hierarchical) throws IOException {
FacetResult result = facetCollector.getTopChildren(facet.maxTerms == 0 ? Integer.MAX_VALUE : facet.maxTerms, facet.fieldname, path);
if (result == null)
return null;
List<DrilldownData.Term> terms = new ArrayList<>();
for (LabelAndValue l : result.labelValues) {
DrilldownData.Term term = new DrilldownData.Term(l.label, l.value.intValue());
if (hierarchical) {
String[] newPath = new String[path.length + 1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[newPath.length - 1] = l.label;
term.subTerms = drilldownDataFromFacetResult(facetCollector, facet, newPath, hierarchical);
}
terms.add(term);
}
return terms;
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:18,代码来源:Lucene.java
示例2: getChromosomeIdsWhereVariationsPresentFacet
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
/**
* Returns a {@code List} of chromosome IDs for a project, specified by ID, where variations exist and satisfy a
* specified query
*
* @param projectId an ID of a project, which index to query
* @param query a query to filter variations
* @return a {@code List} of chromosome IDs
* @throws IOException
*/
public List<Long> getChromosomeIdsWhereVariationsPresentFacet(long projectId, Query query) throws IOException {
List<Long> chromosomeIds = new ArrayList<>();
try (
Directory index = fileManager.getIndexForProject(projectId);
IndexReader reader = DirectoryReader.open(index)
) {
if (reader.numDocs() == 0) {
return Collections.emptyList();
}
FacetsCollector facetsCollector = new FacetsCollector();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.search(query, facetsCollector);
Facets facets = new SortedSetDocValuesFacetCounts(new DefaultSortedSetDocValuesReaderState(reader,
FeatureIndexFields.FACET_CHR_ID.getFieldName()), facetsCollector);
FacetResult res = facets.getTopChildren(FACET_LIMIT, FeatureIndexFields.CHR_ID.getFieldName());
if (res == null) {
return Collections.emptyList();
}
for (LabelAndValue labelAndValue : res.labelValues) {
chromosomeIds.add(Long.parseLong(labelAndValue.label));
}
}
return chromosomeIds;
}
开发者ID:react-dev26,项目名称:NGB-master,代码行数:39,代码来源:FeatureIndexDao.java
示例3: processFacetResults
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
/**
* Processes the faceting results and adds them to the QueryResults builder.
*
* @param indexSearcher the IndexSearcher performing the query
* @param facetsCollector the FacetsCollector that was used for the search
* @param facetFields the fields to Facet on
* @param resultBuilder the QueryResults.Builder
* @throws IOException if an error occurs performing faceting
*/
protected void processFacetResults(final IndexSearcher indexSearcher, final FacetsCollector facetsCollector, final Set<String> facetFields,
final QueryResults.Builder<QR> resultBuilder) throws IOException {
if (facetFields == null) {
return;
}
for (String facetField : facetFields) {
final List<FacetCount> facetResultCounts = new ArrayList<>();
// TODO this will produce an exception if no documents were indexed with the field to facet on
// java.lang.IllegalArgumentException: field "foo" was not indexed with SortedSetDocValues
// at org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState.<init>(DefaultSortedSetDocValuesReaderState.java:72)
if (facetsCollector.getMatchingDocs() != null && facetsCollector.getMatchingDocs().size() > 0) {
final SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(indexSearcher.getIndexReader(), facetField);
final Facets facets = new SortedSetDocValuesFacetCounts(state, facetsCollector);
org.apache.lucene.facet.FacetResult result = facets.getTopChildren(10, facetField);
for (int i = 0; i < result.childCount; i++) {
LabelAndValue lv = result.labelValues[i];
facetResultCounts.add(new FacetCount(lv.label, lv.value.longValue()));
}
}
resultBuilder.addFacetResult(new FacetResult(facetField, facetResultCounts));
}
}
开发者ID:bbende,项目名称:tripod,代码行数:36,代码来源:LuceneService.java
示例4: getChromosomeIdsWhereVariationsPresentFacet
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
/**
* Returns a {@code List} of chromosome IDs for a project, specified by ID, where variations exist and satisfy a
* specified query
*
* @param projectId an ID of a project, which index to query
* @param query a query to filter variations
* @return a {@code List} of chromosome IDs
* @throws IOException
*/
public List<Long> getChromosomeIdsWhereVariationsPresentFacet(long projectId, Query query) throws IOException {
List<Long> chromosomeIds = new ArrayList<>();
try (
Directory index = fileManager.getIndexForProject(projectId);
IndexReader reader = DirectoryReader.open(index)
) {
if (reader.numDocs() == 0) {
return Collections.emptyList();
}
FacetsCollector facetsCollector = new FacetsCollector();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.search(query, facetsCollector);
Facets facets = new SortedSetDocValuesFacetCounts(new DefaultSortedSetDocValuesReaderState(reader,
FeatureIndexFields.FACET_CHR_ID.getFieldName()), facetsCollector);
FacetResult res = facets.getTopChildren(FACET_LIMIT, FeatureIndexFields.CHR_ID.getFieldName());
if (res == null) {
return Collections.emptyList();
}
for (LabelAndValue labelAndValue : res.labelValues) {
chromosomeIds.add(Long.parseLong(labelAndValue.label));
}
}
return chromosomeIds;
}
开发者ID:epam,项目名称:NGB,代码行数:39,代码来源:FeatureIndexDao.java
示例5: getTopChildren
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) {
if (dim.equals(field) == false) {
throw new IllegalArgumentException("invalid dim \"" + dim + "\"; should be \"" + field + "\"");
}
if (path.length != 0) {
throw new IllegalArgumentException("path.length should be 0");
}
LabelAndValue[] labelValues = new LabelAndValue[counts.length];
for(int i=0;i<counts.length;i++) {
labelValues[i] = new LabelAndValue(ranges[i].label, counts[i]);
}
return new FacetResult(dim, path, totCount, labelValues, labelValues.length);
}
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:RangeFacetCounts.java
示例6: testSegmentsWithoutCategoriesOrResults
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
public void testSegmentsWithoutCategoriesOrResults() throws Exception {
// tests the accumulator when there are segments with no results
Directory indexDir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setMergePolicy(NoMergePolicy.INSTANCE); // prevent merges
IndexWriter indexWriter = new IndexWriter(indexDir, iwc);
TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
FacetsConfig config = new FacetsConfig();
indexTwoDocs(taxoWriter, indexWriter, config, false); // 1st segment, no content, with categories
indexTwoDocs(taxoWriter, indexWriter, null, true); // 2nd segment, with content, no categories
indexTwoDocs(taxoWriter, indexWriter, config, true); // 3rd segment ok
indexTwoDocs(taxoWriter, indexWriter, null, false); // 4th segment, no content, or categories
indexTwoDocs(taxoWriter, indexWriter, null, true); // 5th segment, with content, no categories
indexTwoDocs(taxoWriter, indexWriter, config, true); // 6th segment, with content, with categories
indexTwoDocs(taxoWriter, indexWriter, null, true); // 7th segment, with content, no categories
IOUtils.close(indexWriter, taxoWriter);
DirectoryReader indexReader = DirectoryReader.open(indexDir);
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
IndexSearcher indexSearcher = newSearcher(indexReader);
// search for "f:a", only segments 1 and 3 should match results
Query q = new TermQuery(new Term("f", "a"));
FacetsCollector sfc = new FacetsCollector();
indexSearcher.search(q, sfc);
Facets facets = getTaxonomyFacetCounts(taxoReader, config, sfc);
FacetResult result = facets.getTopChildren(10, "A");
assertEquals("wrong number of children", 2, result.labelValues.length);
for (LabelAndValue labelValue : result.labelValues) {
assertEquals("wrong weight for child " + labelValue.label, 2, labelValue.value.intValue());
}
IOUtils.close(indexReader, taxoReader, indexDir, taxoDir);
}
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:TestTaxonomyFacetCounts.java
示例7: verifyResults
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
private void verifyResults(Directory indexDir, Directory taxoDir) throws IOException {
DirectoryReader indexReader = DirectoryReader.open(indexDir);
DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
IndexSearcher searcher = newSearcher(indexReader);
FacetsCollector collector = new FacetsCollector();
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, collector);
// tag facets
Facets tagFacets = new FastTaxonomyFacetCounts("$tags", taxoReader, facetConfig, collector);
FacetResult result = tagFacets.getTopChildren(10, "tag");
for (LabelAndValue lv: result.labelValues) {
if (VERBOSE) {
System.out.println(lv);
}
assertEquals(NUM_DOCS, lv.value.intValue());
}
// id facets
Facets idFacets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, collector);
FacetResult idResult = idFacets.getTopChildren(10, "id");
assertEquals(NUM_DOCS, idResult.childCount);
assertEquals(NUM_DOCS * 2, idResult.value); // each "id" appears twice
BinaryDocValues bdv = MultiDocValues.getBinaryValues(indexReader, "bdv");
BinaryDocValues cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv");
for (int i = 0; i < indexReader.maxDoc(); i++) {
assertEquals(Integer.parseInt(cbdv.get(i).utf8ToString()), Integer.parseInt(bdv.get(i).utf8ToString())*2);
}
IOUtils.close(indexReader, taxoReader);
}
开发者ID:europeana,项目名称:search,代码行数:32,代码来源:TestOrdinalMappingAtomicReader.java
示例8: testFacetSuperCollector
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
@Test
public void testFacetSuperCollector() throws Throwable {
Lucene I = new Lucene(this.tmpDir, new LuceneSettings());
for (int i = 0; i < 1000; i++) {
Map<String, String> fields = new HashMap<String, String>();
fields.put("field1", Integer.toString(i));
fields.put("field2", new String(new char[1000]).replace("\0", Integer.toString(i)));
Map<String, String> facets = new HashMap<String, String>();
facets.put("facet1", "value" + (i % 100));
Document document1 = createDocument(fields,facets);
I.addDocument("id" + i, document1);
}
I.close();
I = new Lucene(this.tmpDir, new LuceneSettings());
FacetSuperCollector C = new FacetSuperCollector(I.data.getManager().acquire().taxonomyReader, I.data.getFacetsConfig(), new DocValuesOrdinalsReader());
MatchAllDocsQuery Q = new MatchAllDocsQuery();
I.search(Q, null, C);
FacetResult tc = C.getTopChildren(10, "facet1");
LabelAndValue[] expected = new LabelAndValue[] {
new LabelAndValue("value90", 10),
new LabelAndValue("value91", 10),
new LabelAndValue("value92", 10),
new LabelAndValue("value93", 10),
new LabelAndValue("value94", 10),
new LabelAndValue("value95", 10),
new LabelAndValue("value96", 10),
new LabelAndValue("value97", 10),
new LabelAndValue("value98", 10),
new LabelAndValue("value99", 10)
};
assertArrayEquals(expected, tc.labelValues);
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:33,代码来源:SuperCollectorTest.java
示例9: makeFacets
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
private List<SearchFacet> makeFacets(FacetResult facetResult) {
if (facetResult != null) {
List<SearchFacet> facets = new ArrayList<>(
facetResult.labelValues.length);
for (LabelAndValue facet : facetResult.labelValues) {
facets.add(new LuceneSearchFacet(facetResult.dim, facet));
}
return facets;
} else {
return Collections.emptyList();
}
}
开发者ID:KolonelKustard,项目名称:discodj,代码行数:13,代码来源:LuceneSearchResults.java
示例10: getFacet
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
private SearchResponse.Lst getFacet(final Facets facets) throws IOException {
final SearchResponse.Lst facetCounts = new SearchResponse.Lst("facet_counts");
final List<SearchResponse.Lst> facetCountsList = Lists.newArrayList();
final SearchResponse.Lst facetFields = new SearchResponse.Lst("facet_fields");
final List<SearchResponse.Lst> facetFieldsList = Lists.newArrayList();
for (FacetResult facetResult : facets.getAllDims(Integer.MAX_VALUE)) {
final String label = facetResult.dim;
final SearchResponse.Lst facetLst = new SearchResponse.Lst(label);
final List<SearchResponse.Int> facetInts = Lists.newArrayList();
for (LabelAndValue labelValue : facetResult.labelValues) {
facetInts.add(new SearchResponse.Int(labelValue.label, labelValue.value.toString()));
}
facetLst.setInts(facetInts);
facetFieldsList.add(facetLst);
}
facetFields.setLsts(facetFieldsList);
facetCountsList.add(facetFields);
facetCounts.setLsts(facetCountsList);
return facetCounts;
}
开发者ID:RIPE-NCC,项目名称:whois,代码行数:29,代码来源:FullTextSearch.java
示例11: getTopChildren
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
if (topN <= 0) {
throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
}
DimConfig dimConfig = verifyDim(dim);
FacetLabel cp = new FacetLabel(dim, path);
int dimOrd = taxoReader.getOrdinal(cp);
if (dimOrd == -1) {
return null;
}
TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.min(taxoReader.getSize(), topN));
int bottomValue = 0;
int ord = children[dimOrd];
int totValue = 0;
int childCount = 0;
TopOrdAndIntQueue.OrdAndValue reuse = null;
while(ord != TaxonomyReader.INVALID_ORDINAL) {
if (values[ord] > 0) {
totValue += values[ord];
childCount++;
if (values[ord] > bottomValue) {
if (reuse == null) {
reuse = new TopOrdAndIntQueue.OrdAndValue();
}
reuse.ord = ord;
reuse.value = values[ord];
reuse = q.insertWithOverflow(reuse);
if (q.size() == topN) {
bottomValue = q.top().value;
}
}
}
ord = siblings[ord];
}
if (totValue == 0) {
return null;
}
if (dimConfig.multiValued) {
if (dimConfig.requireDimCount) {
totValue = values[dimOrd];
} else {
// Our sum'd value is not correct, in general:
totValue = -1;
}
} else {
// Our sum'd dim value is accurate, so we keep it
}
LabelAndValue[] labelValues = new LabelAndValue[q.size()];
for(int i=labelValues.length-1;i>=0;i--) {
TopOrdAndIntQueue.OrdAndValue ordAndValue = q.pop();
FacetLabel child = taxoReader.getPath(ordAndValue.ord);
labelValues[i] = new LabelAndValue(child.components[cp.length], ordAndValue.value);
}
return new FacetResult(dim, path, totValue, labelValues, childCount);
}
开发者ID:europeana,项目名称:search,代码行数:66,代码来源:IntTaxonomyFacets.java
示例12: getTopChildren
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
if (topN <= 0) {
throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
}
DimConfig dimConfig = verifyDim(dim);
FacetLabel cp = new FacetLabel(dim, path);
int dimOrd = taxoReader.getOrdinal(cp);
if (dimOrd == -1) {
return null;
}
TopOrdAndFloatQueue q = new TopOrdAndFloatQueue(Math.min(taxoReader.getSize(), topN));
float bottomValue = 0;
int ord = children[dimOrd];
float sumValues = 0;
int childCount = 0;
TopOrdAndFloatQueue.OrdAndValue reuse = null;
while(ord != TaxonomyReader.INVALID_ORDINAL) {
if (values[ord] > 0) {
sumValues += values[ord];
childCount++;
if (values[ord] > bottomValue) {
if (reuse == null) {
reuse = new TopOrdAndFloatQueue.OrdAndValue();
}
reuse.ord = ord;
reuse.value = values[ord];
reuse = q.insertWithOverflow(reuse);
if (q.size() == topN) {
bottomValue = q.top().value;
}
}
}
ord = siblings[ord];
}
if (sumValues == 0) {
return null;
}
if (dimConfig.multiValued) {
if (dimConfig.requireDimCount) {
sumValues = values[dimOrd];
} else {
// Our sum'd count is not correct, in general:
sumValues = -1;
}
} else {
// Our sum'd dim count is accurate, so we keep it
}
LabelAndValue[] labelValues = new LabelAndValue[q.size()];
for(int i=labelValues.length-1;i>=0;i--) {
TopOrdAndFloatQueue.OrdAndValue ordAndValue = q.pop();
FacetLabel child = taxoReader.getPath(ordAndValue.ord);
labelValues[i] = new LabelAndValue(child.components[cp.length], ordAndValue.value);
}
return new FacetResult(dim, path, sumValues, labelValues, childCount);
}
开发者ID:europeana,项目名称:search,代码行数:65,代码来源:FloatTaxonomyFacets.java
示例13: testManyFacetsInOneDocument
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
public void testManyFacetsInOneDocument() throws Exception {
assumeTrue("default Codec doesn't support huge BinaryDocValues", TestUtil.fieldSupportsHugeBinaryDocValues(FacetsConfig.DEFAULT_INDEX_FIELD_NAME));
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
FacetsConfig config = new FacetsConfig();
config.setMultiValued("dim", true);
int numLabels = TestUtil.nextInt(random(), 40000, 100000);
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
for (int i = 0; i < numLabels; i++) {
doc.add(new FacetField("dim", "" + i));
}
writer.addDocument(config.build(taxoWriter, doc));
// NRT open
IndexSearcher searcher = newSearcher(writer.getReader());
// NRT open
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
// Aggregate the facet counts:
FacetsCollector c = new FacetsCollector();
// MatchAllDocsQuery is for "browsing" (counts facets
// for all non-deleted docs in the index); normally
// you'd use a "normal" query, and use MultiCollector to
// wrap collecting the "normal" hits and also facets:
searcher.search(new MatchAllDocsQuery(), c);
Facets facets = getTaxonomyFacetCounts(taxoReader, config, c);
FacetResult result = facets.getTopChildren(Integer.MAX_VALUE, "dim");
assertEquals(numLabels, result.labelValues.length);
Set<String> allLabels = new HashSet<>();
for (LabelAndValue labelValue : result.labelValues) {
allLabels.add(labelValue.label);
assertEquals(1, labelValue.value.intValue());
}
assertEquals(numLabels, allLabels.size());
IOUtils.close(searcher.getIndexReader(), taxoWriter, writer, taxoReader, dir, taxoDir);
}
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:TestTaxonomyFacetCounts.java
示例14: searchWithFacets
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
private void searchWithFacets(FacetRequest facetRequest, Query q, IndexSearcher indexSearcher, TopDocsCollector<?> collector,
SegmentResponse.Builder segmentReponseBuilder) throws Exception {
FacetsCollector facetsCollector = new FacetsCollector();
indexSearcher.search(q, MultiCollector.wrap(collector, facetsCollector));
Facets facets = new FastTaxonomyFacetCounts(taxoReader, facetsConfig, facetsCollector);
for (CountRequest countRequest : facetRequest.getCountRequestList()) {
String label = countRequest.getFacetField().getLabel();
if (!indexConfig.existingFacet(label)) {
throw new Exception(label + " is not defined as a facetable field");
}
if (countRequest.hasSegmentFacets()) {
if (indexConfig.getNumberOfSegments() == 1) {
log.info("Segment facets is ignored with segments of 1 for facet <" + label + "> on index <" + indexName + ">");
}
if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) {
throw new IllegalArgumentException("Segment facets must be greater than or equal to max facets");
}
}
int numOfFacets;
if (indexConfig.getNumberOfSegments() > 1) {
if (countRequest.getSegmentFacets() != 0) {
numOfFacets = countRequest.getSegmentFacets();
}
else {
numOfFacets = countRequest.getMaxFacets() * 8;
}
}
else {
numOfFacets = countRequest.getMaxFacets();
}
FacetResult facetResult = null;
try {
if (indexConfig.getNumberOfSegments() > 1) {
if (countRequest.hasSegmentFacets() && countRequest.getSegmentFacets() == 0) {
//TODO: this not ideal
numOfFacets = taxoReader.getSize();
}
}
facetResult = facets.getTopChildren(numOfFacets, label);
}
catch (UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause.getMessage().contains(" was not indexed with SortedSetDocValues")) {
//this is when no data has been indexing into a facet or facet does not exist
}
else {
throw e;
}
}
FacetGroup.Builder fg = FacetGroup.newBuilder();
fg.setCountRequest(countRequest);
if (facetResult != null) {
for (LabelAndValue subResult : facetResult.labelValues) {
FacetCount.Builder facetCountBuilder = FacetCount.newBuilder();
facetCountBuilder.setCount(subResult.value.longValue());
facetCountBuilder.setFacet(subResult.label);
fg.addFacetCount(facetCountBuilder);
}
}
segmentReponseBuilder.addFacetGroup(fg);
}
}
开发者ID:lumongo,项目名称:lumongo,代码行数:76,代码来源:LumongoSegment.java
示例15: testFacetAndTopsMultiCollector
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
@Test
public void testFacetAndTopsMultiCollector() throws Throwable {
Lucene I = new Lucene(this.tmpDir, new LuceneSettings());
for (int i = 0; i < 99; i++) {
Map<String, String> fields = new HashMap<String, String>();
fields.put("field1", Integer.toString(i));
fields.put("field2", new String(new char[1000]).replace("\0", Integer.toString(i)));
Map<String, String> facets = new HashMap<String, String>();
facets.put("facet1", "value" + (i % 10));
Document document1 = createDocument(fields,facets);
I.addDocument("id" + i, document1);
}
I.maybeCommitAfterUpdate();
I.close();
I = new Lucene(this.tmpDir, new LuceneSettings());
FacetSuperCollector f = new FacetSuperCollector(I.data.getManager().acquire().taxonomyReader, I.data.getFacetsConfig(), new DocValuesOrdinalsReader());
TopScoreDocSuperCollector t = new TopScoreDocSuperCollector(10);
List<SuperCollector<?>> collectors = new ArrayList<SuperCollector<?>>();
collectors.add(t);
collectors.add(f);
MultiSuperCollector C = new MultiSuperCollector(collectors);
MatchAllDocsQuery Q = new MatchAllDocsQuery();
I.search(Q, null, C);
assertEquals(99, t.topDocs(0).totalHits);
assertEquals(10, t.topDocs(0).scoreDocs.length);
FacetResult tc = f.getTopChildren(10, "facet1");
LabelAndValue[] expected = new LabelAndValue[] {
new LabelAndValue("value0", 10),
new LabelAndValue("value1", 10),
new LabelAndValue("value2", 10),
new LabelAndValue("value3", 10),
new LabelAndValue("value4", 10),
new LabelAndValue("value5", 10),
new LabelAndValue("value6", 10),
new LabelAndValue("value7", 10),
new LabelAndValue("value8", 10),
new LabelAndValue("value9", 9)
};
assertArrayEquals(expected, tc.labelValues);
}
开发者ID:seecr,项目名称:meresco-lucene,代码行数:44,代码来源:SuperCollectorTest.java
示例16: LuceneSearchFacet
import org.apache.lucene.facet.LabelAndValue; //导入依赖的package包/类
LuceneSearchFacet(String fieldName, LabelAndValue facet) {
id = fieldName + ":" + facet.label;
name = facet.label;
numMatches = facet.value.longValue();
}
开发者ID:KolonelKustard,项目名称:discodj,代码行数:6,代码来源:LuceneSearchFacet.java
注:本文中的org.apache.lucene.facet.LabelAndValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论