Example usage for org.apache.lucene.search PositiveScoresOnlyCollector PositiveScoresOnlyCollector

List of usage examples for org.apache.lucene.search PositiveScoresOnlyCollector PositiveScoresOnlyCollector

Introduction

In this page you can find the example usage for org.apache.lucene.search PositiveScoresOnlyCollector PositiveScoresOnlyCollector.

Prototype

public PositiveScoresOnlyCollector(Collector in) 

Source Link

Usage

From source file:com.tekstosense.stemmer.index.Indexer.java

License:Open Source License

/**
 * Searcher./*from  w w w .ja va2s  . c o  m*/
 *
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws QueryNodeException
 *             the query node exception
 * @throws ParseException
 *             the parse exception
 */
private static void searcher() throws IOException, QueryNodeException, ParseException {
    Path indexDirectoryPath = new File(INDEX_PATH).toPath();
    FSDirectory indexDirectory = new SimpleFSDirectory(indexDirectoryPath);
    DirectoryReader ireader = DirectoryReader.open(indexDirectory);
    IndexSearcher isearcher = new IndexSearcher(ireader);
    QueryParser parser = new QueryParser("title", new StandardAnalyzer());
    Query query = parser.parse("\"Lucene in Action\"");

    TopScoreDocCollector collector = TopScoreDocCollector.create(10);
    isearcher.search(query, new PositiveScoresOnlyCollector(collector));
    TopDocs topDocs = collector.topDocs();
    Set<String> fields = new HashSet<String>();
    fields.add("title");
    fields.add("isbn");
    for (ScoreDoc result : topDocs.scoreDocs) {
        Document doc = isearcher.doc(result.doc, fields);

        if (LOGGER.isInfoEnabled()) {

            LOGGER.info("--- Title :  " + doc.getField("title").stringValue() + " ---");
            LOGGER.info("--- ISBN : " + doc.getField("isbn").stringValue() + " ---");
            LOGGER.info(isearcher.explain(query, result.doc));
        }

    }

}