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


Java TopScoreDocCollector类代码示例

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


TopScoreDocCollector类属于org.apache.lucene.search包,在下文中一共展示了TopScoreDocCollector类的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;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:38,代码来源:QuickSearcher.java

示例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;
}
 
开发者ID:searsia,项目名称:searsiaserver,代码行数:26,代码来源:SearchResultIndex.java

示例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;
	}
}
 
开发者ID:searsia,项目名称:searsiaserver,代码行数:22,代码来源:SearchResultIndex.java

示例4: getVector

import org.apache.lucene.search.TopScoreDocCollector; //导入依赖的package包/类
public Object2DoubleMap<String> getVector(Language lang, String value) {
    Object2DoubleMap<String> uriWeightMap = new Object2DoubleOpenHashMap<>();
    
    try {
        Search luceneSearch = search();
        final String field = getContentFieldName(lang);
        
        TopScoreDocCollector docsCollector = luceneSearch.search(value, field);
        
        ScoreDoc[] scoreDocs = docsCollector.topDocs().scoreDocs;
        
        double score = 0.0;
        for(int i=0;i<scoreDocs.length;++i) {
            int docID = scoreDocs[i].doc;
            score = scoreDocs[i].score;
            Document document = luceneSearch.getDocumentWithDocID(docID);
            String uri = document.get(fieldNameURI);
            uriWeightMap.put(uri, score);
        }
        return uriWeightMap;
    } catch(IOException x) {
        throw new RuntimeException(x);
    }
}
 
开发者ID:jmccrae,项目名称:naisc,代码行数:25,代码来源:Corpus.java

示例5: 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;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:ReRankQParserPlugin.java

示例6: 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;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ExpandComponent.java

示例7: 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;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:27,代码来源:LuceneSearchIndex.java

示例8: 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;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:25,代码来源:AlfrescoReRankQParserPlugin.java

示例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;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:TestMultipleCategoryLists.java

示例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;
}
 
开发者ID:asenovm,项目名称:FuzzyClassifier,代码行数:22,代码来源:MovieIndex.java

示例11: 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]));
  }
}
 
开发者ID:tballison,项目名称:lucene-addons,代码行数:17,代码来源:TestOverallSpanQueryParser.java

示例12: 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;
}
 
开发者ID:otaviojava,项目名称:Easy-Cassandra-samples,代码行数:19,代码来源:MusicSearch.java

示例13: 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;
}
 
开发者ID:otaviojava,项目名称:Easy-Cassandra-samples,代码行数:19,代码来源:ResumeSearch.java

示例14: searchUri

import org.apache.lucene.search.TopScoreDocCollector; //导入依赖的package包/类
private String searchUri(String title, Language language) {
	BooleanClause.Occur[] flags = {BooleanClause.Occur.MUST,
			BooleanClause.Occur.MUST};	
	String uri = null;
	String[] queryStrings = new String[2];
	String[] fields = new String[2];
	queryStrings[0] = title;
	queryStrings[1] = language.getIso639_1();
	fields[0] = TitleURILucDocCreator.Fields.Title.toString();
	fields[1] = TitleURILucDocCreator.Fields.LanguageISOCode.toString();		
	TopScoreDocCollector docCollector = searcher.multiFieldTermSearch(queryStrings, fields, flags, 10);
	ScoreDoc[] scoreDocs = docCollector.topDocs().scoreDocs;
	if(scoreDocs.length>0) {
		ScoreDoc scoreDoc = scoreDocs[0];
		Document document = searcher.getDocumentWithDocID(scoreDoc.doc);
		uri = document.get(TitleURILucDocCreator.Fields.URI_EN.toString());
	}
	return uri;
}
 
开发者ID:kasooja,项目名称:cl-esa,代码行数:20,代码来源:ArticlesOTDFProcessor.java

示例15: makeVector

import org.apache.lucene.search.TopScoreDocCollector; //导入依赖的package包/类
public void makeVector() {
	TIntDoubleHashMap vecMapT = new TIntDoubleHashMap();	
	String fieldName = pair.getSecond().getIso639_1() + "TopicContent";
	TopScoreDocCollector docsCollector = searcher.search(pair.getFirst(), lucHits, fieldName, AnalyzerFactory.getAnalyzer(pair.getSecond()));			
	if(docsCollector == null) {
		vectorMapT.put(threadName, null); 
		return;				
	}	
	ScoreDoc[] scoreDocs = docsCollector.topDocs().scoreDocs;
	double score = 0.0;
	for(int i=0;i<scoreDocs.length;++i) {
		int docID = scoreDocs[i].doc;
		score = scoreDocs[i].score;
		vecMapT.put(docID, score);
	}		
	vectorMapT.put(threadName, vecMapT);
}
 
开发者ID:kasooja,项目名称:cl-esa,代码行数:18,代码来源:CLESA.java


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