本文整理汇总了Java中org.apache.lucene.search.grouping.SecondPassGroupingCollector.getTopGroups方法的典型用法代码示例。如果您正苦于以下问题:Java SecondPassGroupingCollector.getTopGroups方法的具体用法?Java SecondPassGroupingCollector.getTopGroups怎么用?Java SecondPassGroupingCollector.getTopGroups使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.grouping.SecondPassGroupingCollector
的用法示例。
在下文中一共展示了SecondPassGroupingCollector.getTopGroups方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.apache.lucene.search.grouping.SecondPassGroupingCollector; //导入方法依赖的package包/类
public Map<DocumentType, List<SearchResult>> search(String searchString) throws ParseException {
Map<DocumentType, List<SearchResult>> resultMap = new TreeMap<DocumentType, List<SearchResult>>();
try {
Query query = parser.parse(searchString);
final SecondPassGroupingCollector collector = new SecondPassGroupingCollector("documentType", searchGroups,
Sort.RELEVANCE, null, 5, true, false, true);
searcher.search(query, collector);
final TopGroups groups = collector.getTopGroups(0);
for (GroupDocs groupDocs : groups.groups) {
DocumentType docType = DocumentType.valueOf(groupDocs.groupValue);
List<SearchResult> results = new ArrayList<SearchResult>();
for (ScoreDoc scoreDoc : groupDocs.scoreDocs) {
Document doc = searcher.doc(scoreDoc.doc);
SearchResult result = new SearchResult(
docType,
doc.get("name"),
doc.get("url"),
doc.get("className"),
doc.get("package"),
doc.get("ensemblePath"),
doc.get("shortDescription")
);
results.add(result);
}
resultMap.put(docType, results);
}
} catch (IOException e) {
e.printStackTrace();
}
return resultMap;
}