lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sirish Vadala <>
Subject Problem using TopFieldCollector
Date Fri, 11 Jun 2010 18:31:56 GMT

Currently I am on Lucene 2.2, migrating to 2.9 before eventually plan to move
to 3.1.

In Lucene 2.2, I have a custom hit collector that does both filtering and
sorting my search results.

Let me put the functionality achieved. When a user includes advance search
criteria with text search, I execute a query to fetch the advance search
results. Now, I have this collection of advance search result ids, that need
to match with the text search result ids.

Successfully implemented in 2.2 using the below collector:


public class ResultHitCollector extends TopFieldDocCollector{

	private IndexSearcher searcher;
	private AnalysisTextSearchBean textSearchBean;

	public ResultHitCollector(IndexSearcher searcher, int numHits,
			AnalysisTextSearchBean textSearchBean, Sort sort)
			throws IOException {
		super(searcher.getIndexReader(), sort, numHits);
		this.searcher = searcher;
		this.textSearchBean = textSearchBean;

	public void collect(int doc, float score) {
		try {
			HashMap<String, String> advanceSearchIds = textSearchBean
			if (advanceSearchBills == null) {
				super.collect(doc, score);
			} else {
				Document document = searcher.doc(doc);
				if (document != null) {
					String id = document.get(IFIELD_ID);
					if (advanceSearchIds.containsKey(id)) {
						super.collect(doc, score);
		} catch (CorruptIndexException e) {
			System.err.println("ERROR: " + e.getMessage());
		} catch (IOException e) {
			System.err.println("ERROR: " + e.getMessage());

Calling the hit collection as below:

Sort sort = new Sort(sortOrder);
ResultHitCollector collector = new ResultHitCollector(indexSearcher, 100000,
analysisTextSearchBean, sort);, collector);
ScoreDoc[] hitScore = collector.topDocs().scoreDocs;
Utility.Log(Level.INFO, this, "Hits found: "+ hitScore.length);


Since in Lucene 2.9, TopFieldDocCollector is deprecated, the documentation
suggests me to use TopFieldCollector instead. I am not really sure how to
get this to work using this, as TopFieldCollector doesn't have any public
constructors to extend this object. Any hints on how to implement this would
be highly appreciated.

However, using Collector in 2.9, this can be achieved without sort the
functionality. I also need to sort the results after filtering the search.

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message