本文整理汇总了Java中org.apache.lucene.search.TopScoreDocCollector.create方法的典型用法代码示例。如果您正苦于以下问题:Java TopScoreDocCollector.create方法的具体用法?Java TopScoreDocCollector.create怎么用?Java TopScoreDocCollector.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.TopScoreDocCollector
的用法示例。
在下文中一共展示了TopScoreDocCollector.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
/**
* Given a search field to search,the name of the field to return results in
* and a query string, return search results up to the limit.
*
* @param searchfieldName
* @param returnFieldName
* @param queryStr
* @param limit
* @return search results (with confidences)
* @throws ParseException
* @throws IOException
*/
public HashMap<String[], Float> search(String searchfieldName,
String[] returnFieldName, String queryStr, int limit)
throws ParseException, IOException {
if (queryStr == null || queryStr.length() == 0)
return new HashMap<String[], Float>();
final String clean = QueryParser.escape(queryStr);
final Query q = new QueryParser(Version.LUCENE_40, searchfieldName,
analyser).parse(clean);
final TopScoreDocCollector collector = TopScoreDocCollector.create(
limit, true);
searcher.search(q, collector);
final ScoreDoc[] hits = collector.topDocs().scoreDocs;
final HashMap<String[], Float> results = new HashMap<String[], Float>();
for (int i = 0; i < hits.length; ++i) {
final int docId = hits[i].doc;
final Document d = searcher.doc(docId);
String[] rvalues = new String[returnFieldName.length];
for(int j=0;j<rvalues.length;j++){
rvalues[j]=d.get(returnFieldName[j]);
}
results.put(rvalues, hits[i].score);
}
return results;
}
示例2: search
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
public SearchResult search (String queryString, int hitsPerPage) throws IOException {
SearchResult result = new SearchResult();
result.setQuery(queryString);
TopScoreDocCollector collector;
ScoreDoc[] docs;
Query query;
try { // new Query parser, because it is not thread safe
query = new QueryParser("terms", new StandardAnalyzer()).parse(QueryParser.escape(queryString));
} catch (ParseException e) {
throw new IOException(e);
}
collector = TopScoreDocCollector.create(hitsPerPage, true);
if (hitsSearcher == null) openReader(); // reopen index to see updates.
hitsSearcher.search(query, collector);
docs = collector.topDocs().scoreDocs;
for(ScoreDoc doc: docs) {
int docId = doc.doc;
Document d = hitsSearcher.doc(docId);
Hit hit = new Hit(d.get("result"));
hit.put("score", doc.score);
hit.remove("query"); // remove for privacy reasons
result.addHit(hit);
}
return result;
}
示例3: getHit
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
/**
* Get Hit by Lucene id. Used for tests only
* @param hitId
* @return hit
* @throws IOException
*/
protected Hit getHit(String hitId) throws IOException {
Term term = new Term("id", hitId);
Query query = new TermQuery(term);
TopScoreDocCollector collector = TopScoreDocCollector.create(1, true);
if (hitsSearcher == null) openReader();
hitsSearcher.search(query, collector);
if (collector.getTotalHits() > 0) {
ScoreDoc[] docs = collector.topDocs().scoreDocs;
Document doc = hitsSearcher.doc(docs[0].doc);
Hit hit = new Hit(doc.get("result"));
return hit;
} else {
return null;
}
}
示例4: ReRankCollector
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
public ReRankCollector(int reRankDocs,
int length,
Query reRankQuery,
double reRankWeight,
SolrIndexSearcher.QueryCommand cmd,
IndexSearcher searcher,
Map<BytesRef, Integer> boostedPriority) throws IOException {
super(null);
this.reRankQuery = reRankQuery;
this.reRankDocs = reRankDocs;
this.length = length;
this.boostedPriority = boostedPriority;
Sort sort = cmd.getSort();
if(sort == null) {
this.mainCollector = TopScoreDocCollector.create(Math.max(this.reRankDocs, length),true);
} else {
sort = sort.rewrite(searcher);
this.mainCollector = TopFieldCollector.create(sort, Math.max(this.reRankDocs, length), false, true, true, true);
}
this.searcher = searcher;
this.reRankWeight = reRankWeight;
}
示例5: GroupExpandCollector
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
public GroupExpandCollector(SortedDocValues docValues, FixedBitSet groupBits, IntOpenHashSet collapsedSet, int limit, Sort sort) throws IOException {
int numGroups = collapsedSet.size();
groups = new IntObjectOpenHashMap<>(numGroups * 2);
collectors = new ArrayList<>();
DocIdSetIterator iterator = groupBits.iterator();
int group;
while ((group = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
Collector collector = (sort == null) ? TopScoreDocCollector.create(limit, true) : TopFieldCollector.create(sort, limit, false, false, false, true);
groups.put(group, collector);
collectors.add(collector);
}
this.collapsedSet = collapsedSet;
this.groupBits = groupBits;
this.docValues = docValues;
}
示例6: search
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private List<KObject> search(final Query query,
final int totalNumHitsEstimate,
final IOSearchService.Filter filter,
final ClusterSegment... clusterSegments) {
final TopScoreDocCollector collector = TopScoreDocCollector.create(totalNumHitsEstimate);
final IndexSearcher index = indexManager.getIndexSearcher(clusterSegments);
final List<KObject> result = new ArrayList<KObject>();
try {
index.search(query,
collector);
final ScoreDoc[] hits = collector.topDocs(0).scoreDocs;
for (int i = 0; i < hits.length; i++) {
final KObject kObject = toKObject(index.doc(hits[i].doc));
if (filter.accept(kObject)) {
result.add(kObject);
}
}
} catch (final Exception ex) {
throw new RuntimeException("Error during Query!",
ex);
} finally {
indexManager.release(index);
}
return result;
}
示例7: ReRankCollector
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
public ReRankCollector(int reRankDocs,
int length,
Query reRankQuery,
double reRankWeight,
SolrIndexSearcher.QueryCommand cmd,
IndexSearcher searcher,
Map<BytesRef, Integer> boostedPriority,
boolean scale) throws IOException {
super(null);
this.reRankQuery = reRankQuery;
this.reRankDocs = reRankDocs;
this.length = length;
this.boostedPriority = boostedPriority;
this.scale = scale;
Sort sort = cmd.getSort();
if(sort == null) {
this.mainCollector = TopScoreDocCollector.create(Math.max(this.reRankDocs, length),true);
} else {
sort = sort.rewrite(searcher);
this.mainCollector = TopFieldCollector.create(sort, Math.max(this.reRankDocs, length), false, true, true, true);
}
this.searcher = searcher;
this.reRankWeight = reRankWeight;
}
示例8: compareHits
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private void compareHits(SpanQueryParser p, String s, IndexSearcher searcher, int ... docids) throws Exception{
Query q = p.parse(s);
TopScoreDocCollector results = TopScoreDocCollector.create(1000);
searcher.search(q, results);
ScoreDoc[] scoreDocs = results.topDocs().scoreDocs;
Set<Integer> hits = new HashSet<>();
for (int i = 0; i < scoreDocs.length; i++) {
hits.add(scoreDocs[i].doc);
}
assertEquals(docids.length, hits.size());
for (int i = 0; i < docids.length; i++) {
assertTrue("couldn't find " + Integer.toString(docids[i]) + " among the hits", hits.contains(docids[i]));
}
}
示例9: performSearch
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private FacetsCollector performSearch(FacetIndexingParams iParams, TaxonomyReader tr, IndexReader ir,
IndexSearcher searcher) throws IOException {
// step 1: collect matching documents into a collector
Query q = new MatchAllDocsQuery();
TopScoreDocCollector topDocsCollector = TopScoreDocCollector.create(10, true);
List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
facetRequests.add(new CountFacetRequest(new CategoryPath("Band"), 10));
CountFacetRequest bandDepth = new CountFacetRequest(new CategoryPath("Band"), 10);
bandDepth.setDepth(2);
// makes it easier to check the results in the test.
bandDepth.setResultMode(ResultMode.GLOBAL_FLAT);
facetRequests.add(bandDepth);
facetRequests.add(new CountFacetRequest(new CategoryPath("Author"), 10));
facetRequests.add(new CountFacetRequest(new CategoryPath("Band", "Rock & Pop"), 10));
// Faceted search parameters indicate which facets are we interested in
FacetSearchParams facetSearchParams = new FacetSearchParams(iParams, facetRequests);
// perform documents search and facets accumulation
FacetsCollector facetsCollector = FacetsCollector.create(facetSearchParams, ir, tr);
searcher.search(q, MultiCollector.wrap(topDocsCollector, facetsCollector));
return facetsCollector;
}
示例10: getNeighbours
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
public Map<Movie, Float> getNeighbours(final Movie movie,
final int numberOfHits) throws ParseException, IOException {
final StandardAnalyzer analyzer = new StandardAnalyzer(
Version.LUCENE_46);
final QueryParser parser = new QueryParser(Version.LUCENE_46,
FIELD_SUMMARY, analyzer);
final Query query = parser.parse(movie.toString());
final TopScoreDocCollector collector = TopScoreDocCollector.create(
numberOfHits, true);
final IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(
writer, false));
searcher.search(query, collector);
final Map<Movie, Float> result = new LinkedHashMap<Movie, Float>();
final ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;
for (final ScoreDoc doc : scoreDocs) {
result.put(indexedMovies.get(doc.doc), 1 - doc.score);
}
return result;
}
示例11: returnMusics
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private List<String> returnMusics(Query query) throws IOException {
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(LuceneUtil.INSTANCE.getDirectory());
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(
hitsPerPage, true);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
List<String> musics = new LinkedList<>();
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
musics.add(d.get(COLUMN_NAME));
}
return musics;
}
示例12: returnResume
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private List<String> returnResume(Query query) throws IOException {
int hitsPerPage = 10;
IndexReader reader = DirectoryReader.open(LuceneUtil.INSTANCE.getDirectory());
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.create(
hitsPerPage, true);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
List<String> resumeIDs = new LinkedList<>();
for(int i=0;i<hits.length;++i) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
resumeIDs.add(d.get(COLUMN_NICk_NAME));
}
return resumeIDs;
}
示例13: getFromIndex
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private List<Triple> getFromIndex(int maxNumberOfResults, BooleanQuery bq) throws IOException {
log.debug("\t start asking index...");
TopScoreDocCollector collector = TopScoreDocCollector.create(maxNumberOfResults, true);
// Similarity BM25Similarity = new BM25Similarity();
// isearcher.setSimilarity(BM25Similarity);
isearcher.search(bq, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
List<Triple> triples = new ArrayList<Triple>();
String s, p, o;
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
s = hitDoc.get(FIELD_NAME_SUBJECT);
p = hitDoc.get(FIELD_NAME_PREDICATE);
o = hitDoc.get(FIELD_NAME_OBJECT_URI);
if (o == null) {
o = hitDoc.get(FIELD_NAME_OBJECT_LITERAL);
}
Triple triple = new Triple(s, p, o);
triples.add(triple);
}
log.debug("\t finished asking index...");
return triples;
}
示例14: query
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private static void query(IndexSearcher indexSearcher, Query q) throws IOException, ParseException {
int hitsPerPage = 10;
TopDocsCollector collector = TopScoreDocCollector.create(hitsPerPage, false);
indexSearcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
LOGGER.info("Found " + hits.length + " hits.");
for (int i = 0; i < hits.length; ++i) {
int docId = hits[i].doc;
Document d = indexSearcher.doc(docId);
LOGGER.info((i + 1) + ". " + d.get("title"));
}
}
示例15: getFromIndex
import org.apache.lucene.search.TopScoreDocCollector; //导入方法依赖的package包/类
private List<Triple> getFromIndex(final int maxNumberOfResults, final BooleanQuery bq)
throws IOException {
log.debug("\t start asking index...");
final TopScoreDocCollector collector = TopScoreDocCollector.create(maxNumberOfResults, true);
// Similarity BM25Similarity = new BM25Similarity();
// isearcher.setSimilarity(BM25Similarity);
isearcher.search(bq, collector);
final ScoreDoc[] hits = collector.topDocs().scoreDocs;
final List<Triple> triples = new ArrayList<Triple>();
String s, p, o;
for (int i = 0; i < hits.length; i++) {
final Document hitDoc = isearcher.doc(hits[i].doc);
s = hitDoc.get(FIELD_NAME_SUBJECT);
p = hitDoc.get(FIELD_NAME_PREDICATE);
o = hitDoc.get(FIELD_NAME_OBJECT_URI);
if (o == null) {
o = hitDoc.get(FIELD_NAME_OBJECT_LITERAL);
}
final Triple triple = new Triple(s, p, o);
triples.add(triple);
}
log.debug("\t finished asking index...");
return triples;
}