diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Encoder.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Encoder.java index f72c7585f68..0ac399a5574 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Encoder.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Encoder.java @@ -25,7 +25,6 @@ public interface Encoder { /** * @param originalText The section of text being output - * @return */ String encodeText(String originalText); } \ No newline at end of file diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Formatter.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Formatter.java index 311d1603f85..8eb874109e9 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Formatter.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Formatter.java @@ -27,7 +27,6 @@ public interface Formatter * @param originalText The section of text being considered for markup * @param tokenGroup contains one or several overlapping Tokens along with * their scores and positions. - * @return */ String highlightTerm(String originalText, TokenGroup tokenGroup); } diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Fragmenter.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Fragmenter.java index ffd07d2edc6..0dd268f8d5a 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Fragmenter.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Fragmenter.java @@ -34,7 +34,6 @@ public interface Fragmenter /** * Test to see if this token from the stream should be held in a new TextFragment * @param nextToken - * @return */ public boolean isNewFragment(Token nextToken); } diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java index 1d6a1feaefe..fbb13563c11 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java @@ -127,7 +127,6 @@ public class Highlighter * @param text * @param maxNumFragments * @param mergeContiguousFragments - * @return * @throws IOException */ public final TextFragment[] getBestTextFragments( @@ -411,7 +410,6 @@ public class Highlighter } /** - * @return */ public Fragmenter getTextFragmenter() { diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenGroup.java b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenGroup.java index 2acaa3f5a8a..bb48ced6a21 100644 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenGroup.java +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/TokenGroup.java @@ -105,7 +105,7 @@ public class TokenGroup } /** - * @return + * @return all tokens' scores summed up */ public float getTotalScore() { diff --git a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/package.html b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/package.html index 6f67db1ee02..8d4e5b5d455 100755 --- a/contrib/highlighter/src/java/org/apache/lucene/search/highlight/package.html +++ b/contrib/highlighter/src/java/org/apache/lucene/search/highlight/package.html @@ -1,51 +1,57 @@
+ The highlight package contains classes to provide "keyword in context" features -typically used to highlight search terms in the text of results pages.- IndexSearcher searcher = new IndexSearcher(ramDir); - Query query = QueryParser.parse("Kenne*", FIELD_NAME, analyzer); - query=query.rewrite(reader); //required to expand search terms - Hits hits = searcher.search(query); + IndexSearcher searcher = new IndexSearcher(ramDir); + Query query = QueryParser.parse("Kenne*", FIELD_NAME, analyzer); + query = query.rewrite(reader); //required to expand search terms + Hits hits = searcher.search(query); - Highlighter highlighter =new Highlighter(this,new QueryScorer(query)); - for (int i = 0; i < hits.length(); i++) - { - String text = hits.doc(i).get(FIELD_NAME); - TokenStream tokenStream=analyzer.tokenStream(FIELD_NAME,new StringReader(text)); - // Get 3 best fragments and seperate with a "..." - String result = highlighter.getBestFragments(tokenStream,text,3,"..."); - System.out.println(result); - } + Highlighter highlighter = new Highlighter(this, new QueryScorer(query)); + for (int i = 0; i < hits.length(); i++) + { + String text = hits.doc(i).get(FIELD_NAME); + TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text)); + // Get 3 best fragments and seperate with a "..." + String result = highlighter.getBestFragments(tokenStream, text, 3, "..."); + System.out.println(result); + }+
The highlighter takes a TokenStream as input. Until now these streams have typically been produced using an Analyzer but the new class TokenSources provides helper methods for obtaining TokenStreams from the new TermVector position support (see latest CVS version).
+The new class GradientFormatter can use a scale of colors to highlight terms according to their score. A subtle use of color can help emphasise the reasons for matching (useful when doing "MoreLikeThis" queries and -you want to see what the basis of the similarities are)
+you want to see what the basis of the similarities are). +The QueryScorer class has a new constructor which can use an IndexReader to derive the IDF (inverse document frequency) for each term in order to influcence the score. This is useful for helping to extracting the most significant sections of a document and in supplying scores used by the new GradientFormatter to color significant words more strongly.