You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2012/09/21 19:22:27 UTC
svn commit: r1388574 [16/45] - in /lucene/dev/branches/LUCENE-2878: ./
dev-tools/ dev-tools/eclipse/ dev-tools/eclipse/dot.settings/
dev-tools/idea/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/
dev-tools/idea/lucene/ dev-tools/idea/lucene/anal...
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyQuery.java Fri Sep 21 17:21:34 2012
@@ -28,12 +28,21 @@ import org.apache.lucene.util.ToStringUt
import org.apache.lucene.util.automaton.LevenshteinAutomata;
/** Implements the fuzzy search query. The similarity measurement
- * is based on the Damerau-Levenshtein (optimal string alignment) algorithm.
+ * is based on the Damerau-Levenshtein (optimal string alignment) algorithm,
+ * though you can explicitly choose classic Levenshtein by passing <code>false</code>
+ * to the <code>transpositions</code> parameter.
*
* <p>This query uses {@link MultiTermQuery.TopTermsScoringBooleanQueryRewrite}
* as default. So terms will be collected and scored according to their
* edit distance. Only the top terms are used for building the {@link BooleanQuery}.
* It is not recommended to change the rewrite mode for fuzzy queries.
+ *
+ * <p>At most, this query will match terms up to
+ * {@value org.apache.lucene.util.automaton.LevenshteinAutomata#MAXIMUM_SUPPORTED_DISTANCE} edits.
+ * Higher distances (especially with transpositions enabled), are generally not useful and
+ * will match a significant amount of the term dictionary. If you really want this, consider
+ * using an n-gram indexing technique (such as the SpellChecker in the
+ * <a href="{@docRoot}/../suggest/overview-summary.html">suggest module</a>) instead.
*/
public class FuzzyQuery extends MultiTermQuery {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/FuzzyTermsEnum.java Fri Sep 21 17:21:34 2012
@@ -398,12 +398,17 @@ public class FuzzyTermsEnum extends Term
return scale_factor;
}
- /** @lucene.internal */
+ /**
+ * reuses compiled automata across different segments,
+ * because they are independent of the index
+ * @lucene.internal */
public static interface LevenshteinAutomataAttribute extends Attribute {
public List<CompiledAutomaton> automata();
}
- /** @lucene.internal */
+ /**
+ * Stores compiled automata as a list (indexed by edit distance)
+ * @lucene.internal */
public static final class LevenshteinAutomataAttributeImpl extends AttributeImpl implements LevenshteinAutomataAttribute {
private final List<CompiledAutomaton> automata = new ArrayList<CompiledAutomaton>();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/HitQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/HitQueue.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/HitQueue.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/HitQueue.java Fri Sep 21 17:21:34 2012
@@ -30,8 +30,8 @@ final class HitQueue extends PriorityQue
* <b>NOTE:</b> in case <code>prePopulate</code> is true, you should pop
* elements from the queue using the following code example:
*
- * <pre>
- * PriorityQueue pq = new HitQueue(10, true); // pre-populate.
+ * <pre class="prettyprint">
+ * PriorityQueue<ScoreDoc> pq = new HitQueue(10, true); // pre-populate.
* ScoreDoc top = pq.top();
*
* // Add/Update one element.
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java Fri Sep 21 17:21:34 2012
@@ -39,6 +39,7 @@ import org.apache.lucene.index.IndexRead
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.ReaderUtil;
+import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.index.StoredFieldVisitor;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
@@ -83,7 +84,7 @@ public class IndexSearcher {
// in the next release
protected final IndexReaderContext readerContext;
protected final List<AtomicReaderContext> leafContexts;
- // used with executor - each slice holds a set of leafs executed within one thread
+ /** used with executor - each slice holds a set of leafs executed within one thread */
protected final LeafSlice[] leafSlices;
// These are only used for multi-threaded search
@@ -123,7 +124,7 @@ public class IndexSearcher {
*
* @lucene.experimental */
public IndexSearcher(IndexReader r, ExecutorService executor) {
- this(r.getTopReaderContext(), executor);
+ this(r.getContext(), executor);
}
/**
@@ -139,7 +140,7 @@ public class IndexSearcher {
* href="https://issues.apache.org/jira/browse/LUCENE-2239">LUCENE-2239</a>).
*
* @see IndexReaderContext
- * @see IndexReader#getTopReaderContext()
+ * @see IndexReader#getContext()
* @lucene.experimental
*/
public IndexSearcher(IndexReaderContext context, ExecutorService executor) {
@@ -155,7 +156,7 @@ public class IndexSearcher {
* Creates a searcher searching the provided top-level {@link IndexReaderContext}.
*
* @see IndexReaderContext
- * @see IndexReader#getTopReaderContext()
+ * @see IndexReader#getContext()
* @lucene.experimental
*/
public IndexSearcher(IndexReaderContext context) {
@@ -182,7 +183,7 @@ public class IndexSearcher {
}
/** Sugar for <code>.getIndexReader().document(docID)</code> */
- public Document doc(int docID) throws IOException {
+ public StoredDocument doc(int docID) throws IOException {
return reader.document(docID);
}
@@ -192,11 +193,11 @@ public class IndexSearcher {
}
/** Sugar for <code>.getIndexReader().document(docID, fieldsToLoad)</code> */
- public final Document document(int docID, Set<String> fieldsToLoad) throws IOException {
+ public final StoredDocument document(int docID, Set<String> fieldsToLoad) throws IOException {
return reader.document(docID, fieldsToLoad);
}
- /** Expert: Set the Similarity implementation used by this Searcher.
+ /** Expert: Set the Similarity implementation used by this IndexSearcher.
*
*/
public void setSimilarity(Similarity similarity) {
@@ -640,7 +641,7 @@ public class IndexSearcher {
/**
* Returns this searchers the top-level {@link IndexReaderContext}.
- * @see IndexReader#getTopReaderContext()
+ * @see IndexReader#getContext()
*/
/* sugar for #getReader().getTopReaderContext() */
public IndexReaderContext getTopReaderContext() {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Fri Sep 21 17:21:34 2012
@@ -100,7 +100,7 @@ public class MultiPhraseQuery extends Qu
* Do not modify the List or its contents.
*/
public List<Term[]> getTermArrays() {
- return Collections.unmodifiableList(termArrays);
+ return Collections.unmodifiableList(termArrays);
}
/**
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManager.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManager.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManager.java Fri Sep 21 17:21:34 2012
@@ -27,6 +27,7 @@ import java.util.concurrent.locks.Reentr
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexDocument;
import org.apache.lucene.index.SegmentInfoPerCommit;
import org.apache.lucene.index.IndexReader; // javadocs
import org.apache.lucene.index.IndexWriter;
@@ -154,25 +155,25 @@ public class NRTManager extends Referenc
this.writer = writer;
}
- public long updateDocument(Term t, Iterable<? extends IndexableField> d, Analyzer a) throws IOException {
+ public long updateDocument(Term t, IndexDocument d, Analyzer a) throws IOException {
writer.updateDocument(t, d, a);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long updateDocument(Term t, Iterable<? extends IndexableField> d) throws IOException {
+ public long updateDocument(Term t, IndexDocument d) throws IOException {
writer.updateDocument(t, d);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long updateDocuments(Term t, Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer a) throws IOException {
+ public long updateDocuments(Term t, Iterable<? extends IndexDocument> docs, Analyzer a) throws IOException {
writer.updateDocuments(t, docs, a);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long updateDocuments(Term t, Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException {
+ public long updateDocuments(Term t, Iterable<? extends IndexDocument> docs) throws IOException {
writer.updateDocuments(t, docs);
// Return gen as of when indexing finished:
return indexingGen.get();
@@ -208,25 +209,25 @@ public class NRTManager extends Referenc
return indexingGen.get();
}
- public long addDocument(Iterable<? extends IndexableField> d, Analyzer a) throws IOException {
+ public long addDocument(IndexDocument d, Analyzer a) throws IOException {
writer.addDocument(d, a);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer a) throws IOException {
+ public long addDocuments(Iterable<? extends IndexDocument> docs, Analyzer a) throws IOException {
writer.addDocuments(docs, a);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long addDocument(Iterable<? extends IndexableField> d) throws IOException {
+ public long addDocument(IndexDocument d) throws IOException {
writer.addDocument(d);
// Return gen as of when indexing finished:
return indexingGen.get();
}
- public long addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException {
+ public long addDocuments(Iterable<? extends IndexDocument> docs) throws IOException {
writer.addDocuments(docs);
// Return gen as of when indexing finished:
return indexingGen.get();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManagerReopenThread.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManagerReopenThread.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManagerReopenThread.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NRTManagerReopenThread.java Fri Sep 21 17:21:34 2012
@@ -29,7 +29,7 @@ import org.apache.lucene.util.ThreadInte
*
* <p> Typical usage looks like this:
*
- * <pre>
+ * <pre class="prettyprint">
* ... open your own writer ...
*
* NRTManager manager = new NRTManager(writer);
@@ -45,7 +45,7 @@ import org.apache.lucene.util.ThreadInte
*
* Then, for each incoming query, do this:
*
- * <pre>
+ * <pre class="prettyprint">
* // For each incoming query:
* IndexSearcher searcher = manager.get();
* try {
@@ -58,7 +58,7 @@ import org.apache.lucene.util.ThreadInte
* You should make changes using the <code>NRTManager</code>; if you later need to obtain
* a searcher reflecting those changes:
*
- * <pre>
+ * <pre class="prettyprint">
* // ... or updateDocument, deleteDocuments, etc:
* long gen = manager.addDocument(...);
*
@@ -73,7 +73,7 @@ import org.apache.lucene.util.ThreadInte
*
*
* When you are done be sure to close both the manager and the reopen thrad:
- * <pre>
+ * <pre class="prettyprint">
* reopenThread.close();
* manager.close();
* </pre>
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeFilter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeFilter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeFilter.java Fri Sep 21 17:21:34 2012
@@ -34,7 +34,7 @@ import org.apache.lucene.util.NumericUti
* <p>You create a new NumericRangeFilter with the static
* factory methods, eg:
*
- * <pre>
+ * <pre class="prettyprint">
* Filter f = NumericRangeFilter.newFloatRange("weight", 0.03f, 0.10f, true, true);
* </pre>
*
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/NumericRangeQuery.java Fri Sep 21 17:21:34 2012
@@ -49,7 +49,7 @@ import org.apache.lucene.index.Term; //
* <p>You create a new NumericRangeQuery with the static
* factory methods, eg:
*
- * <pre>
+ * <pre class="prettyprint">
* Query q = NumericRangeQuery.newFloatRange("weight", 0.03f, 0.10f, true, true);
* </pre>
*
@@ -289,7 +289,7 @@ public final class NumericRangeQuery<T e
@Override @SuppressWarnings("unchecked")
protected TermsEnum getTermsEnum(final Terms terms, AttributeSource atts) throws IOException {
- // very strange: java.lang.Number itsself is not Comparable, but all subclasses used here are
+ // very strange: java.lang.Number itself is not Comparable, but all subclasses used here are
if (min != null && max != null && ((Comparable<T>) min).compareTo(max) > 0) {
return TermsEnum.EMPTY;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhrasePositions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhrasePositions.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhrasePositions.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhrasePositions.java Fri Sep 21 17:21:34 2012
@@ -26,13 +26,13 @@ import java.io.IOException;
* Position of a term in a document that takes into account the term offset within the phrase.
*/
final class PhrasePositions {
- int doc; // current doc
- int position; // position in doc
- int count; // remaining pos in this doc
- int offset; // position in phrase
+ int doc; // current doc
+ int position; // position in doc
+ int count; // remaining pos in this doc
+ int offset; // position in phrase
final int ord; // unique across all PhrasePositions instances
- final DocsAndPositionsEnum postings; // stream of docs & positions
- PhrasePositions next; // used to make lists
+ final DocsAndPositionsEnum postings; // stream of docs & positions
+ PhrasePositions next; // used to make lists
int rptGroup = -1; // >=0 indicates that this is a repeating PP
int rptInd; // index in the rptGroup
final Term[] terms; // for repetitions initialization
@@ -44,7 +44,7 @@ final class PhrasePositions {
this.terms = terms;
}
- final boolean next() throws IOException { // increments to next doc
+ final boolean next() throws IOException { // increments to next doc
doc = postings.nextDoc();
if (doc == DocIdSetIterator.NO_MORE_DOCS) {
@@ -62,8 +62,7 @@ final class PhrasePositions {
}
final void firstPosition() throws IOException {
-
- count = postings.freq(); // read first pos
+ count = postings.freq(); // read first pos
nextPosition();
}
@@ -74,7 +73,7 @@ final class PhrasePositions {
* have exactly the same <code>position</code>.
*/
final boolean nextPosition() throws IOException {
- if (count-- > 0) { // read subsequent pos's
+ if (count-- > 0) { // read subsequent pos's
position = postings.nextPosition() - offset;
return true;
} else
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java Fri Sep 21 17:21:34 2012
@@ -251,7 +251,7 @@ public class PhraseQuery extends Query {
final Term t = terms.get(i);
final TermState state = states[i].get(context.ord);
if (state == null) { /* term doesnt exist in this segment */
- assert termNotInReader(reader, field, t.bytes()): "no termstate found but term exists in reader";
+ assert termNotInReader(reader, t): "no termstate found but term exists in reader";
return null;
}
te.seekExact(t.bytes(), state);
@@ -272,7 +272,7 @@ public class PhraseQuery extends Query {
ArrayUtil.mergeSort(postingsFreqs);
}
- if (slop == 0) { // optimize exact case
+ if (slop == 0) { // optimize exact case
ExactPhraseScorer s = new ExactPhraseScorer(this, postingsFreqs, similarity.exactSimScorer(stats, context));
if (s.noDocs) {
return null;
@@ -286,8 +286,8 @@ public class PhraseQuery extends Query {
}
// only called from assert
- private boolean termNotInReader(AtomicReader reader, String field, BytesRef bytes) throws IOException {
- return reader.docFreq(field, bytes) == 0;
+ private boolean termNotInReader(AtomicReader reader, Term term) throws IOException {
+ return reader.docFreq(term) == 0;
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Query.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Query.java Fri Sep 21 17:21:34 2012
@@ -28,17 +28,21 @@ import org.apache.lucene.index.Term;
<p>Instantiable subclasses are:
<ul>
<li> {@link TermQuery}
- <li> {@link MultiTermQuery}
<li> {@link BooleanQuery}
<li> {@link WildcardQuery}
<li> {@link PhraseQuery}
<li> {@link PrefixQuery}
<li> {@link MultiPhraseQuery}
<li> {@link FuzzyQuery}
+ <li> {@link RegexpQuery}
<li> {@link TermRangeQuery}
<li> {@link NumericRangeQuery}
- <li> {@link org.apache.lucene.search.spans.SpanQuery}
+ <li> {@link ConstantScoreQuery}
+ <li> {@link DisjunctionMaxQuery}
+ <li> {@link MatchAllDocsQuery}
</ul>
+ <p>See also the family of {@link org.apache.lucene.search.spans Span Queries}
+ and additional queries available in the <a href="{@docRoot}/../queries/overview-summary.html">Queries module</a>
*/
public abstract class Query implements Cloneable {
private float boost = 1.0f; // query boost factor
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java Fri Sep 21 17:21:34 2012
@@ -40,6 +40,8 @@ public class QueryWrapperFilter extends
* <code>query</code>.
*/
public QueryWrapperFilter(Query query) {
+ if (query == null)
+ throw new NullPointerException("Query may not be null");
this.query = query;
}
@@ -51,7 +53,7 @@ public class QueryWrapperFilter extends
@Override
public DocIdSet getDocIdSet(final AtomicReaderContext context, final Bits acceptDocs) throws IOException {
// get a private context that is used to rewrite, createWeight and score eventually
- final AtomicReaderContext privateContext = context.reader().getTopReaderContext();
+ final AtomicReaderContext privateContext = context.reader().getContext();
final Weight weight = new IndexSearcher(privateContext).createNormalizedWeight(query);
return new DocIdSet() {
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/RegexpQuery.java Fri Sep 21 17:21:34 2012
@@ -97,7 +97,9 @@ public class RegexpQuery extends Automat
buffer.append(term.field());
buffer.append(":");
}
+ buffer.append('/');
buffer.append(term.text());
+ buffer.append('/');
buffer.append(ToStringUtils.boost(getBoost()));
return buffer.toString();
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java Fri Sep 21 17:21:34 2012
@@ -73,6 +73,7 @@ class ReqOptSumScorer extends Scorer {
*/
@Override
public float score() throws IOException {
+ // TODO: sum into a double and cast to float if we ever send required clauses to BS1
int curDoc = reqScorer.docID();
float reqScore = reqScorer.score();
if (optScorer == null) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Scorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Scorer.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Scorer.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Scorer.java Fri Sep 21 17:21:34 2012
@@ -42,6 +42,8 @@ import java.util.Collections;
* with these scores.
*/
public abstract class Scorer extends DocIdSetIterator {
+ /** the Scorer's parent Weight. in some cases this may be null */
+ // TODO can we clean this up?
protected final Weight weight;
/**
@@ -118,13 +120,26 @@ public abstract class Scorer extends Doc
return Collections.emptyList();
}
- /** a child Scorer and its relationship to its parent.
+ /** A child Scorer and its relationship to its parent.
* the meaning of the relationship depends upon the parent query.
* @lucene.experimental */
public static class ChildScorer {
+ /**
+ * Child Scorer. (note this is typically a direct child, and may
+ * itself also have children).
+ */
public final Scorer child;
+ /**
+ * An arbitrary string relating this scorer to the parent.
+ */
public final String relationship;
+ /**
+ * Creates a new ChildScorer node with the specified relationship.
+ * <p>
+ * The relationship can be any be any string that makes sense to
+ * the parent Scorer.
+ */
public ChildScorer(Scorer child, String relationship) {
this.child = child;
this.relationship = relationship;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ScoringRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ScoringRewrite.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ScoringRewrite.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ScoringRewrite.java Fri Sep 21 17:21:34 2012
@@ -32,7 +32,11 @@ import org.apache.lucene.util.BytesRefHa
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.BytesRefHash.DirectBytesStartArray;
-/** @lucene.internal Only public to be accessible by spans package. */
+/**
+ * Base rewrite method that translates each term into a query, and keeps
+ * the scores as computed by the query.
+ * <p>
+ * @lucene.internal Only public to be accessible by spans package. */
public abstract class ScoringRewrite<Q extends Query> extends TermCollectingRewrite<Q> {
/** A rewrite method that first translates each term into
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java Fri Sep 21 17:21:34 2012
@@ -35,7 +35,7 @@ import org.apache.lucene.util.IOUtils;
*
* Use it like this:
*
- * <pre>
+ * <pre class="prettyprint">
* SearcherLifetimeManager mgr = new SearcherLifetimeManager();
* </pre>
*
@@ -44,7 +44,7 @@ import org.apache.lucene.util.IOUtils;
* using {@link SearcherManager} or {@link NRTManager}), and
* then record this searcher:
*
- * <pre>
+ * <pre class="prettyprint">
* // Record the current searcher, and save the returend
* // token into user's search results (eg as a hidden
* // HTML form field):
@@ -55,7 +55,7 @@ import org.apache.lucene.util.IOUtils;
* clicks next page, drills down/up, etc., take the token
* that you saved from the previous search and:
*
- * <pre>
+ * <pre class="prettyprint">
* // If possible, obtain the same searcher as the last
* // search:
* IndexSearcher searcher = mgr.acquire(token);
@@ -78,7 +78,7 @@ import org.apache.lucene.util.IOUtils;
* that's periodically reopening your searchers, you should
* periodically prune old searchers:
*
- * <pre>
+ * <pre class="prettyprint">
* mgr.prune(new PruneByAge(600.0));
* </pre>
*
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SortField.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/SortField.java Fri Sep 21 17:21:34 2012
@@ -38,6 +38,9 @@ import org.apache.lucene.util.StringHelp
*/
public class SortField {
+ /**
+ * Specifies the type of the terms to be sorted, or special types such as CUSTOM
+ */
public static enum Type {
/** Sort by document score (relevance). Sort values are Float and higher
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermCollectingRewrite.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermCollectingRewrite.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermCollectingRewrite.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermCollectingRewrite.java Fri Sep 21 17:21:34 2012
@@ -46,7 +46,7 @@ abstract class TermCollectingRewrite<Q e
final void collectTerms(IndexReader reader, MultiTermQuery query, TermCollector collector) throws IOException {
- IndexReaderContext topReaderContext = reader.getTopReaderContext();
+ IndexReaderContext topReaderContext = reader.getContext();
Comparator<BytesRef> lastTermComp = null;
for (AtomicReaderContext context : topReaderContext.leaves()) {
final Fields fields = context.reader().fields();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermQuery.java Fri Sep 21 17:21:34 2012
@@ -109,8 +109,7 @@ public class TermQuery extends Query {
private TermsEnum getTermsEnum(AtomicReaderContext context) throws IOException {
final TermState state = termStates.get(context.ord);
if (state == null) { // term is not present in that reader
- assert termNotInReader(context.reader(), term.field(), term.bytes()) : "no termstate found but term exists in reader term="
- + term;
+ assert termNotInReader(context.reader(), term) : "no termstate found but term exists in reader term=" + term;
return null;
}
// System.out.println("LD=" + reader.getLiveDocs() + " set?=" +
@@ -121,12 +120,11 @@ public class TermQuery extends Query {
return termsEnum;
}
- private boolean termNotInReader(AtomicReader reader, String field,
- BytesRef bytes) throws IOException {
+ private boolean termNotInReader(AtomicReader reader, Term term) throws IOException {
// only called from assert
// System.out.println("TQ.termNotInReader reader=" + reader + " term=" +
// field + ":" + bytes.utf8ToString());
- return reader.docFreq(field, bytes) == 0;
+ return reader.docFreq(term) == 0;
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermStatistics.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermStatistics.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermStatistics.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TermStatistics.java Fri Sep 21 17:21:34 2012
@@ -17,7 +17,7 @@ package org.apache.lucene.search;
* limitations under the License.
*/
-import org.apache.lucene.index.AtomicReader; // javadocs
+import org.apache.lucene.index.TermsEnum; // javadocs
import org.apache.lucene.util.BytesRef;
/**
* Contains statistics for a specific term
@@ -42,13 +42,13 @@ public class TermStatistics {
}
/** returns the number of documents this term occurs in
- * @see AtomicReader#docFreq(String, BytesRef) */
+ * @see TermsEnum#docFreq() */
public final long docFreq() {
return docFreq;
}
/** returns the total number of occurrences of this term
- * @see AtomicReader#totalTermFreq(String, BytesRef) */
+ * @see TermsEnum#totalTermFreq() */
public final long totalTermFreq() {
return totalTermFreq;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java Fri Sep 21 17:21:34 2012
@@ -86,7 +86,7 @@ public class TimeLimitingCollector exten
* set the baseline through this method in your prelude.
* <p>
* Example usage:
- * <pre>
+ * <pre class="prettyprint">
* Counter clock = ...;
* long baseline = clock.get();
* // ... prepare search
@@ -225,6 +225,8 @@ public class TimeLimitingCollector exten
}
/**
+ * Thread used to timeout search requests.
+ * Can be stopped completely with {@link TimerThread#stopTimer()}
* @lucene.experimental
*/
public static final class TimerThread extends Thread {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java Fri Sep 21 17:21:34 2012
@@ -33,8 +33,8 @@ import org.apache.lucene.util.PriorityQu
*/
public abstract class TopDocsCollector<T extends ScoreDoc> extends Collector {
- // This is used in case topDocs() is called with illegal parameters, or there
- // simply aren't (enough) results.
+ /** This is used in case topDocs() is called with illegal parameters, or there
+ * simply aren't (enough) results. */
protected static final TopDocs EMPTY_TOPDOCS = new TopDocs(0, new ScoreDoc[0], Float.NaN);
/**
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/TopScoreDocCollector.java Fri Sep 21 17:21:34 2012
@@ -30,7 +30,7 @@ import org.apache.lucene.index.AtomicRea
* going to be collected in doc Id order or not.
*
* <p><b>NOTE</b>: The values {@link Float#NaN} and
- * {Float#NEGATIVE_INFINITY} are not valid scores. This
+ * {@link Float#NEGATIVE_INFINITY} are not valid scores. This
* collector will not properly collect hits with such
* scores.
*/
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Weight.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/Weight.java Fri Sep 21 17:21:34 2012
@@ -38,7 +38,7 @@ import org.apache.lucene.util.Bits;
* <p>
* Since {@link Weight} creates {@link Scorer} instances for a given
* {@link AtomicReaderContext} ({@link #scorer(AtomicReaderContext,
- * boolean, boolean, boolean, boolean, boolean, Bits)})
+ * boolean, boolean, PostingFeatures, Bits)})
* callers must maintain the relationship between the searcher's top-level
* {@link IndexReaderContext} and the context used to create a {@link Scorer}.
* <p>
@@ -53,7 +53,7 @@ import org.apache.lucene.util.Bits;
* <li>The query normalization factor is passed to {@link #normalize(float, float)}. At
* this point the weighting is complete.
* <li>A <code>Scorer</code> is constructed by
- * {@link #scorer(AtomicReaderContext, boolean, boolean, boolean, boolean, boolean, Bits)}.
+ * {@link #scorer(AtomicReaderContext, boolean, boolean, PostingFeatures, Bits)}.
* </ol>
*
* @since 2.9
@@ -119,7 +119,7 @@ public abstract class Weight {
* Returns true iff this implementation scores docs only out of order. This
* method is used in conjunction with {@link Collector}'s
* {@link Collector#acceptsDocsOutOfOrder() acceptsDocsOutOfOrder} and
- * {@link #scorer(AtomicReaderContext, boolean, boolean, boolean, boolean, boolean, Bits)} to
+ * {@link #scorer(AtomicReaderContext, boolean, boolean, PostingFeatures, Bits)} to
* create a matching {@link Scorer} instance for a given {@link Collector}, or
* vice versa.
* <p>
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/WildcardQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/WildcardQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/WildcardQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/WildcardQuery.java Fri Sep 21 17:21:34 2012
@@ -28,7 +28,9 @@ import java.util.List;
/** Implements the wildcard search query. Supported wildcards are <code>*</code>, which
* matches any character sequence (including the empty one), and <code>?</code>,
- * which matches any single character. Note this query can be slow, as it
+ * which matches any single character. '\' is the escape character.
+ * <p>
+ * Note this query can be slow, as it
* needs to iterate over many terms. In order to prevent extremely slow WildcardQueries,
* a Wildcard term should not start with the wildcard <code>*</code>
*
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java Fri Sep 21 17:21:34 2012
@@ -24,12 +24,12 @@ package org.apache.lucene.search.payload
public class MinPayloadFunction extends PayloadFunction {
@Override
- public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
+ public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
if (numPayloadsSeen == 0) {
return currentPayloadScore;
} else {
- return Math.min(currentPayloadScore, currentScore);
- }
+ return Math.min(currentPayloadScore, currentScore);
+ }
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadFunction.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadFunction.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadFunction.java Fri Sep 21 17:21:34 2012
@@ -56,10 +56,10 @@ public abstract class PayloadFunction {
public abstract float docScore(int docId, String field, int numPayloadsSeen, float payloadScore);
public Explanation explain(int docId, String field, int numPayloadsSeen, float payloadScore){
- Explanation result = new Explanation();
- result.setDescription(getClass().getSimpleName() + ".docScore()");
- result.setValue(docScore(docId, field, numPayloadsSeen, payloadScore));
- return result;
+ Explanation result = new Explanation();
+ result.setDescription(getClass().getSimpleName() + ".docScore()");
+ result.setValue(docScore(docId, field, numPayloadsSeen, payloadScore));
+ return result;
};
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java Fri Sep 21 17:21:34 2012
@@ -257,7 +257,7 @@ public class PayloadNearQuery extends Sp
getPayloads(spansArr);
more = spans.next();
} while (more && (doc == spans.doc()));
- return true;
+ return true;
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java Fri Sep 21 17:21:34 2012
@@ -60,7 +60,7 @@ public class PayloadSpanUtil {
* @param context
* that contains doc with payloads to extract
*
- * @see IndexReader#getTopReaderContext()
+ * @see IndexReader#getContext()
*/
public PayloadSpanUtil(IndexReaderContext context) {
this.context = context;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/BooleanIntervalIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/BooleanIntervalIterator.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/BooleanIntervalIterator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/BooleanIntervalIterator.java Fri Sep 21 17:21:34 2012
@@ -18,8 +18,6 @@ package org.apache.lucene.search.positio
*/
import org.apache.lucene.search.Scorer;
-import com.sun.tools.javac.resources.compiler;
-
import java.io.IOException;
import java.util.List;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffect.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffect.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffect.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffect.java Fri Sep 21 17:21:34 2012
@@ -30,6 +30,13 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public abstract class AfterEffect {
+
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public AfterEffect() {}
+
/** Returns the aftereffect score. */
public abstract float score(BasicStats stats, float tfn);
@@ -38,6 +45,10 @@ public abstract class AfterEffect {
/** Implementation used when there is no aftereffect. */
public static final class NoAfterEffect extends AfterEffect {
+
+ /** Sole constructor: parameter-free */
+ public NoAfterEffect() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
return 1f;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectB.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectB.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectB.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectB.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,10 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public class AfterEffectB extends AfterEffect {
+
+ /** Sole constructor: parameter-free */
+ public AfterEffectB() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
long F = stats.getTotalTermFreq()+1;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectL.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectL.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectL.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/AfterEffectL.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,10 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public class AfterEffectL extends AfterEffect {
+
+ /** Sole constructor: parameter-free */
+ public AfterEffectL() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
return 1 / (tfn + 1);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BM25Similarity.java Fri Sep 21 17:21:34 2012
@@ -41,6 +41,11 @@ public class BM25Similarity extends Simi
private final float b;
// TODO: should we add a delta like sifaka.cs.uiuc.edu/~ylv2/pub/sigir11-bm25l.pdf ?
+ /**
+ * BM25 with the supplied parameter values.
+ * @param k1 Controls non-linear term frequency normalization (saturation).
+ * @param b Controls to what degree document length normalizes tf values.
+ */
public BM25Similarity(float k1, float b) {
this.k1 = k1;
this.b = b;
@@ -98,17 +103,23 @@ public class BM25Similarity extends Simi
return NORM_TABLE[b & 0xFF];
}
- // Default true
+ /**
+ * True if overlap tokens (tokens with a position of increment of zero) are
+ * discounted from the document's length.
+ */
protected boolean discountOverlaps = true;
- /** Determines whether overlap tokens (Tokens with 0 position increment) are
+ /** Sets whether overlap tokens (Tokens with 0 position increment) are
* ignored when computing norm. By default this is true, meaning overlap
* tokens do not count when computing norms. */
public void setDiscountOverlaps(boolean v) {
discountOverlaps = v;
}
- /** @see #setDiscountOverlaps */
+ /**
+ * Returns true if overlap tokens are discounted from the document's length.
+ * @see #setDiscountOverlaps
+ */
public boolean getDiscountOverlaps() {
return discountOverlaps;
}
@@ -130,6 +141,28 @@ public class BM25Similarity extends Simi
norm.setByte(encodeNormValue(state.getBoost(), numTerms));
}
+ /**
+ * Computes a score factor for a simple term and returns an explanation
+ * for that score factor.
+ *
+ * <p>
+ * The default implementation uses:
+ *
+ * <pre class="prettyprint">
+ * idf(docFreq, searcher.maxDoc());
+ * </pre>
+ *
+ * Note that {@link CollectionStatistics#maxDoc()} is used instead of
+ * {@link org.apache.lucene.index.IndexReader#numDocs() IndexReader#numDocs()} because also
+ * {@link TermStatistics#docFreq()} is used, and when the latter
+ * is inaccurate, so is {@link CollectionStatistics#maxDoc()}, and in the same direction.
+ * In addition, {@link CollectionStatistics#maxDoc()} is more efficient to compute
+ *
+ * @param collectionStats collection-level statistics
+ * @param termStats term-level statistics for the term
+ * @return an Explain object that includes both an idf score factor
+ and an explanation for the term.
+ */
public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics termStats) {
final long df = termStats.docFreq();
final long max = collectionStats.maxDoc();
@@ -137,6 +170,19 @@ public class BM25Similarity extends Simi
return new Explanation(idf, "idf(docFreq=" + df + ", maxDocs=" + max + ")");
}
+ /**
+ * Computes a score factor for a phrase.
+ *
+ * <p>
+ * The default implementation sums the idf factor for
+ * each term in the phrase.
+ *
+ * @param collectionStats collection-level statistics
+ * @param termStats term-level statistics for the terms in the phrase
+ * @return an Explain object that includes both an idf
+ * score factor for the phrase and an explanation
+ * for each term.
+ */
public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics termStats[]) {
final long max = collectionStats.maxDoc();
float idf = 0.0f;
@@ -344,10 +390,18 @@ public class BM25Similarity extends Simi
return "BM25(k1=" + k1 + ",b=" + b + ")";
}
+ /**
+ * Returns the <code>k1</code> parameter
+ * @see #BM25Similarity(float, float)
+ */
public float getK1() {
return k1;
}
+ /**
+ * Returns the <code>b</code> parameter
+ * @see #BM25Similarity(float, float)
+ */
public float getB() {
return b;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModel.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModel.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModel.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModel.java Fri Sep 21 17:21:34 2012
@@ -29,6 +29,13 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public abstract class BasicModel {
+
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public BasicModel() {}
+
/** Returns the informative content score. */
public abstract float score(BasicStats stats, float tfn);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelBE.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelBE.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelBE.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelBE.java Fri Sep 21 17:21:34 2012
@@ -30,6 +30,10 @@ import static org.apache.lucene.search.s
* but with less practical problems.
*/
public class BasicModelBE extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelBE() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
double F = stats.getTotalTermFreq() + 1 + tfn;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelD.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelD.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelD.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelD.java Fri Sep 21 17:21:34 2012
@@ -32,6 +32,10 @@ import static org.apache.lucene.search.s
* @lucene.experimental
*/
public class BasicModelD extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelD() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
// we have to ensure phi is always < 1 for tiny TTF values, otherwise nphi can go negative,
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelG.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelG.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelG.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelG.java Fri Sep 21 17:21:34 2012
@@ -26,6 +26,10 @@ import static org.apache.lucene.search.s
* @lucene.experimental
*/
public class BasicModelG extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelG() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
// just like in BE, approximation only holds true when F << N, so we use lambda = F / (N + F)
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIF.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIF.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIF.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIF.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,10 @@ import static org.apache.lucene.search.s
* @lucene.experimental
*/
public class BasicModelIF extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelIF() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
long N = stats.getNumberOfDocuments();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIn.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIn.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIn.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIn.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,10 @@ import static org.apache.lucene.search.s
* @lucene.experimental
*/
public class BasicModelIn extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelIn() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
long N = stats.getNumberOfDocuments();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIne.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIne.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIne.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelIne.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,10 @@ import static org.apache.lucene.search.s
* @lucene.experimental
*/
public class BasicModelIne extends BasicModel {
+
+ /** Sole constructor: parameter-free */
+ public BasicModelIne() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
long N = stats.getNumberOfDocuments();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelP.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelP.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelP.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/BasicModelP.java Fri Sep 21 17:21:34 2012
@@ -31,6 +31,9 @@ public class BasicModelP extends BasicMo
/** {@code log2(Math.E)}, precomputed. */
protected static double LOG2_E = log2(Math.E);
+ /** Sole constructor: parameter-free */
+ public BasicModelP() {}
+
@Override
public final float score(BasicStats stats, float tfn) {
float lambda = (float)(stats.getTotalTermFreq()+1) / (stats.getNumberOfDocuments()+1);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DFRSimilarity.java Fri Sep 21 17:21:34 2012
@@ -18,6 +18,8 @@ package org.apache.lucene.search.similar
*/
import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.similarities.AfterEffect.NoAfterEffect;
+import org.apache.lucene.search.similarities.Normalization.NoNormalization;
/**
* Implements the <em>divergence from randomness (DFR)</em> framework
@@ -31,6 +33,41 @@ import org.apache.lucene.search.Explanat
* {@code BasicModel}, {@code AfterEffect} and {@code Normalization},
* respectively. The names of these classes were chosen to match the names of
* their counterparts in the Terrier IR engine.</p>
+ * <p>To construct a DFRSimilarity, you must specify the implementations for
+ * all three components of DFR:
+ * <ol>
+ * <li>{@link BasicModel}: Basic model of information content:
+ * <ul>
+ * <li>{@link BasicModelBE}: Limiting form of Bose-Einstein
+ * <li>{@link BasicModelG}: Geometric approximation of Bose-Einstein
+ * <li>{@link BasicModelP}: Poisson approximation of the Binomial
+ * <li>{@link BasicModelD}: Divergence approximation of the Binomial
+ * <li>{@link BasicModelIn}: Inverse document frequency
+ * <li>{@link BasicModelIne}: Inverse expected document
+ * frequency [mixture of Poisson and IDF]
+ * <li>{@link BasicModelIF}: Inverse term frequency
+ * [approximation of I(ne)]
+ * </ul>
+ * <li>{@link AfterEffect}: First normalization of information
+ * gain:
+ * <ul>
+ * <li>{@link AfterEffectL}: Laplace's law of succession
+ * <li>{@link AfterEffectB}: Ratio of two Bernoulli processes
+ * <li>{@link NoAfterEffect}: no first normalization
+ * </ul>
+ * <li>{@link Normalization}: Second (length) normalization:
+ * <ul>
+ * <li>{@link NormalizationH1}: Uniform distribution of term
+ * frequency
+ * <li>{@link NormalizationH2}: term frequency density inversely
+ * related to length
+ * <li>{@link NormalizationH3}: term frequency normalization
+ * provided by Dirichlet prior
+ * <li>{@link NormalizationZ}: term frequency normalization provided
+ * by a Zipfian relation
+ * <li>{@link NoNormalization}: no second normalization
+ * </ul>
+ * </ol>
* <p>Note that <em>qtf</em>, the multiplicity of term-occurrence in the query,
* is not handled by this implementation.</p>
* @see BasicModel
@@ -46,6 +83,16 @@ public class DFRSimilarity extends Simil
/** The term frequency normalization. */
protected final Normalization normalization;
+ /**
+ * Creates DFRSimilarity from the three components.
+ * <p>
+ * Note that <code>null</code> values are not allowed:
+ * if you want no normalization or after-effect, instead pass
+ * {@link NoNormalization} or {@link NoAfterEffect} respectively.
+ * @param basicModel Basic model of information content
+ * @param afterEffect First normalization of information gain
+ * @param normalization Second (length) normalization
+ */
public DFRSimilarity(BasicModel basicModel,
AfterEffect afterEffect,
Normalization normalization) {
@@ -84,14 +131,23 @@ public class DFRSimilarity extends Simil
+ normalization.toString();
}
+ /**
+ * Returns the basic model of information content
+ */
public BasicModel getBasicModel() {
return basicModel;
}
+ /**
+ * Returns the first normalization
+ */
public AfterEffect getAfterEffect() {
return afterEffect;
}
+ /**
+ * Returns the second normalization
+ */
public Normalization getNormalization() {
return normalization;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DefaultSimilarity.java Fri Sep 21 17:21:34 2012
@@ -1,9 +1,5 @@
package org.apache.lucene.search.similarities;
-import org.apache.lucene.index.FieldInvertState;
-import org.apache.lucene.index.Norm;
-import org.apache.lucene.util.BytesRef;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -21,9 +17,16 @@ import org.apache.lucene.util.BytesRef;
* limitations under the License.
*/
+import org.apache.lucene.index.FieldInvertState;
+import org.apache.lucene.index.Norm;
+import org.apache.lucene.util.BytesRef;
+
/** Expert: Default scoring implementation. */
public class DefaultSimilarity extends TFIDFSimilarity {
+ /** Sole constructor: parameter-free */
+ public DefaultSimilarity() {}
+
/** Implemented as <code>overlap / maxOverlap</code>. */
public float coord(int overlap, int maxOverlap) {
return overlap / (float)maxOverlap;
@@ -76,7 +79,10 @@ public class DefaultSimilarity extends T
return (float)(Math.log(numDocs/(double)(docFreq+1)) + 1.0);
}
- // Default true
+ /**
+ * True if overlap tokens (tokens with a position of increment of zero) are
+ * discounted from the document's length.
+ */
protected boolean discountOverlaps = true;
/** Determines whether overlap tokens (Tokens with
@@ -92,7 +98,10 @@ public class DefaultSimilarity extends T
discountOverlaps = v;
}
- /** @see #setDiscountOverlaps */
+ /**
+ * Returns true if overlap tokens are discounted from the document's length.
+ * @see #setDiscountOverlaps
+ */
public boolean getDiscountOverlaps() {
return discountOverlaps;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Distribution.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Distribution.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Distribution.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Distribution.java Fri Sep 21 17:21:34 2012
@@ -26,6 +26,13 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public abstract class Distribution {
+
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public Distribution() {}
+
/** Computes the score. */
public abstract float score(BasicStats stats, float tfn, float lambda);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionLL.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionLL.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionLL.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionLL.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,10 @@ package org.apache.lucene.search.similar
* @lucene.experimental
*/
public class DistributionLL extends Distribution {
+
+ /** Sole constructor: parameter-free */
+ public DistributionLL() {}
+
@Override
public final float score(BasicStats stats, float tfn, float lambda) {
return (float)-Math.log(lambda / (tfn + lambda));
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionSPL.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionSPL.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionSPL.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/DistributionSPL.java Fri Sep 21 17:21:34 2012
@@ -26,6 +26,10 @@ package org.apache.lucene.search.similar
* @lucene.experimental
*/
public class DistributionSPL extends Distribution {
+
+ /** Sole constructor: parameter-free */
+ public DistributionSPL() {}
+
@Override
public final float score(BasicStats stats, float tfn, float lambda) {
if (lambda == 1f) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/IBSimilarity.java Fri Sep 21 17:21:34 2012
@@ -18,6 +18,7 @@ package org.apache.lucene.search.similar
*/
import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.similarities.Normalization.NoNormalization;
/**
* Provides a framework for the family of information-based models, as described
@@ -39,6 +40,32 @@ import org.apache.lucene.search.Explanat
* <p>The framework described in the paper has many similarities to the DFR
* framework (see {@link DFRSimilarity}). It is possible that the two
* Similarities will be merged at one point.</p>
+ * <p>To construct an IBSimilarity, you must specify the implementations for
+ * all three components of the Information-Based model.
+ * <ol>
+ * <li>{@link Distribution}: Probabilistic distribution used to
+ * model term occurrence
+ * <ul>
+ * <li>{@link DistributionLL}: Log-logistic</li>
+ * <li>{@link DistributionLL}: Smoothed power-law</li>
+ * </ul>
+ * </li>
+ * <li>{@link Lambda}: λ<sub>w</sub> parameter of the
+ * probability distribution
+ * <ul>
+ * <li>{@link LambdaDF}: <code>N<sub>w</sub>/N</code> or average
+ * number of documents where w occurs</li>
+ * <li>{@link LambdaTTF}: <code>F<sub>w</sub>/N</code> or
+ * average number of occurrences of w in the collection</li>
+ * </ul>
+ * </li>
+ * <li>{@link Normalization}: Term frequency normalization
+ * <blockquote>Any supported DFR normalization (listed in
+ * {@link DFRSimilarity})</blockquote>
+ * </li>
+ * </ol>
+ * <p>
+ * @see DFRSimilarity
* @lucene.experimental
*/
public class IBSimilarity extends SimilarityBase {
@@ -49,6 +76,16 @@ public class IBSimilarity extends Simila
/** The term frequency normalization. */
protected final Normalization normalization;
+ /**
+ * Creates IBSimilarity from the three components.
+ * <p>
+ * Note that <code>null</code> values are not allowed:
+ * if you want no normalization, instead pass
+ * {@link NoNormalization}.
+ * @param distribution probabilistic distribution modeling term occurrence
+ * @param lambda distribution's λ<sub>w</sub> parameter
+ * @param normalization term frequency normalization
+ */
public IBSimilarity(Distribution distribution,
Lambda lambda,
Normalization normalization) {
@@ -92,14 +129,23 @@ public class IBSimilarity extends Simila
+ normalization.toString();
}
+ /**
+ * Returns the distribution
+ */
public Distribution getDistribution() {
return distribution;
}
+ /**
+ * Returns the distribution's lambda parameter
+ */
public Lambda getLambda() {
return lambda;
}
-
+
+ /**
+ * Returns the term frequency normalization
+ */
public Normalization getNormalization() {
return normalization;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMDirichletSimilarity.java Fri Sep 21 17:21:34 2012
@@ -40,13 +40,13 @@ public class LMDirichletSimilarity exten
/** The μ parameter. */
private final float mu;
- /** @param mu the μ parameter. */
+ /** Instantiates the similarity with the provided μ parameter. */
public LMDirichletSimilarity(CollectionModel collectionModel, float mu) {
super(collectionModel);
this.mu = mu;
}
- /** @param mu the μ parameter. */
+ /** Instantiates the similarity with the provided μ parameter. */
public LMDirichletSimilarity(float mu) {
this.mu = mu;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.java Fri Sep 21 17:21:34 2012
@@ -37,14 +37,14 @@ public class LMJelinekMercerSimilarity e
/** The λ parameter. */
private final float lambda;
- /** @param lambda the λ parameter. */
+ /** Instantiates with the specified collectionModel and λ parameter. */
public LMJelinekMercerSimilarity(
CollectionModel collectionModel, float lambda) {
super(collectionModel);
this.lambda = lambda;
}
- /** @param lambda the λ parameter. */
+ /** Instantiates with the specified λ parameter. */
public LMJelinekMercerSimilarity(float lambda) {
this.lambda = lambda;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LMSimilarity.java Fri Sep 21 17:21:34 2012
@@ -104,6 +104,9 @@ public abstract class LMSimilarity exten
/** The probability that the current term is generated by the collection. */
private float collectionProbability;
+ /**
+ * Creates LMStats for the provided field and query-time boost
+ */
public LMStats(String field, float queryBoost) {
super(field, queryBoost);
}
@@ -142,6 +145,10 @@ public abstract class LMSimilarity exten
* collection, divided by the total number of tokens {@code + 1}.
*/
public static class DefaultCollectionModel implements CollectionModel {
+
+ /** Sole constructor: parameter-free */
+ public DefaultCollectionModel() {}
+
@Override
public float computeProbability(BasicStats stats) {
return (stats.getTotalTermFreq()+1F) / (stats.getNumberOfFieldTokens()+1F);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Lambda.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Lambda.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Lambda.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Lambda.java Fri Sep 21 17:21:34 2012
@@ -26,6 +26,13 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public abstract class Lambda {
+
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public Lambda() {}
+
/** Computes the lambda parameter. */
public abstract float lambda(BasicStats stats);
/** Explains the lambda parameter. */
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaDF.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaDF.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaDF.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaDF.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,10 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public class LambdaDF extends Lambda {
+
+ /** Sole constructor: parameter-free */
+ public LambdaDF() {}
+
@Override
public final float lambda(BasicStats stats) {
return (stats.getDocFreq()+1F) / (stats.getNumberOfDocuments()+1F);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaTTF.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaTTF.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaTTF.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/LambdaTTF.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,10 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public class LambdaTTF extends Lambda {
+
+ /** Sole constructor: parameter-free */
+ public LambdaTTF() {}
+
@Override
public final float lambda(BasicStats stats) {
return (stats.getTotalTermFreq()+1F) / (stats.getNumberOfDocuments()+1F);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/MultiSimilarity.java Fri Sep 21 17:21:34 2012
@@ -34,8 +34,11 @@ import org.apache.lucene.util.BytesRef;
* @lucene.experimental
*/
public class MultiSimilarity extends Similarity {
+ /** the sub-similarities used to create the combined score */
protected final Similarity sims[];
+ /** Creates a MultiSimilarity which will sum the scores
+ * of the provided <code>sims</code>. */
public MultiSimilarity(Similarity sims[]) {
this.sims = sims;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Normalization.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Normalization.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Normalization.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/Normalization.java Fri Sep 21 17:21:34 2012
@@ -27,6 +27,13 @@ import org.apache.lucene.search.Explanat
* @lucene.experimental
*/
public abstract class Normalization {
+
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public Normalization() {}
+
/** Returns the normalized term frequency.
* @param len the field length. */
public abstract float tfn(BasicStats stats, float tf, float len);
@@ -50,6 +57,10 @@ public abstract class Normalization {
/** Implementation used when there is no normalization. */
public static final class NoNormalization extends Normalization {
+
+ /** Sole constructor: parameter-free */
+ public NoNormalization() {}
+
@Override
public final float tfn(BasicStats stats, float tf, float len) {
return tf;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH1.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH1.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH1.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH1.java Fri Sep 21 17:21:34 2012
@@ -30,10 +30,18 @@ package org.apache.lucene.search.similar
public class NormalizationH1 extends Normalization {
private final float c;
+ /**
+ * Creates NormalizationH1 with the supplied parameter <code>c</code>.
+ * @param c hyper-parameter that controls the term frequency
+ * normalization with respect to the document length.
+ */
public NormalizationH1(float c) {
this.c = c;
}
+ /**
+ * Calls {@link #NormalizationH1(float) NormalizationH1(1)}
+ */
public NormalizationH1() {
this(1);
}
@@ -48,6 +56,10 @@ public class NormalizationH1 extends Nor
return "1";
}
+ /**
+ * Returns the <code>c</code> parameter.
+ * @see #NormalizationH1(float)
+ */
public float getC() {
return c;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH2.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH2.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/similarities/NormalizationH2.java Fri Sep 21 17:21:34 2012
@@ -32,10 +32,18 @@ import static org.apache.lucene.search.s
public class NormalizationH2 extends Normalization {
private final float c;
+ /**
+ * Creates NormalizationH2 with the supplied parameter <code>c</code>.
+ * @param c hyper-parameter that controls the term frequency
+ * normalization with respect to the document length.
+ */
public NormalizationH2(float c) {
this.c = c;
}
+ /**
+ * Calls {@link #NormalizationH2(float) NormalizationH2(1)}
+ */
public NormalizationH2() {
this(1);
}
@@ -50,6 +58,10 @@ public class NormalizationH2 extends Nor
return "2";
}
+ /**
+ * Returns the <code>c</code> parameter.
+ * @see #NormalizationH2(float)
+ */
public float getC() {
return c;
}