improve Highlighter javadocs

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@805923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2009-08-19 18:43:43 +00:00
parent 99b3406bb5
commit 66c2217a55
6 changed files with 51 additions and 38 deletions

View File

@ -17,7 +17,7 @@ package org.apache.lucene.search.highlight;
/**
* Encodes original text. The Encoder works with the Formatter to generate the output.
* Encodes original text. The Encoder works with the {@link Formatter} to generate output.
*
*/
public interface Encoder

View File

@ -28,10 +28,10 @@ public interface Fragmenter {
/**
* Initializes the Fragmenter. You can grab references to the Attributes you are
* interested in from tokenStream and then access the values in isNewFragment.
* interested in from tokenStream and then access the values in {@link #isNewFragment()}.
*
* @param originalText
* @param tokenStream
* @param originalText the original source text
* @param tokenStream the {@link TokenStream} to be fragmented
*/
public void start(String originalText, TokenStream tokenStream);

View File

@ -10,13 +10,15 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.memory.MemoryIndex;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.util.StringHelper;
/**
* {@link Scorer} implementation which scores text fragments by the number of
* unique query terms found. This class converts appropriate Querys to
* SpanQuerys and attempts to score only those terms that participated in
* unique query terms found. This class converts appropriate {@link Query}s to
* {@link SpanQuery}s and attempts to score only those terms that participated in
* generating the 'hit' on the document.
*/
public class QueryScorer implements Scorer {
@ -36,8 +38,6 @@ public class QueryScorer implements Scorer {
/**
* @param query Query to use for highlighting
*
* @throws IOException
*/
public QueryScorer(Query query) {
init(query, null, null, true);
@ -46,7 +46,6 @@ public class QueryScorer implements Scorer {
/**
* @param query Query to use for highlighting
* @param field Field to highlight - pass null to ignore fields
* @throws IOException
*/
public QueryScorer(Query query, String field) {
init(query, field, null, true);
@ -55,19 +54,20 @@ public class QueryScorer implements Scorer {
/**
* @param query Query to use for highlighting
* @param field Field to highlight - pass null to ignore fields
*
* @param reader
* @throws IOException
* @param reader {@link IndexReader} to use for quasi tf/idf scoring
*/
public QueryScorer(Query query, IndexReader reader, String field) {
init(query, field, reader, true);
}
/**
* As above, but with ability to pass in an <tt>IndexReader</tt>
* @param query to use for highlighting
* @param reader {@link IndexReader} to use for quasi tf/idf scoring
* @param field to highlight - pass null to ignore fields
* @param defaultField
*/
public QueryScorer(Query query, IndexReader reader, String field, String defaultField)
throws IOException {
public QueryScorer(Query query, IndexReader reader, String field, String defaultField) {
this.defaultField = StringHelper.intern(defaultField);
init(query, field, reader, true);
}
@ -81,7 +81,7 @@ public class QueryScorer implements Scorer {
}
/**
* @param weightedTerms
* @param weightedTerms an array of pre-created {@link WeightedSpanTerm}s
*/
public QueryScorer(WeightedSpanTerm[] weightedTerms) {
this.fieldWeightedSpanTerms = new HashMap(weightedTerms.length);
@ -112,7 +112,7 @@ public class QueryScorer implements Scorer {
/**
*
* @return The highest weighted term (useful for passing to
* GradientFormatter to set top end of coloring scale.
* GradientFormatter to set top end of coloring scale).
*/
public float getMaxTermWeight() {
return maxTermWeight;
@ -151,6 +151,9 @@ public class QueryScorer implements Scorer {
return score;
}
/* (non-Javadoc)
* @see org.apache.lucene.search.highlight.Scorer#init(org.apache.lucene.analysis.TokenStream)
*/
public TokenStream init(TokenStream tokenStream) throws IOException {
position = -1;
termAtt = (TermAttribute) tokenStream.getAttribute(TermAttribute.class);
@ -165,10 +168,10 @@ public class QueryScorer implements Scorer {
}
/**
* Retrieve the WeightedSpanTerm for the specified token. Useful for passing
* Span information to a Fragmenter.
* Retrieve the {@link WeightedSpanTerm} for the specified token. Useful for passing
* Span information to a {@link Fragmenter}.
*
* @param token
* @param token to get {@link WeightedSpanTerm} for
* @return WeightedSpanTerm for token
*/
public WeightedSpanTerm getWeightedSpanTerm(String token) {
@ -180,7 +183,6 @@ public class QueryScorer implements Scorer {
* @param field
* @param tokenStream
* @param reader
* @throws IOException
*/
private void init(Query query, String field, IndexReader reader, boolean expandMultiTermQuery) {
this.reader = reader;
@ -218,10 +220,19 @@ public class QueryScorer implements Scorer {
totalScore = 0;
}
/**
* @return true if multi-term queries should be expanded
*/
public boolean isExpandMultiTermQuery() {
return expandMultiTermQuery;
}
/**
* Controls whether or not multi-term queries are expanded
* against a {@link MemoryIndex} {@link IndexReader}.
*
* @param expandMultiTermQuery true if multi-term queries should be expanded
*/
public void setExpandMultiTermQuery(boolean expandMultiTermQuery) {
this.expandMultiTermQuery = expandMultiTermQuery;
}

View File

@ -22,44 +22,44 @@ import java.io.IOException;
import org.apache.lucene.analysis.TokenStream;
/**
* Adds to the score for a fragment based on its tokens
* A Scorer is responsible for scoring a stream of tokens. These token scores
* can then be used to compute {@link TextFragment} scores.
*/
public interface Scorer {
/**
* Called to init the Scorer with a TokenStream. You can grab references to
* the attributes you are interested in here and access them from
* getTokenScore().
* Called to init the Scorer with a {@link TokenStream}. You can grab references to
* the attributes you are interested in here and access them from {@link #getTokenScore()}.
*
* @param tokenStream
* @return either a TokenStream that the Highlighter should continue using (eg
* @param tokenStream the {@link TokenStream} that will be scored.
* @return either a {@link TokenStream} that the Highlighter should continue using (eg
* if you read the tokenSream in this method) or null to continue
* using the same TokenStream that was passed in.
* using the same {@link TokenStream} that was passed in.
* @throws IOException
*/
public TokenStream init(TokenStream tokenStream) throws IOException;
/**
* called when a new fragment is started for consideration
* Called when a new fragment is started for consideration.
*
* @param newFragment
* @param newFragment the fragment that will be scored next
*/
public void startFragment(TextFragment newFragment);
/**
* Called for each token in the current fragment. The Highlighter will
* increment the TokenStream passed to init on every call.
* Called for each token in the current fragment. The {@link Highlighter} will
* increment the {@link TokenStream} passed to init on every call.
*
* @return a score which is passed to the Highlighter class to influence the
* @return a score which is passed to the {@link Highlighter} class to influence the
* mark-up of the text (this return value is NOT used to score the
* fragment)
*/
public float getTokenScore();
/**
* Called when the highlighter has no more tokens for the current fragment -
* the scorer returns the weighting it has derived for the most recent
* fragment, typically based on the tokens passed to getTokenScore().
* Called when the {@link Highlighter} has no more tokens for the current fragment -
* the Scorer returns the weighting it has derived for the most recent
* fragment, typically based on the results of {@link #getTokenScore()}.
*
*/
public float getFragmentScore();

View File

@ -23,11 +23,12 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.search.spans.Spans;
/**
* {@link Fragmenter} implementation which breaks text up into same-size
* fragments but does not split up Spans. This is a simple sample class.
* fragments but does not split up {@link Spans}. This is a simple sample class.
*/
public class SimpleSpanFragmenter implements Fragmenter {
private static final int DEFAULT_FRAGMENT_SIZE = 100;

View File

@ -53,7 +53,8 @@ import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.util.StringHelper;
/**
* Class used to extract {@link WeightedSpanTerm}s from a {@link Query} based on whether Terms from the query are contained in a supplied TokenStream.
* Class used to extract {@link WeightedSpanTerm}s from a {@link Query} based on whether
* {@link Term}s from the {@link Query} are contained in a supplied {@link TokenStream}.
*/
public class WeightedSpanTermExtractor {