package org.frtu.simple.lucene;

import java.io.IOException;

import org.apache.lucene.document.Document;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopScoreDocCollector;

public class SearchHandler {
	private LuceneHandlerFactory luceneHandlerFactory;
	private IndexSearcher searcher;

	public SearchHandler(LuceneHandlerFactory luceneHandlerFactory, IndexSearcher searcher) {
		super();
		this.luceneHandlerFactory = luceneHandlerFactory;
		this.searcher = searcher;
	}

	public Document getDocById(int docId) throws IOException {
		Document document = searcher.doc(docId);
		return document;
	}

	public Collector search(String fieldName, String querystr, Collector collector) throws ParseException, IOException {
		Query query = luceneHandlerFactory.buildQuery(fieldName, querystr);
		searcher.search(query, collector);
		return collector;
	}
	
	public ScoreDoc[] searchDocByTopScore(String fieldName, String querystr, int hitsPerPage) throws ParseException, IOException {
		TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
		search(fieldName, querystr, collector);
		TopDocs topDocs = collector.topDocs();
		ScoreDoc[] hits = topDocs.scoreDocs;
		return hits;
	}

}

@@ -99,16 +99,60 @@
 cument;%0A
+import org.apache.lucene.index.IndexReader;%0A
 import o
@@ -768,24 +768,182 @@
 archer;%0A%09%7D%0A%0A
+%09public int getMaxDoc() throws IOException %7B%0A%09%09IndexReader indexReader = searcher.getIndexReader();%0A%09%09int maxDoc = indexReader.maxDoc();%0A%09%09return maxDoc;%0A%09%7D%0A%0A
 %09public Docu

Add lucene document listing