lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Natalia Connolly <>
Subject PostingsHighlighter in Lucene SearchFiles always returns nulls
Date Wed, 09 Jul 2014 16:58:51 GMT

   Can anyone help me with an example of using PostingsHighlighter in
Lucene 4.7.  I am trying to modify (which can be found in
the demo directory) so that it would display not only which documents
contains the terms I was searching for, but also the entire sentences where
it found those terms.  For example, if I am looking for "brown dog" and
document 1 contains a sentence "I have a brown dog", I'd like to see
something like this:

doc = 1, score = ####, matching sentence = "I have a brown dog"

   so I have:

IndexReader reader =
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_47,emptyset);

AnalyzingQueryParser parser = new AnalyzingQueryParser(Version.LUCENE_47,
field, analyzer);
Query query = parser.parse("brown dog");
PostingsHighlighter highlighter = new PostingsHighlighter();

TopDocs results =, 5 * hitsPerPage);
String highlights[] = highlighter.highlight("contents", query, searcher,
for (int k = 0; k< highlights.length; k++) {
    System.out.println("highlights[ " + k + "] is " + highlights[k]);

  I get the documents and the scores but the highlights[#] elements are
always null.    What am I doing wrong?



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message