當前位置: 首頁>>代碼示例>>Java>>正文


Java FacetsAccumulator類代碼示例

本文整理匯總了Java中org.apache.lucene.facet.search.FacetsAccumulator的典型用法代碼示例。如果您正苦於以下問題:Java FacetsAccumulator類的具體用法?Java FacetsAccumulator怎麽用?Java FacetsAccumulator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FacetsAccumulator類屬於org.apache.lucene.facet.search包,在下文中一共展示了FacetsAccumulator類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sumAssociations

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
/** User runs a query and aggregates facets by summing their association values. */
private List<FacetResult> sumAssociations() throws IOException {
  DirectoryReader indexReader = DirectoryReader.open(indexDir);
  IndexSearcher searcher = new IndexSearcher(indexReader);
  TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
  
  CategoryPath tags = new CategoryPath("tags");
  CategoryPath genre = new CategoryPath("genre");
  FacetSearchParams fsp = new FacetSearchParams(
      new AssociationIntSumFacetRequest(tags, 10), 
      new AssociationFloatSumFacetRequest(genre, 10));

  // every category has a different type of association, so use chain their
  // respective aggregators.
  final Map<CategoryPath,FacetsAggregator> aggregators = new HashMap<CategoryPath,FacetsAggregator>();
  aggregators.put(tags, new SumIntAssociationFacetsAggregator());
  aggregators.put(genre, new SumFloatAssociationFacetsAggregator());
  FacetsAccumulator fa = new FacetsAccumulator(fsp, indexReader, taxoReader) {
    @Override
    public FacetsAggregator getAggregator() {
      return new MultiAssociationsFacetsAggregator(aggregators);
    }
  };
  FacetsCollector fc = FacetsCollector.create(fa);
  
  // 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(), fc);
  
  // Retrieve results
  List<FacetResult> facetResults = fc.getFacetResults();
  
  indexReader.close();
  taxoReader.close();
  
  return facetResults;
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:40,代碼來源:AssociationsFacetsExample.java

示例2: testIntSumAssociation

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
@Test
public void testIntSumAssociation() throws Exception {
  DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
  
  // facet requests for two facets
  FacetSearchParams fsp = new FacetSearchParams(
      new AssociationIntSumFacetRequest(aint, 10),
      new AssociationIntSumFacetRequest(bint, 10));
  
  Query q = new MatchAllDocsQuery();
  
  FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
    @Override
    public FacetsAggregator getAggregator() {
      return new SumIntAssociationFacetsAggregator();
    }
  };
  
  FacetsCollector fc = FacetsCollector.create(fa);
  
  IndexSearcher searcher = newSearcher(reader);
  searcher.search(q, fc);
  List<FacetResult> res = fc.getFacetResults();
  
  assertNotNull("No results!",res);
  assertEquals("Wrong number of results!",2, res.size());
  assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
  assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
  
  taxo.close();
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:32,代碼來源:AssociationsFacetRequestTest.java

示例3: testFloatSumAssociation

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
@Test
public void testFloatSumAssociation() throws Exception {
  DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
  
  // facet requests for two facets
  FacetSearchParams fsp = new FacetSearchParams(
      new AssociationFloatSumFacetRequest(afloat, 10),
      new AssociationFloatSumFacetRequest(bfloat, 10));
  
  Query q = new MatchAllDocsQuery();
  
  FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
    @Override
    public FacetsAggregator getAggregator() {
      return new SumFloatAssociationFacetsAggregator();
    }
  };
  
  FacetsCollector fc = FacetsCollector.create(fa);
  
  IndexSearcher searcher = newSearcher(reader);
  searcher.search(q, fc);
  List<FacetResult> res = fc.getFacetResults();
  
  assertNotNull("No results!",res);
  assertEquals("Wrong number of results!", 2, res.size());
  assertEquals("Wrong count for category 'a'!",50f, (float) res.get(0).getFacetResultNode().value, 0.00001);
  assertEquals("Wrong count for category 'b'!",10f, (float) res.get(1).getFacetResultNode().value, 0.00001);
  
  taxo.close();
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:32,代碼來源:AssociationsFacetRequestTest.java

示例4: testDifferentAggregatorsSameCategoryList

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
@Test
public void testDifferentAggregatorsSameCategoryList() throws Exception {
  DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
  
  // facet requests for two facets
  FacetSearchParams fsp = new FacetSearchParams(
      new AssociationIntSumFacetRequest(aint, 10),
      new AssociationIntSumFacetRequest(bint, 10),
      new AssociationFloatSumFacetRequest(afloat, 10),
      new AssociationFloatSumFacetRequest(bfloat, 10));
  
  Query q = new MatchAllDocsQuery();
  
  final SumIntAssociationFacetsAggregator sumInt = new SumIntAssociationFacetsAggregator();
  final SumFloatAssociationFacetsAggregator sumFloat = new SumFloatAssociationFacetsAggregator();
  final Map<CategoryPath,FacetsAggregator> aggregators = new HashMap<CategoryPath,FacetsAggregator>();
  aggregators.put(aint, sumInt);
  aggregators.put(bint, sumInt);
  aggregators.put(afloat, sumFloat);
  aggregators.put(bfloat, sumFloat);
  FacetsAccumulator fa = new FacetsAccumulator(fsp, reader, taxo) {
    @Override
    public FacetsAggregator getAggregator() {
      return new MultiAssociationsFacetsAggregator(aggregators);
    }
  };
  FacetsCollector fc = FacetsCollector.create(fa);
  
  IndexSearcher searcher = newSearcher(reader);
  searcher.search(q, fc);
  List<FacetResult> res = fc.getFacetResults();
  
  assertEquals("Wrong number of results!", 4, res.size());
  assertEquals("Wrong count for category 'a'!", 200, (int) res.get(0).getFacetResultNode().value);
  assertEquals("Wrong count for category 'b'!", 150, (int) res.get(1).getFacetResultNode().value);
  assertEquals("Wrong count for category 'a'!",50f, (float) res.get(2).getFacetResultNode().value, 0.00001);
  assertEquals("Wrong count for category 'b'!",10f, (float) res.get(3).getFacetResultNode().value, 0.00001);
  
  taxo.close();
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:41,代碼來源:AssociationsFacetRequestTest.java

示例5: wrap

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
/** Wraps the given {@link FacetsAccumulator accumulators}. */
public static FacetsAccumulator wrap(FacetsAccumulator... accumulators) {
  if (accumulators.length == 0) {
    return accumulators[0];
  } else {
    return new MultiFacetsAccumulator(accumulators);
  }
}
 
開發者ID:jimaguere,項目名稱:Maskana-Gestor-de-Conocimiento,代碼行數:9,代碼來源:MultiFacetsAccumulator.java

示例6: requiresDocScores

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
@Override
public boolean requiresDocScores() {
  for (FacetsAccumulator fa : accumulators) {
    if (fa.requiresDocScores()) {
      return true;
    }
  }
  return false;
}
 
開發者ID:jimaguere,項目名稱:Maskana-Gestor-de-Conocimiento,代碼行數:10,代碼來源:MultiFacetsAccumulator.java

示例7: accumulate

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
@Override
public List<FacetResult> accumulate(List<MatchingDocs> matchingDocs) throws IOException {
  List<FacetResult> merged = new ArrayList<FacetResult>();
  for (FacetsAccumulator fa : accumulators) {
    merged.addAll(fa.accumulate(matchingDocs));
  }
  return merged;
}
 
開發者ID:jimaguere,項目名稱:Maskana-Gestor-de-Conocimiento,代碼行數:9,代碼來源:MultiFacetsAccumulator.java

示例8: MultiFacetsAccumulator

import org.apache.lucene.facet.search.FacetsAccumulator; //導入依賴的package包/類
private MultiFacetsAccumulator(FacetsAccumulator... accumulators) {
  super((FacetSearchParams) null);
  this.accumulators = accumulators;
}
 
開發者ID:jimaguere,項目名稱:Maskana-Gestor-de-Conocimiento,代碼行數:5,代碼來源:MultiFacetsAccumulator.java


注:本文中的org.apache.lucene.facet.search.FacetsAccumulator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。