// highlighting respects fieldnames used in query
Scorer fieldSpecificScorer = null;
if (mode == this.SPAN) {
TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(docMainText));
CachingTokenFilter ctf = new CachingTokenFilter(tokenStream);
fieldSpecificScorer = new SpanScorer(query, FIELD_NAME, ctf);
} else if (mode == this.STANDARD) {
fieldSpecificScorer = new QueryScorer(query, "contents");
}
Highlighter fieldSpecificHighlighter = new Highlighter(new SimpleHTMLFormatter(),
fieldSpecificScorer);
fieldSpecificHighlighter.setTextFragmenter(new NullFragmenter());
String result = fieldSpecificHighlighter.getBestFragment(analyzer, FIELD_NAME, docMainText);
assertEquals("Should match", result, "<B>fred</B> is one of the people");
// highlighting does not respect fieldnames used in query
Scorer fieldInSpecificScorer = null;
if (mode == this.SPAN) {
TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(docMainText));
CachingTokenFilter ctf = new CachingTokenFilter(tokenStream);
fieldInSpecificScorer = new SpanScorer(query, null, ctf);
} else if (mode == this.STANDARD) {
fieldInSpecificScorer = new QueryScorer(query);
}