lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From saisantoshi <saisantosh...@gmail.com>
Subject Re: Extending TopScoreDocCollector to write a custom collector
Date Thu, 24 Jan 2013 07:08:50 GMT
Here is the way I implemented a collector class. Appreciate if you could let
me know of any issues.. 

public class MyCollector extends PositiveScoresOnlyCollector  {

    private IndexReader indexReader;
      
   
    public MyCollector (IndexReader indexReader,PositiveScoresOnlyCollector
topScore) {
        super(topScore); 
        this.indexReader = indexReader;
    }

    @Override
    public void collect(int doc) {
        try {
               //Custom Logic
                    super.collect(doc);
           }
            
        } catch (Exception e) {
         
        }
    }



//Usage:

MyCollector collector;
                TopScoreDocCollector topScore =
TopScoreDocCollector.create(hits, true);
                IndexSearcher searcher = new IndexSearcher(reader);
                try {
                    collector = new MyCollector(indexReader, new
PositiveScoresOnlyCollector(topScore));
                    searcher.search(query, (Filter) null, collector);
                } finally {
                 
                }
    
 TopDocs hitDocs = topScore.topDocs();



--
View this message in context: http://lucene.472066.n3.nabble.com/Extending-TopScoreDocCollector-to-write-a-custom-collector-tp4035861p4035869.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message