You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Christophe Jolif <cj...@gmail.com> on 2022/01/19 09:37:29 UTC

MemoryIndex and UnifiedHiglighter

Hi all,

Sorry, I'm totally new to Lucene so this might sound obvious to you.
I'm trying to use the UnifiedHiglighter with MemoryIndex. I can't make
it work so far. At first, I did not set the storeOffsets/Payloads
options in the MemoryIndex so I figured that might be the cause of my
issue but even with that, I'm out of luck. Is that meant to work? The
MemoryIndex javadoc mentions the use with a highlighter but is not
very specific.

My code looks like:

Analyzer analyzer = new FrenchAnalyzer();
MemoryIndex index = new MemoryIndex(true, true);
IndexableField titleField = new TextField("content", content, Field.Store.YES);
index.addField(titleField, analyzer)

QueryParser parser = new QueryParser("content", analyzer);
Query query = parser.parse("ma recherche");

IndexSearcher searcher = index.createSearcher();

index.freeze();

TopDocs docs = searcher.search(query, 1);

UnifiedHighlighter uhighlighter = new UnifiedHighlighter(searcher, analyzer);
String[] results = uhighlighter.highlight("content", query, docs);
String result = results[0];

System.out.println("score=" + docs.scoreDocs[0].score);
System.out.println("highlight with unified=" + result);

The result is always "null".

Thanks!
-- 
Christophe

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