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 [13/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/index/ConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java Fri Sep 21 17:21:34 2012
@@ -47,6 +47,7 @@ public class ConcurrentMergeScheduler ex
private int mergeThreadPriority = -1;
+ /** List of currently active {@link MergeThread}s. */
protected List<MergeThread> mergeThreads = new ArrayList<MergeThread>();
// Max number of merge threads allowed to be running at
@@ -63,11 +64,21 @@ public class ConcurrentMergeScheduler ex
// throttling the incoming threads
private int maxMergeCount = maxThreadCount+2;
+ /** {@link Directory} that holds the index. */
protected Directory dir;
+ /** {@link IndexWriter} that owns this instance. */
protected IndexWriter writer;
+
+ /** How many {@link MergeThread}s have kicked off (this is use
+ * to name them). */
protected int mergeThreadCount;
+ /** Sole constructor, with all settings set to default
+ * values. */
+ public ConcurrentMergeScheduler() {
+ }
+
/** Sets the max # simultaneous merge threads that should
* be running at once. This must be <= {@link
* #setMaxMergeCount}. */
@@ -81,7 +92,9 @@ public class ConcurrentMergeScheduler ex
maxThreadCount = count;
}
- /** @see #setMaxThreadCount(int) */
+ /** Returns {@code maxThreadCount}.
+ *
+ * @see #setMaxThreadCount(int) */
public int getMaxThreadCount() {
return maxThreadCount;
}
@@ -129,7 +142,7 @@ public class ConcurrentMergeScheduler ex
updateMergeThreads();
}
- // Larger merges come first
+ /** Sorts {@link MergeThread}s; larger merges come first. */
protected static final Comparator<MergeThread> compareByMergeDocCount = new Comparator<MergeThread>() {
public int compare(MergeThread t1, MergeThread t2) {
final MergePolicy.OneMerge m1 = t1.getCurrentMerge();
@@ -210,7 +223,7 @@ public class ConcurrentMergeScheduler ex
* Returns true if verbosing is enabled. This method is usually used in
* conjunction with {@link #message(String)}, like that:
*
- * <pre>
+ * <pre class="prettyprint">
* if (verbose()) {
* message("your message");
* }
@@ -398,6 +411,8 @@ public class ConcurrentMergeScheduler ex
return thread;
}
+ /** Runs a merge thread, which may run one or more merges
+ * in sequence. */
protected class MergeThread extends Thread {
IndexWriter tWriter;
@@ -405,19 +420,24 @@ public class ConcurrentMergeScheduler ex
MergePolicy.OneMerge runningMerge;
private volatile boolean done;
+ /** Sole constructor. */
public MergeThread(IndexWriter writer, MergePolicy.OneMerge startMerge) {
this.tWriter = writer;
this.startMerge = startMerge;
}
+ /** Record the currently running merge. */
public synchronized void setRunningMerge(MergePolicy.OneMerge merge) {
runningMerge = merge;
}
+ /** Return the currently running merge. */
public synchronized MergePolicy.OneMerge getRunningMerge() {
return runningMerge;
}
+ /** Return the current merge, or null if this {@code
+ * MergeThread} is done. */
public synchronized MergePolicy.OneMerge getCurrentMerge() {
if (done) {
return null;
@@ -428,6 +448,7 @@ public class ConcurrentMergeScheduler ex
}
}
+ /** Set the priority of this thread. */
public void setThreadPriority(int pri) {
try {
setPriority(pri);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/CorruptIndexException.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,7 @@ import java.io.IOException;
* an inconsistency in the index.
*/
public class CorruptIndexException extends IOException {
+ /** Sole constructor. */
public CorruptIndexException(String message) {
super(message);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DirectoryReader.java Fri Sep 21 17:21:34 2012
@@ -49,8 +49,11 @@ import org.apache.lucene.store.Directory
(non-Lucene) objects instead.
*/
public abstract class DirectoryReader extends BaseCompositeReader<AtomicReader> {
+
+ /** Default termInfosIndexDivisor. */
public static final int DEFAULT_TERMS_INDEX_DIVISOR = 1;
+ /** The index directory. */
protected final Directory directory;
/** Returns a IndexReader reading the index in the given
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java Fri Sep 21 17:21:34 2012
@@ -28,6 +28,7 @@ import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.FieldInfosWriter;
import org.apache.lucene.codecs.PerDocConsumer;
+import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.DocumentsWriterPerThread.DocState;
import org.apache.lucene.index.TypePromoter.TypeCompatibility;
import org.apache.lucene.store.IOContext;
@@ -218,59 +219,24 @@ final class DocFieldProcessor extends Do
// seen before (eg suddenly turning on norms or
// vectors, etc.):
- for(IndexableField field : docState.doc) {
+ for(IndexableField field : docState.doc.indexableFields()) {
final String fieldName = field.name();
+ IndexableFieldType ft = field.fieldType();
- // Make sure we have a PerField allocated
- final int hashPos = fieldName.hashCode() & hashMask;
- DocFieldProcessorPerField fp = fieldHash[hashPos];
- while(fp != null && !fp.fieldInfo.name.equals(fieldName)) {
- fp = fp.next;
- }
-
- if (fp == null) {
-
- // TODO FI: we need to genericize the "flags" that a
- // field holds, and, how these flags are merged; it
- // needs to be more "pluggable" such that if I want
- // to have a new "thing" my Fields can do, I can
- // easily add it
- FieldInfo fi = fieldInfos.addOrUpdate(fieldName, field.fieldType());
-
- fp = new DocFieldProcessorPerField(this, fi);
- fp.next = fieldHash[hashPos];
- fieldHash[hashPos] = fp;
- totalFieldCount++;
-
- if (totalFieldCount >= fieldHash.length/2) {
- rehash();
- }
- } else {
- fieldInfos.addOrUpdate(fp.fieldInfo.name, field.fieldType());
- }
-
- if (thisFieldGen != fp.lastGen) {
-
- // First time we're seeing this field for this doc
- fp.fieldCount = 0;
-
- if (fieldCount == fields.length) {
- final int newSize = fields.length*2;
- DocFieldProcessorPerField newArray[] = new DocFieldProcessorPerField[newSize];
- System.arraycopy(fields, 0, newArray, 0, fieldCount);
- fields = newArray;
- }
-
- fields[fieldCount++] = fp;
- fp.lastGen = thisFieldGen;
- }
+ DocFieldProcessorPerField fp = processField(fieldInfos, thisFieldGen, fieldName, ft);
fp.addField(field);
+ }
+ for (StorableField field: docState.doc.storableFields()) {
+ final String fieldName = field.name();
+ IndexableFieldType ft = field.fieldType();
- if (field.fieldType().stored()) {
+ DocFieldProcessorPerField fp = processField(fieldInfos, thisFieldGen, fieldName, ft);
+ if (ft.stored()) {
fieldsWriter.addField(field, fp.fieldInfo);
}
- final DocValues.Type dvType = field.fieldType().docValueType();
+
+ final DocValues.Type dvType = ft.docValueType();
if (dvType != null) {
DocValuesConsumerHolder docValuesConsumer = docValuesConsumer(dvType,
docState, fp.fieldInfo);
@@ -313,6 +279,54 @@ final class DocFieldProcessor extends Do
}
}
+ private DocFieldProcessorPerField processField(FieldInfos.Builder fieldInfos,
+ final int thisFieldGen, final String fieldName, IndexableFieldType ft) {
+ // Make sure we have a PerField allocated
+ final int hashPos = fieldName.hashCode() & hashMask;
+ DocFieldProcessorPerField fp = fieldHash[hashPos];
+ while(fp != null && !fp.fieldInfo.name.equals(fieldName)) {
+ fp = fp.next;
+ }
+
+ if (fp == null) {
+
+ // TODO FI: we need to genericize the "flags" that a
+ // field holds, and, how these flags are merged; it
+ // needs to be more "pluggable" such that if I want
+ // to have a new "thing" my Fields can do, I can
+ // easily add it
+ FieldInfo fi = fieldInfos.addOrUpdate(fieldName, ft);
+
+ fp = new DocFieldProcessorPerField(this, fi);
+ fp.next = fieldHash[hashPos];
+ fieldHash[hashPos] = fp;
+ totalFieldCount++;
+
+ if (totalFieldCount >= fieldHash.length/2) {
+ rehash();
+ }
+ } else {
+ fieldInfos.addOrUpdate(fp.fieldInfo.name, ft);
+ }
+
+ if (thisFieldGen != fp.lastGen) {
+
+ // First time we're seeing this field for this doc
+ fp.fieldCount = 0;
+
+ if (fieldCount == fields.length) {
+ final int newSize = fields.length*2;
+ DocFieldProcessorPerField newArray[] = new DocFieldProcessorPerField[newSize];
+ System.arraycopy(fields, 0, newArray, 0, fieldCount);
+ fields = newArray;
+ }
+
+ fields[fieldCount++] = fp;
+ fp.lastGen = thisFieldGen;
+ }
+ return fp;
+ }
+
private static final Comparator<DocFieldProcessorPerField> fieldsComp = new Comparator<DocFieldProcessorPerField>() {
public int compare(DocFieldProcessorPerField o1, DocFieldProcessorPerField o2) {
return o1.fieldInfo.name.compareTo(o2.fieldInfo.name);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java Fri Sep 21 17:21:34 2012
@@ -75,7 +75,7 @@ final class DocInverterPerField extends
// TODO FI: this should be "genericized" to querying
// consumer if it wants to see this particular field
// tokenized.
- if (fieldType.indexed() && doInvert) {
+ if (doInvert) {
final boolean analyzed = fieldType.tokenized() && docState.analyzer != null;
// if the field omits norms, the boost cannot be indexed.
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java Fri Sep 21 17:21:34 2012
@@ -17,17 +17,18 @@
package org.apache.lucene.index;
-import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.util.PagedBytes;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.StringHelper;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import java.util.Comparator;
+import java.util.List;
+
+import org.apache.lucene.codecs.PostingsFormat; // javadocs
+import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.PagedBytes;
+import org.apache.lucene.util.StringHelper;
/**
* This class enables fast access to multiple term ords for
@@ -107,32 +108,57 @@ public class DocTermOrds {
// values 0 (end term) and 1 (index is a pointer into byte array)
private final static int TNUM_OFFSET = 2;
- // Default: every 128th term is indexed
+ /** Every 128th term is indexed, by default. */
public final static int DEFAULT_INDEX_INTERVAL_BITS = 7; // decrease to a low number like 2 for testing
private int indexIntervalBits;
private int indexIntervalMask;
private int indexInterval;
+ /** Don't uninvert terms that exceed this count. */
protected final int maxTermDocFreq;
+ /** Field we are uninverting. */
protected final String field;
+ /** Number of terms in the field. */
protected int numTermsInField;
- protected long termInstances; // total number of references to term numbers
+
+ /** Total number of references to term numbers. */
+ protected long termInstances;
private long memsz;
- protected int total_time; // total time to uninvert the field
- protected int phase1_time; // time for phase1 of the uninvert process
+ /** Total time to uninvert the field. */
+ protected int total_time;
+
+ /** Time for phase1 of the uninvert process. */
+ protected int phase1_time;
+
+ /** Holds the per-document ords or a pointer to the ords. */
protected int[] index;
+
+ /** Holds term ords for documents. */
protected byte[][] tnums = new byte[256][];
+
+ /** Total bytes (sum of term lengths) for all indexed terms.*/
protected long sizeOfIndexedStrings;
+
+ /** Holds the indexed (by default every 128th) terms. */
protected BytesRef[] indexedTermsArray;
+
+ /** If non-null, only terms matching this prefix were
+ * indexed. */
protected BytesRef prefix;
+
+ /** Ordinal of the first term in the field, or 0 if the
+ * {@link PostingsFormat} does not implement {@link
+ * TermsEnum#ord}. */
protected int ordBase;
- protected DocsEnum docsEnum; //used while uninverting
+ /** Used while uninverting. */
+ protected DocsEnum docsEnum;
+ /** Returns total bytes used. */
public long ramUsedInBytes() {
// can cache the mem size since it shouldn't change
if (memsz!=0) return memsz;
@@ -214,14 +240,14 @@ public class DocTermOrds {
}
/**
- * @return The number of terms in this field
+ * Returns the number of terms in this field
*/
public int numTerms() {
return numTermsInField;
}
/**
- * @return Whether this <code>DocTermOrds</code> instance is empty.
+ * Returns {@code true} if no terms were indexed.
*/
public boolean isEmpty() {
return index == null;
@@ -231,10 +257,13 @@ public class DocTermOrds {
protected void visitTerm(TermsEnum te, int termNum) throws IOException {
}
+ /** Invoked during {@link #uninvert(AtomicReader,BytesRef)}
+ * to record the document frequency for each uninverted
+ * term. */
protected void setActualDocFreq(int termNum, int df) throws IOException {
}
- // Call this only once (if you subclass!)
+ /** Call this only once (if you subclass!) */
protected void uninvert(final AtomicReader reader, final BytesRef termPrefix) throws IOException {
//System.out.println("DTO uninvert field=" + field + " prefix=" + termPrefix);
final long startTime = System.currentTimeMillis();
@@ -567,11 +596,15 @@ public class DocTermOrds {
return pos;
}
+ /** Iterates over the ords for a single document. */
public class TermOrdsIterator {
private int tnum;
private int upto;
private byte[] arr;
+ TermOrdsIterator() {
+ }
+
/** Buffer must be at least 5 ints long. Returns number
* of term ords placed into buffer; if this count is
* less than buffer.length then that is the end. */
@@ -617,6 +650,7 @@ public class DocTermOrds {
return bufferUpto;
}
+ /** Reset the iterator on a new document. */
public TermOrdsIterator reset(int docID) {
//System.out.println(" reset docID=" + docID);
tnum = 0;
@@ -807,6 +841,8 @@ public class DocTermOrds {
}
}
+ /** Returns the term ({@link BytesRef}) corresponding to
+ * the provided ordinal. */
public BytesRef lookupTerm(TermsEnum termsEnum, int ord) throws IOException {
termsEnum.seekExact(ord);
return termsEnum.term();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocValues.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocValues.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocValues.java Fri Sep 21 17:21:34 2012
@@ -78,11 +78,17 @@ import org.apache.lucene.util.packed.Pac
*/
public abstract class DocValues implements Closeable {
+ /** Zero length DocValues array. */
public static final DocValues[] EMPTY_ARRAY = new DocValues[0];
private volatile SourceCache cache = new SourceCache.DirectSourceCache();
private final Object cacheLock = new Object();
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected DocValues() {
+ }
+
/**
* Loads a new {@link Source} instance for this {@link DocValues} field
* instance. Source instances returned from this method are not cached. It is
@@ -173,9 +179,12 @@ public abstract class DocValues implemen
* @see DocValues#getDirectSource()
*/
public static abstract class Source {
-
+
+ /** {@link Type} of this {@code Source}. */
protected final Type type;
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
protected Source(Type type) {
this.type = type;
}
@@ -261,6 +270,8 @@ public abstract class DocValues implemen
private final Comparator<BytesRef> comparator;
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
protected SortedSource(Type type, Comparator<BytesRef> comparator) {
super(type);
this.comparator = comparator;
@@ -685,6 +696,11 @@ public abstract class DocValues implemen
*/
public static abstract class SourceCache {
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected SourceCache() {
+ }
+
/**
* Atomically loads a {@link Source} into the cache from the given
* {@link DocValues} and returns it iff no other {@link Source} has already
@@ -717,6 +733,10 @@ public abstract class DocValues implemen
public static final class DirectSourceCache extends SourceCache {
private Source ref;
+ /** Sole constructor. */
+ public DirectSourceCache() {
+ }
+
public synchronized Source load(DocValues values) throws IOException {
if (ref == null) {
ref = values.load();
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java Fri Sep 21 17:21:34 2012
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
import java.io.IOException;
+import org.apache.lucene.util.Bits; // javadocs
import org.apache.lucene.util.BytesRef;
/** Also iterates through positions. */
@@ -30,7 +31,12 @@ public abstract class DocsAndPositionsEn
/** Flag to pass to {@link TermsEnum#docsAndPositions(Bits,DocsAndPositionsEnum,int)}
* if you require payloads in the returned enum. */
public static final int FLAG_PAYLOADS = 0x2;
-
+
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected DocsAndPositionsEnum() {
+ }
+
/** Returns the next position. You should only call this
* up to {@link DocsEnum#freq()} times else
* the behavior is not defined. If positions were not
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocsEnum.java Fri Sep 21 17:21:34 2012
@@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.Bits; // javadocs
/** Iterates through the documents and term freqs.
* NOTE: you must first call {@link #nextDoc} before using
@@ -33,6 +34,11 @@ public abstract class DocsEnum extends D
private AttributeSource atts = null;
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected DocsEnum() {
+ }
+
/** Returns term frequency in the current document. Do
* not call this before {@link #nextDoc} is first called,
* nor after {@link #nextDoc} returns NO_MORE_DOCS.
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java Fri Sep 21 17:21:34 2012
@@ -321,7 +321,7 @@ final class DocumentsWriter {
return maybeMerge;
}
- boolean updateDocuments(final Iterable<? extends Iterable<? extends IndexableField>> docs, final Analyzer analyzer,
+ boolean updateDocuments(final Iterable<? extends IndexDocument> docs, final Analyzer analyzer,
final Term delTerm) throws IOException {
boolean maybeMerge = preUpdate();
@@ -352,7 +352,7 @@ final class DocumentsWriter {
return postUpdate(flushingDWPT, maybeMerge);
}
- boolean updateDocument(final Iterable<? extends IndexableField> doc, final Analyzer analyzer,
+ boolean updateDocument(final IndexDocument doc, final Analyzer analyzer,
final Term delTerm) throws IOException {
boolean maybeMerge = preUpdate();
@@ -365,7 +365,7 @@ final class DocumentsWriter {
if (!perThread.isActive()) {
ensureOpen();
- assert false: "perThread is not active but we are still open";
+ throw new IllegalStateException("perThread is not active but we are still open");
}
final DocumentsWriterPerThread dwpt = perThread.dwpt;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterDeleteQueue.java Fri Sep 21 17:21:34 2012
@@ -324,7 +324,7 @@ final class DocumentsWriterDeleteQueue {
.newUpdater(Node.class, Node.class, "next");
void apply(BufferedDeletes bufferedDeletes, int docIDUpto) {
- assert false : "sentinel item must never be applied";
+ throw new IllegalStateException("sentinel item must never be applied");
}
boolean casNext(Node<?> cmp, Node<?> val) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterFlushControl.java Fri Sep 21 17:21:34 2012
@@ -396,11 +396,11 @@ final class DocumentsWriterFlushControl
return flushingWriters.size();
}
- public boolean doApplyAllDeletes() {
+ public boolean doApplyAllDeletes() {
return flushDeletes.getAndSet(false);
}
- public void setApplyAllDeletes() {
+ public void setApplyAllDeletes() {
flushDeletes.set(true);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java Fri Sep 21 17:21:34 2012
@@ -94,7 +94,7 @@ class DocumentsWriterPerThread {
InfoStream infoStream;
Similarity similarity;
int docID;
- Iterable<? extends IndexableField> doc;
+ IndexDocument doc;
String maxTermPrefix;
DocState(DocumentsWriterPerThread docWriter, InfoStream infoStream) {
@@ -225,7 +225,7 @@ class DocumentsWriterPerThread {
return retval;
}
- public void updateDocument(Iterable<? extends IndexableField> doc, Analyzer analyzer, Term delTerm) throws IOException {
+ public void updateDocument(IndexDocument doc, Analyzer analyzer, Term delTerm) throws IOException {
assert writer.testPoint("DocumentsWriterPerThread addDocument start");
assert deleteQueue != null;
docState.doc = doc;
@@ -278,7 +278,7 @@ class DocumentsWriterPerThread {
}
}
- public int updateDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer analyzer, Term delTerm) throws IOException {
+ public int updateDocuments(Iterable<? extends IndexDocument> docs, Analyzer analyzer, Term delTerm) throws IOException {
assert writer.testPoint("DocumentsWriterPerThread addDocuments start");
assert deleteQueue != null;
docState.analyzer = analyzer;
@@ -290,7 +290,7 @@ class DocumentsWriterPerThread {
}
int docCount = 0;
try {
- for(Iterable<? extends IndexableField> doc : docs) {
+ for(IndexDocument doc : docs) {
docState.doc = doc;
docState.docID = numDocsInRAM;
docCount++;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java Fri Sep 21 17:21:34 2012
@@ -23,15 +23,17 @@ import java.util.Map;
import org.apache.lucene.index.DocValues.Type;
/**
- * Access to the Fieldable Info file that describes document fields and whether or
- * not they are indexed. Each segment has a separate Fieldable Info file. Objects
+ * Access to the Field Info file that describes document fields and whether or
+ * not they are indexed. Each segment has a separate Field Info file. Objects
* of this class are thread-safe for multiple readers, but only one thread can
* be adding documents at a time, with no other reader or writer threads
* accessing this object.
**/
public final class FieldInfo {
+ /** Field's name */
public final String name;
+ /** Internal field number */
public final int number;
private boolean indexed;
@@ -55,18 +57,35 @@ public final class FieldInfo {
// NOTE: order is important here; FieldInfo uses this
// order to merge two conflicting IndexOptions (always
// "downgrades" by picking the lowest).
- /** only documents are indexed: term frequencies and positions are omitted */
+ /**
+ * Only documents are indexed: term frequencies and positions are omitted.
+ * Phrase and other positional queries on the field will throw an exception, and scoring
+ * will behave as if any term in the document appears only once.
+ */
// TODO: maybe rename to just DOCS?
DOCS_ONLY,
- /** only documents and term frequencies are indexed: positions are omitted */
+ /**
+ * Only documents and term frequencies are indexed: positions are omitted.
+ * This enables normal scoring, except Phrase and other positional queries
+ * will throw an exception.
+ */
DOCS_AND_FREQS,
- /** documents, frequencies and positions */
+ /**
+ * Indexes documents, frequencies and positions.
+ * This is a typical default for full-text search: full scoring is enabled
+ * and positional queries are supported.
+ */
DOCS_AND_FREQS_AND_POSITIONS,
- /** documents, frequencies, positions and offsets */
+ /**
+ * Indexes documents, frequencies, positions and offsets.
+ * Character offsets are encoded alongside the positions.
+ */
DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS,
};
/**
+ * Sole Constructor.
+ *
* @lucene.experimental
*/
public FieldInfo(String name, boolean indexed, int number, boolean storeTermVector,
@@ -149,27 +168,27 @@ public final class FieldInfo {
assert checkConsistency();
}
- /** @return IndexOptions for the field, or null if the field is not indexed */
+ /** Returns IndexOptions for the field, or null if the field is not indexed */
public IndexOptions getIndexOptions() {
return indexOptions;
}
/**
- * @return true if this field has any docValues.
+ * Returns true if this field has any docValues.
*/
public boolean hasDocValues() {
return docValueType != null;
}
/**
- * @return {@link DocValues.Type} of the docValues. this may be null if the field has no docvalues.
+ * Returns {@link DocValues.Type} of the docValues. this may be null if the field has no docvalues.
*/
public DocValues.Type getDocValuesType() {
return docValueType;
}
/**
- * @return {@link DocValues.Type} of the norm. this may be null if the field has no norms.
+ * Returns {@link DocValues.Type} of the norm. this may be null if the field has no norms.
*/
public DocValues.Type getNormType() {
return normType;
@@ -193,35 +212,35 @@ public final class FieldInfo {
}
/**
- * @return true if norms are explicitly omitted for this field
+ * Returns true if norms are explicitly omitted for this field
*/
public boolean omitsNorms() {
return omitNorms;
}
/**
- * @return true if this field actually has any norms.
+ * Returns true if this field actually has any norms.
*/
public boolean hasNorms() {
return normType != null;
}
/**
- * @return true if this field is indexed.
+ * Returns true if this field is indexed.
*/
public boolean isIndexed() {
return indexed;
}
/**
- * @return true if any payloads exist for this field.
+ * Returns true if any payloads exist for this field.
*/
public boolean hasPayloads() {
return storePayloads;
}
/**
- * @return true if any term vectors exist for this field.
+ * Returns true if any term vectors exist for this field.
*/
public boolean hasVectors() {
return storeTermVector;
@@ -256,7 +275,7 @@ public final class FieldInfo {
}
/**
- * @return internal codec attributes map. May be null if no mappings exist.
+ * Returns internal codec attributes map. May be null if no mappings exist.
*/
public Map<String,String> attributes() {
return attributes;
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java Fri Sep 21 17:21:34 2012
@@ -34,6 +34,8 @@ import org.apache.lucene.index.FieldInfo
public class FieldInfos implements Iterable<FieldInfo> {
private final boolean hasFreq;
private final boolean hasProx;
+ private final boolean hasPayloads;
+ private final boolean hasOffsets;
private final boolean hasVectors;
private final boolean hasNorms;
private final boolean hasDocValues;
@@ -42,28 +44,41 @@ public class FieldInfos implements Itera
private final HashMap<String,FieldInfo> byName = new HashMap<String,FieldInfo>();
private final Collection<FieldInfo> values; // for an unmodifiable iterator
+ /**
+ * Constructs a new FieldInfos from an array of FieldInfo objects
+ */
public FieldInfos(FieldInfo[] infos) {
boolean hasVectors = false;
boolean hasProx = false;
+ boolean hasPayloads = false;
+ boolean hasOffsets = false;
boolean hasFreq = false;
boolean hasNorms = false;
boolean hasDocValues = false;
for (FieldInfo info : infos) {
- assert !byNumber.containsKey(info.number);
- byNumber.put(info.number, info);
- assert !byName.containsKey(info.name);
- byName.put(info.name, info);
+ FieldInfo previous = byNumber.put(info.number, info);
+ if (previous != null) {
+ throw new IllegalArgumentException("duplicate field numbers: " + previous.name + " and " + info.name + " have: " + info.number);
+ }
+ previous = byName.put(info.name, info);
+ if (previous != null) {
+ throw new IllegalArgumentException("duplicate field names: " + previous.number + " and " + info.number + " have: " + info.name);
+ }
hasVectors |= info.hasVectors();
hasProx |= info.isIndexed() && info.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
hasFreq |= info.isIndexed() && info.getIndexOptions() != IndexOptions.DOCS_ONLY;
+ hasOffsets |= info.isIndexed() && info.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
hasNorms |= info.hasNorms();
hasDocValues |= info.hasDocValues();
+ hasPayloads |= info.hasPayloads();
}
this.hasVectors = hasVectors;
this.hasProx = hasProx;
+ this.hasPayloads = hasPayloads;
+ this.hasOffsets = hasOffsets;
this.hasFreq = hasFreq;
this.hasNorms = hasNorms;
this.hasDocValues = hasDocValues;
@@ -79,31 +94,33 @@ public class FieldInfos implements Itera
public boolean hasProx() {
return hasProx;
}
+
+ /** Returns true if any fields have payloads */
+ public boolean hasPayloads() {
+ return hasPayloads;
+ }
+
+ /** Returns true if any fields have offsets */
+ public boolean hasOffsets() {
+ return hasOffsets;
+ }
- /**
- * @return true if at least one field has any vectors
- */
+ /** Returns true if any fields have vectors */
public boolean hasVectors() {
return hasVectors;
}
- /**
- * @return true if at least one field has any norms
- */
+ /** Returns true if any fields have norms */
public boolean hasNorms() {
return hasNorms;
}
- /**
- * @return true if at least one field has doc values
- */
+ /** Returns true if any fields have DocValues */
public boolean hasDocValues() {
return hasDocValues;
}
- /**
- * @return number of fields
- */
+ /** Returns the number of fields */
public int size() {
assert byNumber.size() == byName.size();
return byNumber.size();
@@ -249,11 +266,11 @@ public class FieldInfos implements Itera
return addOrUpdateInternal(name, -1, isIndexed, storeTermVector, omitNorms, storePayloads, indexOptions, docValues, normType);
}
- // NOTE: this method does not carry over termVector
- // booleans nor docValuesType; the indexer chain
- // (TermVectorsConsumerPerField, DocFieldProcessor) must
- // set these fields when they succeed in consuming
- // the document:
+ /** NOTE: this method does not carry over termVector
+ * booleans nor docValuesType; the indexer chain
+ * (TermVectorsConsumerPerField, DocFieldProcessor) must
+ * set these fields when they succeed in consuming
+ * the document */
public FieldInfo addOrUpdate(String name, IndexableFieldType fieldType) {
// TODO: really, indexer shouldn't even call this
// method (it's only called from DocFieldProcessor);
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FieldInvertState.java Fri Sep 21 17:21:34 2012
@@ -16,6 +16,7 @@
*/
package org.apache.lucene.index;
+import org.apache.lucene.analysis.TokenStream; // javadocs
import org.apache.lucene.util.AttributeSource;
/**
@@ -36,10 +37,14 @@ public final class FieldInvertState {
float boost;
AttributeSource attributeSource;
+ /** Creates {code FieldInvertState} for the specified
+ * field name. */
public FieldInvertState(String name) {
this.name = name;
}
+ /** Creates {code FieldInvertState} for the specified
+ * field name and values for all fields. */
public FieldInvertState(String name, int position, int length, int numOverlap, int offset, float boost) {
this.name = name;
this.position = position;
@@ -79,6 +84,7 @@ public final class FieldInvertState {
return length;
}
+ /** Set length value. */
public void setLength(int length) {
this.length = length;
}
@@ -91,6 +97,8 @@ public final class FieldInvertState {
return numOverlap;
}
+ /** Set number of terms with {@code positionIncrement ==
+ * 0}. */
public void setNumOverlap(int numOverlap) {
this.numOverlap = numOverlap;
}
@@ -112,7 +120,8 @@ public final class FieldInvertState {
public float getBoost() {
return boost;
}
-
+
+ /** Set boost value. */
public void setBoost(float boost) {
this.boost = boost;
}
@@ -132,7 +141,10 @@ public final class FieldInvertState {
public int getUniqueTermCount() {
return uniqueTermCount;
}
-
+
+ /** Returns the {@link AttributeSource} from the {@link
+ * TokenStream} that provided the indexed tokens for this
+ * field. */
public AttributeSource getAttributeSource() {
return attributeSource;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/Fields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/Fields.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/Fields.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/Fields.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,11 @@ import java.util.Iterator;
public abstract class Fields implements Iterable<String> {
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected Fields() {
+ }
+
/** Returns an iterator that will step through all fields
* names. This will not return null. */
public abstract Iterator<String> iterator();
@@ -33,32 +38,11 @@ public abstract class Fields implements
* null if the field does not exist. */
public abstract Terms terms(String field) throws IOException;
- /** Returns the number of terms for all fields, or -1 if this
- * measure isn't stored by the codec. Note that, just like
- * other term measures, this measure does not take deleted
- * documents into account. */
- public abstract int size() throws IOException;
-
- /** Returns the number of terms for all fields, or -1 if this
- * measure isn't stored by the codec. Note that, just like
- * other term measures, this measure does not take deleted
- * documents into account. */
- // TODO: deprecate?
- public long getUniqueTermCount() throws IOException {
- long numTerms = 0;
- for (String field : this) {
- Terms terms = terms(field);
- if (terms != null) {
- final long termCount = terms.size();
- if (termCount == -1) {
- return -1;
- }
-
- numTerms += termCount;
- }
- }
- return numTerms;
- }
+ /** Returns the number of fields or -1 if the number of
+ * distinct field names is unknown. If >= 0,
+ * {@link #iterator} will return as many field names. */
+ public abstract int size();
+ /** Zero-length {@code Fields} array. */
public final static Fields[] EMPTY_ARRAY = new Fields[0];
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java Fri Sep 21 17:21:34 2012
@@ -40,8 +40,13 @@ public class FilterAtomicReader extends
/** Base class for filtering {@link Fields}
* implementations. */
public static class FilterFields extends Fields {
+ /** The underlying Fields instance. */
protected final Fields in;
+ /**
+ * Creates a new FilterFields.
+ * @param in the underlying Fields instance.
+ */
public FilterFields(Fields in) {
this.in = in;
}
@@ -57,21 +62,21 @@ public class FilterAtomicReader extends
}
@Override
- public int size() throws IOException {
+ public int size() {
return in.size();
}
-
- @Override
- public long getUniqueTermCount() throws IOException {
- return in.getUniqueTermCount();
- }
}
/** Base class for filtering {@link Terms}
* implementations. */
public static class FilterTerms extends Terms {
+ /** The underlying Terms instance. */
protected final Terms in;
+ /**
+ * Creates a new FilterTerms
+ * @param in the underlying Terms instance.
+ */
public FilterTerms(Terms in) {
this.in = in;
}
@@ -129,8 +134,13 @@ public class FilterAtomicReader extends
/** Base class for filtering {@link TermsEnum} implementations. */
public static class FilterTermsEnum extends TermsEnum {
+ /** The underlying TermsEnum instance. */
protected final TermsEnum in;
+ /**
+ * Creates a new FilterTermsEnum
+ * @param in the underlying TermsEnum instance.
+ */
public FilterTermsEnum(TermsEnum in) { this.in = in; }
@Override
@@ -206,8 +216,13 @@ public class FilterAtomicReader extends
/** Base class for filtering {@link DocsEnum} implementations. */
public static class FilterDocsEnum extends DocsEnum {
+ /** The underlying DocsEnum instance. */
protected final DocsEnum in;
+ /**
+ * Create a new FilterDocsEnum
+ * @param in the underlying DocsEnum instance.
+ */
public FilterDocsEnum(DocsEnum in) {
this.in = in;
}
@@ -240,8 +255,13 @@ public class FilterAtomicReader extends
/** Base class for filtering {@link DocsAndPositionsEnum} implementations. */
public static class FilterDocsAndPositionsEnum extends DocsAndPositionsEnum {
+ /** The underlying DocsAndPositionsEnum instance. */
protected final DocsAndPositionsEnum in;
+ /**
+ * Create a new FilterDocsAndPositionsEnum
+ * @param in the underlying DocsAndPositionsEnum instance.
+ */
public FilterDocsAndPositionsEnum(DocsAndPositionsEnum in) {
this.in = in;
}
@@ -292,6 +312,7 @@ public class FilterAtomicReader extends
}
}
+ /** The underlying AtomicReader. */
protected final AtomicReader in;
/**
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FilteredTermsEnum.java Fri Sep 21 17:21:34 2012
@@ -48,7 +48,20 @@ public abstract class FilteredTermsEnum
* the enum should call {@link #nextSeekTerm} and step forward.
* @see #accept(BytesRef)
*/
- protected static enum AcceptStatus {YES, YES_AND_SEEK, NO, NO_AND_SEEK, END};
+ protected static enum AcceptStatus {
+ /** Accept the term and position the enum at the next term. */
+ YES,
+ /** Accept the term and advance ({@link FilteredTermsEnum#nextSeekTerm(BytesRef)})
+ * to the next term. */
+ YES_AND_SEEK,
+ /** Reject the term and position the enum at the next term. */
+ NO,
+ /** Reject the term and advance ({@link FilteredTermsEnum#nextSeekTerm(BytesRef)})
+ * to the next term. */
+ NO_AND_SEEK,
+ /** Reject the term and stop enumerating. */
+ END
+ };
/** Return if term is accepted, not accepted or the iteration should ended
* (and possibly seek).
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java Fri Sep 21 17:21:34 2012
@@ -103,12 +103,7 @@ final class FreqProxTermsWriterPerField
@Override
boolean start(IndexableField[] fields, int count) {
- for(int i=0;i<count;i++) {
- if (fields[i].fieldType().indexed()) {
- return true;
- }
- }
- return false;
+ return true;
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexCommit.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexCommit.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexCommit.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexCommit.java Fri Sep 21 17:21:34 2012
@@ -73,11 +73,19 @@ public abstract class IndexCommit implem
*/
public abstract void delete();
+ /** Returns true if this commit should be deleted; this is
+ * only used by {@link IndexWriter} after invoking the
+ * {@link IndexDeletionPolicy}. */
public abstract boolean isDeleted();
/** Returns number of segments referenced by this commit. */
public abstract int getSegmentCount();
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected IndexCommit() {
+ }
+
/** Two IndexCommits are equal if both their Directory and versions are equal. */
@Override
public boolean equals(Object other) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java Fri Sep 21 17:21:34 2012
@@ -571,7 +571,7 @@ final class IndexFileDeleter {
infoStream.message("IFD", "delete \"" + fileName + "\"");
}
directory.deleteFile(fileName);
- } catch (IOException e) { // if delete fails
+ } catch (IOException e) { // if delete fails
if (directory.fileExists(fileName)) {
// Some operating systems (e.g. Windows) don't
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java Fri Sep 21 17:21:34 2012
@@ -40,6 +40,9 @@ import org.apache.lucene.codecs.Codec;
*/
public final class IndexFileNames {
+
+ /** No instance */
+ private IndexFileNames() {}
/** Name of the index segment file */
public static final String SEGMENTS = "segments";
@@ -184,6 +187,10 @@ public final class IndexFileNames {
return filename;
}
+ /**
+ * Removes the extension (anything after the first '.'),
+ * otherwise returns the original filename.
+ */
public static String stripExtension(String filename) {
int idx = filename.indexOf('.');
if (idx != -1) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooNewException.java Fri Sep 21 17:21:34 2012
@@ -25,14 +25,28 @@ import org.apache.lucene.store.DataInput
*/
public class IndexFormatTooNewException extends CorruptIndexException {
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooNewException}
+ *
+ * @param resourceDesc describes the file that was too old
+ * @param version the version of the file that was too old
+ * @param minVersion the minimum version accepted
+ * @param maxVersion the maxium version accepted
+ *
+ * @lucene.internal */
public IndexFormatTooNewException(String resourceDesc, int version, int minVersion, int maxVersion) {
super("Format version is not supported (resource: " + resourceDesc + "): "
+ version + " (needs to be between " + minVersion + " and " + maxVersion + ")");
assert resourceDesc != null;
}
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooNewException}
+ *
+ * @param in the open file that's too old
+ * @param version the version of the file that was too old
+ * @param minVersion the minimum version accepted
+ * @param maxVersion the maxium version accepted
+ *
+ * @lucene.internal */
public IndexFormatTooNewException(DataInput in, int version, int minVersion, int maxVersion) {
this(in.toString(), version, minVersion, maxVersion);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexFormatTooOldException.java Fri Sep 21 17:21:34 2012
@@ -25,19 +25,36 @@ import org.apache.lucene.store.DataInput
*/
public class IndexFormatTooOldException extends CorruptIndexException {
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooOldException}.
+ *
+ * @param resourceDesc describes the file that was too old
+ * @param version the version of the file that was too old
+ *
+ * @lucene.internal */
public IndexFormatTooOldException(String resourceDesc, String version) {
super("Format version is not supported (resource: " + resourceDesc + "): " +
version + ". This version of Lucene only supports indexes created with release 4.0 and later.");
assert resourceDesc != null;
}
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooOldException}.
+ *
+ * @param in the open file that's too old
+ * @param version the version of the file that was too old
+ *
+ * @lucene.internal */
public IndexFormatTooOldException(DataInput in, String version) {
this(in.toString(), version);
}
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooOldException}.
+ *
+ * @param resourceDesc describes the file that was too old
+ * @param version the version of the file that was too old
+ * @param minVersion the minimum version accepted
+ * @param maxVersion the maxium version accepted
+ *
+ * @lucene.internal */
public IndexFormatTooOldException(String resourceDesc, int version, int minVersion, int maxVersion) {
super("Format version is not supported (resource: " + resourceDesc + "): " +
version + " (needs to be between " + minVersion + " and " + maxVersion +
@@ -45,7 +62,14 @@ public class IndexFormatTooOldException
assert resourceDesc != null;
}
- /** @lucene.internal */
+ /** Creates an {@code IndexFormatTooOldException}.
+ *
+ * @param in the open file that's too old
+ * @param version the version of the file that was too old
+ * @param minVersion the minimum version accepted
+ * @param maxVersion the maxium version accepted
+ *
+ * @lucene.internal */
public IndexFormatTooOldException(DataInput in, int version, int minVersion, int maxVersion) {
this(in.toString(), version, minVersion, maxVersion);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexNotFoundException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexNotFoundException.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexNotFoundException.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexNotFoundException.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,8 @@ import java.io.FileNotFoundException;
*/
public final class IndexNotFoundException extends FileNotFoundException {
+ /** Creates IndexFileNotFoundException with the
+ * description message. */
public IndexNotFoundException(String msg) {
super(msg);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReader.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReader.java Fri Sep 21 17:21:34 2012
@@ -21,6 +21,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.WeakHashMap;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -30,7 +31,6 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.search.SearcherManager; // javadocs
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
/** IndexReader is an abstract class, providing an interface for accessing an
index. Search of an index is done entirely through this abstract interface,
@@ -88,6 +88,7 @@ public abstract class IndexReader implem
* @lucene.experimental
*/
public static interface ReaderClosedListener {
+ /** Invoked when the {@link IndexReader} is closed. */
public void onClose(IndexReader reader);
}
@@ -242,7 +243,8 @@ public abstract class IndexReader implem
}
/**
- * @throws AlreadyClosedException if this IndexReader is closed
+ * Throws AlreadyClosedException if this IndexReader or any
+ * of its child readers is closed, otherwise returns.
*/
protected final void ensureOpen() throws AlreadyClosedException {
if (refCount.get() <= 0) {
@@ -340,7 +342,7 @@ public abstract class IndexReader implem
// TODO: we need a separate StoredField, so that the
// Document returned here contains that class not
// IndexableField
- public final Document document(int docID) throws IOException {
+ public final StoredDocument document(int docID) throws IOException {
final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor();
document(docID, visitor);
return visitor.getDocument();
@@ -351,8 +353,10 @@ public abstract class IndexReader implem
* fields. Note that this is simply sugar for {@link
* DocumentStoredFieldVisitor#DocumentStoredFieldVisitor(Set)}.
*/
- public final Document document(int docID, Set<String> fieldsToLoad) throws IOException {
- final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(fieldsToLoad);
+ public final StoredDocument document(int docID, Set<String> fieldsToLoad)
+ throws IOException {
+ final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(
+ fieldsToLoad);
document(docID, visitor);
return visitor.getDocument();
}
@@ -377,9 +381,11 @@ public abstract class IndexReader implem
protected abstract void doClose() throws IOException;
/**
- * Expert: Returns a the root {@link IndexReaderContext} for this
- * {@link IndexReader}'s sub-reader tree. Iff this reader is composed of sub
- * readers ,ie. this reader being a composite reader, this method returns a
+ * Expert: Returns the root {@link IndexReaderContext} for this
+ * {@link IndexReader}'s sub-reader tree.
+ * <p>
+ * Iff this reader is composed of sub
+ * readers, i.e. this reader being a composite reader, this method returns a
* {@link CompositeReaderContext} holding the reader's direct children as well as a
* view of the reader tree's atomic leaf contexts. All sub-
* {@link IndexReaderContext} instances referenced from this readers top-level
@@ -388,14 +394,21 @@ public abstract class IndexReader implem
* atomic leaf reader at a time. If this reader is not composed of child
* readers, this method returns an {@link AtomicReaderContext}.
* <p>
- * Note: Any of the sub-{@link CompositeReaderContext} instances reference from this
- * top-level context holds a <code>null</code> {@link CompositeReaderContext#leaves()}
- * reference. Only the top-level context maintains the convenience leaf-view
+ * Note: Any of the sub-{@link CompositeReaderContext} instances referenced
+ * from this top-level context do not support {@link CompositeReaderContext#leaves()}.
+ * Only the top-level context maintains the convenience leaf-view
* for performance reasons.
- *
- * @lucene.experimental
*/
- public abstract IndexReaderContext getTopReaderContext();
+ public abstract IndexReaderContext getContext();
+
+ /**
+ * Returns the reader's leaves, or itself if this reader is atomic.
+ * This is a convenience method calling {@code this.getContext().leaves()}.
+ * @see IndexReaderContext#leaves()
+ */
+ public final List<AtomicReaderContext> leaves() {
+ return getContext().leaves();
+ }
/** Expert: Returns a key for this IndexReader, so FieldCache/CachingWrapperFilter can find
* it again.
@@ -419,15 +432,17 @@ public abstract class IndexReader implem
* <code>term</code>. This method returns 0 if the term or
* field does not exists. This method does not take into
* account deleted documents that have not yet been merged
- * away. */
- public final int docFreq(Term term) throws IOException {
- return docFreq(term.field(), term.bytes());
- }
-
- /** Returns the number of documents containing the
+ * away.
+ * @see TermsEnum#docFreq()
+ */
+ public abstract int docFreq(Term term) throws IOException;
+
+ /** Returns the number of documents containing the term
* <code>term</code>. This method returns 0 if the term or
- * field does not exists. This method does not take into
- * account deleted documents that have not yet been merged
- * away. */
- public abstract int docFreq(String field, BytesRef term) throws IOException;
+ * field does not exists, or -1 if the Codec does not support
+ * the measure. This method does not take into account deleted
+ * documents that have not yet been merged away.
+ * @see TermsEnum#totalTermFreq()
+ */
+ public abstract long totalTermFreq(Term term) throws IOException;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexReaderContext.java Fri Sep 21 17:21:34 2012
@@ -22,7 +22,6 @@ import java.util.List;
/**
* A struct like class that represents a hierarchical relationship between
* {@link IndexReader} instances.
- * @lucene.experimental
*/
public abstract class IndexReaderContext {
/** The reader context for this reader's immediate parent, or null if none */
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java Fri Sep 21 17:21:34 2012
@@ -67,6 +67,8 @@ public final class IndexUpgrader {
System.exit(1);
}
+ /** Main method to run {code IndexUpgrader} from the
+ * command-line. */
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
String path = null;
@@ -132,7 +134,8 @@ public final class IndexUpgrader {
this.iwc = iwc;
this.deletePriorCommits = deletePriorCommits;
}
-
+
+ /** Perform the upgrade. */
public void upgrade() throws IOException {
if (!DirectoryReader.indexExists(dir)) {
throw new IndexNotFoundException(dir.toString());
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java Fri Sep 21 17:21:34 2012
@@ -69,10 +69,10 @@ import org.apache.lucene.util.ThreadInte
new index if there is not already an index at the provided path
and otherwise open the existing index.</p>
- <p>In either case, documents are added with {@link #addDocument(Iterable)
+ <p>In either case, documents are added with {@link #addDocument(IndexDocument)
addDocument} and removed with {@link #deleteDocuments(Term)} or {@link
#deleteDocuments(Query)}. A document can be updated with {@link
- #updateDocument(Term, Iterable) updateDocument} (which just deletes
+ #updateDocument(Term, IndexDocument) updateDocument} (which just deletes
and then adds the entire document). When finished adding, deleting
and updating documents, {@link #close() close} should be called.</p>
@@ -260,9 +260,6 @@ public class IndexWriter implements Clos
// to allow users to query an IndexWriter settings.
private final LiveIndexWriterConfig config;
- // The PayloadProcessorProvider to use when segments are merged
- private PayloadProcessorProvider payloadProcessorProvider;
-
DirectoryReader getReader() throws IOException {
return getReader(true);
}
@@ -552,6 +549,14 @@ public class IndexWriter implements Clos
}
}
+ /**
+ * Used internally to throw an {@link
+ * AlreadyClosedException} if this IndexWriter has been
+ * closed.
+ * <p>
+ * Calls {@link #ensureOpen(boolean) ensureOpen(true)}.
+ * @throws AlreadyClosedException if this IndexWriter is closed
+ */
protected final void ensureOpen() throws AlreadyClosedException {
ensureOpen(true);
}
@@ -763,8 +768,15 @@ public class IndexWriter implements Clos
}
/**
- * Commits all changes to an index and closes all
- * associated files. Note that this may be a costly
+ * Commits all changes to an index, waits for pending merges
+ * to complete, and closes all associated files.
+ * <p>
+ * This is a "slow graceful shutdown" which may take a long time
+ * especially if a big merge is pending: If you only want to close
+ * resources use {@link #rollback()}. If you only want to commit
+ * pending changes and close resources see {@link #close(boolean)}.
+ * <p>
+ * Note that this may be a costly
* operation, so, try to re-use a single writer instead of
* closing and opening a new one. See {@link #commit()} for
* caveats about write caching done by some IO devices.
@@ -784,7 +796,7 @@ public class IndexWriter implements Clos
* docs in the IndexWriter instance) then you can do
* something like this:</p>
*
- * <pre>
+ * <pre class="prettyprint">
* try {
* writer.close();
* } finally {
@@ -1026,6 +1038,9 @@ public class IndexWriter implements Clos
return count;
}
+ /**
+ * Returns true if this index has deletions (including buffered deletions).
+ */
public synchronized boolean hasDeletions() {
ensureOpen();
if (bufferedDeletesStream.any()) {
@@ -1084,7 +1099,7 @@ public class IndexWriter implements Clos
* @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error
*/
- public void addDocument(Iterable<? extends IndexableField> doc) throws IOException {
+ public void addDocument(IndexDocument doc) throws IOException {
addDocument(doc, analyzer);
}
@@ -1092,7 +1107,7 @@ public class IndexWriter implements Clos
* Adds a document to this index, using the provided analyzer instead of the
* value of {@link #getAnalyzer()}.
*
- * <p>See {@link #addDocument(Iterable)} for details on
+ * <p>See {@link #addDocument(IndexDocument)} for details on
* index and IndexWriter state after an Exception, and
* flushing/merging temporary free space requirements.</p>
*
@@ -1103,7 +1118,7 @@ public class IndexWriter implements Clos
* @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error
*/
- public void addDocument(Iterable<? extends IndexableField> doc, Analyzer analyzer) throws IOException {
+ public void addDocument(IndexDocument doc, Analyzer analyzer) throws IOException {
updateDocument(null, doc, analyzer);
}
@@ -1128,7 +1143,7 @@ public class IndexWriter implements Clos
* perhaps to obtain better index compression), in which case
* you may need to fully re-index your documents at that time.
*
- * <p>See {@link #addDocument(Iterable)} for details on
+ * <p>See {@link #addDocument(IndexDocument)} for details on
* index and IndexWriter state after an Exception, and
* flushing/merging temporary free space requirements.</p>
*
@@ -1148,7 +1163,7 @@ public class IndexWriter implements Clos
*
* @lucene.experimental
*/
- public void addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException {
+ public void addDocuments(Iterable<? extends IndexDocument> docs) throws IOException {
addDocuments(docs, analyzer);
}
@@ -1163,7 +1178,7 @@ public class IndexWriter implements Clos
*
* @lucene.experimental
*/
- public void addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer analyzer) throws IOException {
+ public void addDocuments(Iterable<? extends IndexDocument> docs, Analyzer analyzer) throws IOException {
updateDocuments(null, docs, analyzer);
}
@@ -1180,7 +1195,7 @@ public class IndexWriter implements Clos
*
* @lucene.experimental
*/
- public void updateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException {
+ public void updateDocuments(Term delTerm, Iterable<? extends IndexDocument> docs) throws IOException {
updateDocuments(delTerm, docs, analyzer);
}
@@ -1198,7 +1213,7 @@ public class IndexWriter implements Clos
*
* @lucene.experimental
*/
- public void updateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs, Analyzer analyzer) throws IOException {
+ public void updateDocuments(Term delTerm, Iterable<? extends IndexDocument> docs, Analyzer analyzer) throws IOException {
ensureOpen();
try {
boolean success = false;
@@ -1263,7 +1278,7 @@ public class IndexWriter implements Clos
reader = (AtomicReader) readerIn;
} else {
// Composite reader: lookup sub-reader and re-base docID:
- List<AtomicReaderContext> leaves = readerIn.getTopReaderContext().leaves();
+ List<AtomicReaderContext> leaves = readerIn.leaves();
int subIndex = ReaderUtil.subIndex(docID, leaves);
reader = leaves.get(subIndex).reader();
docID -= leaves.get(subIndex).docBase;
@@ -1395,7 +1410,7 @@ public class IndexWriter implements Clos
* @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error
*/
- public void updateDocument(Term term, Iterable<? extends IndexableField> doc) throws IOException {
+ public void updateDocument(Term term, IndexDocument doc) throws IOException {
ensureOpen();
updateDocument(term, doc, getAnalyzer());
}
@@ -1418,7 +1433,7 @@ public class IndexWriter implements Clos
* @throws CorruptIndexException if the index is corrupt
* @throws IOException if there is a low-level IO error
*/
- public void updateDocument(Term term, Iterable<? extends IndexableField> doc, Analyzer analyzer)
+ public void updateDocument(Term term, IndexDocument doc, Analyzer analyzer)
throws IOException {
ensureOpen();
try {
@@ -2197,7 +2212,7 @@ public class IndexWriter implements Clos
* {@link #prepareFlushedSegment(FlushedSegment)} to obtain the
* {@link SegmentInfo} for the flushed segment.
*
- * @see #prepareFlushedSegment(FlushedSegment)
+ * @see #prepareFlushedSegment(DocumentsWriterPerThread.FlushedSegment)
*/
synchronized void publishFlushedSegment(SegmentInfoPerCommit newSegment,
FrozenBufferedDeletes packet, FrozenBufferedDeletes globalPacket) throws IOException {
@@ -2399,8 +2414,7 @@ public class IndexWriter implements Clos
false, codec, null, null);
SegmentMerger merger = new SegmentMerger(info, infoStream, trackingDir, config.getTermIndexInterval(),
- MergeState.CheckAbort.NONE, payloadProcessorProvider,
- globalFieldNumberMap, context);
+ MergeState.CheckAbort.NONE, globalFieldNumberMap, context);
for (IndexReader reader : readers) { // add new indexes
merger.add(reader);
@@ -2833,7 +2847,7 @@ public class IndexWriter implements Clos
final boolean anySegmentFlushed;
synchronized (fullFlushLock) {
- boolean flushSuccess = false;
+ boolean flushSuccess = false;
try {
anySegmentFlushed = docWriter.flushAllThreads();
flushSuccess = true;
@@ -3503,7 +3517,7 @@ public class IndexWriter implements Clos
final TrackingDirectoryWrapper dirWrapper = new TrackingDirectoryWrapper(directory);
SegmentMerger merger = new SegmentMerger(merge.info.info, infoStream, dirWrapper, config.getTermIndexInterval(), checkAbort,
- payloadProcessorProvider, globalFieldNumberMap, context);
+ globalFieldNumberMap, context);
if (infoStream.isEnabled("IW")) {
infoStream.message("IW", "merging " + segString(merge.segments));
@@ -3751,12 +3765,18 @@ public class IndexWriter implements Clos
return segmentInfos.size() > 0 ? segmentInfos.info(segmentInfos.size()-1) : null;
}
- /** @lucene.internal */
+ /** Returns a string description of all segments, for
+ * debugging.
+ *
+ * @lucene.internal */
public synchronized String segString() {
return segString(segmentInfos);
}
- /** @lucene.internal */
+ /** Returns a string description of the specified
+ * segments, for debugging.
+ *
+ * @lucene.internal */
public synchronized String segString(Iterable<SegmentInfoPerCommit> infos) {
final StringBuilder buffer = new StringBuilder();
for(final SegmentInfoPerCommit info : infos) {
@@ -3768,7 +3788,10 @@ public class IndexWriter implements Clos
return buffer.toString();
}
- /** @lucene.internal */
+ /** Returns a string description of the specified
+ * segment, for debugging.
+ *
+ * @lucene.internal */
public synchronized String segString(SegmentInfoPerCommit info) {
return info.toString(info.info.dir, numDeletedDocs(info) - info.getDelCount());
}
@@ -3983,6 +4006,15 @@ public class IndexWriter implements Clos
* <p><b>NOTE</b>: warm is called before any deletes have
* been carried over to the merged segment. */
public static abstract class IndexReaderWarmer {
+
+ /** Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.) */
+ protected IndexReaderWarmer() {
+ }
+
+ /** Invoked on the {@link AtomicReader} for the newly
+ * merged segment, before that segment is made visible
+ * to near-real-time readers. */
public abstract void warm(AtomicReader reader) throws IOException;
}
@@ -4058,38 +4090,6 @@ public class IndexWriter implements Clos
synchronized void deletePendingFiles() throws IOException {
deleter.deletePendingFiles();
}
-
- /**
- * Sets the {@link PayloadProcessorProvider} to use when merging payloads.
- * Note that the given <code>pcp</code> will be invoked for every segment that
- * is merged, not only external ones that are given through
- * {@link #addIndexes}. If you want only the payloads of the external segments
- * to be processed, you can return <code>null</code> whenever a
- * {@link PayloadProcessorProvider.ReaderPayloadProcessor} is requested for the {@link Directory} of the
- * {@link IndexWriter}.
- * <p>
- * The default is <code>null</code> which means payloads are processed
- * normally (copied) during segment merges. You can also unset it by passing
- * <code>null</code>.
- * <p>
- * <b>NOTE:</b> the set {@link PayloadProcessorProvider} will be in effect
- * immediately, potentially for already running merges too. If you want to be
- * sure it is used for further operations only, such as {@link #addIndexes} or
- * {@link #forceMerge}, you can call {@link #waitForMerges()} before.
- */
- public void setPayloadProcessorProvider(PayloadProcessorProvider pcp) {
- ensureOpen();
- payloadProcessorProvider = pcp;
- }
-
- /**
- * Returns the {@link PayloadProcessorProvider} that is used during segment
- * merges to process payloads.
- */
- public PayloadProcessorProvider getPayloadProcessorProvider() {
- ensureOpen();
- return payloadProcessorProvider;
- }
/**
* NOTE: this method creates a compound file for all files returned by
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexWriterConfig.java Fri Sep 21 17:21:34 2012
@@ -39,7 +39,7 @@ import org.apache.lucene.util.Version;
* All setter methods return {@link IndexWriterConfig} to allow chaining
* settings conveniently, for example:
*
- * <pre>
+ * <pre class="prettyprint">
* IndexWriterConfig conf = new IndexWriterConfig(analyzer);
* conf.setter1().setter2();
* </pre>
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableField.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableField.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableField.java Fri Sep 21 17:21:34 2012
@@ -22,6 +22,8 @@ import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.search.similarities.DefaultSimilarity; // javadocs
+import org.apache.lucene.search.similarities.Similarity; // javadocs
import org.apache.lucene.util.BytesRef;
// TODO: how to handle versioning here...?
@@ -33,29 +35,7 @@ import org.apache.lucene.util.BytesRef;
*
* @lucene.experimental */
-public interface IndexableField {
-
- /** Field name */
- public String name();
-
- /** {@link IndexableFieldType} describing the properties
- * of this field. */
- public IndexableFieldType fieldType();
-
- /** Field boost (you must pre-multiply in any doc boost). */
- public float boost();
-
- /** Non-null if this field has a binary value */
- public BytesRef binaryValue();
-
- /** Non-null if this field has a string value */
- public String stringValue();
-
- /** Non-null if this field has a Reader value */
- public Reader readerValue();
-
- /** Non-null if this field has a numeric value */
- public Number numericValue();
+public interface IndexableField extends GeneralField {
/**
* Creates the TokenStream used for indexing this field. If appropriate,
@@ -67,4 +47,26 @@ public interface IndexableField {
* @throws IOException Can be thrown while creating the TokenStream
*/
public TokenStream tokenStream(Analyzer analyzer) throws IOException;
+
+ /**
+ * Returns the field's index-time boost.
+ * <p>
+ * Only fields can have an index-time boost, if you want to simulate
+ * a "document boost", then you must pre-multiply it across all the
+ * relevant fields yourself.
+ * <p>The boost is used to compute the norm factor for the field. By
+ * default, in the {@link Similarity#computeNorm(FieldInvertState, Norm)} method,
+ * the boost value is multiplied by the length normalization factor and then
+ * rounded by {@link DefaultSimilarity#encodeNormValue(float)} before it is stored in the
+ * index. One should attempt to ensure that this product does not overflow
+ * the range of that encoding.
+ * <p>
+ * It is illegal to return a boost other than 1.0f for a field that is not
+ * indexed ({@link IndexableFieldType#indexed()} is false) or omits normalization values
+ * ({@link IndexableFieldType#omitNorms()} returns true).
+ *
+ * @see Similarity#computeNorm(FieldInvertState, Norm)
+ * @see DefaultSimilarity#encodeNormValue(float)
+ */
+ public float boost();
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java Fri Sep 21 17:21:34 2012
@@ -17,6 +17,7 @@ package org.apache.lucene.index;
* limitations under the License.
*/
+import org.apache.lucene.analysis.Analyzer; // javadocs
import org.apache.lucene.index.FieldInfo.IndexOptions;
/**
@@ -30,30 +31,69 @@ public interface IndexableFieldType {
/** True if the field's value should be stored */
public boolean stored();
-
- /** True if this field's value should be analyzed */
+
+ /**
+ * True if this field's value should be analyzed by the
+ * {@link Analyzer}.
+ * <p>
+ * This has no effect if {@link #indexed()} returns false.
+ */
public boolean tokenized();
- /** True if term vectors should be indexed */
+ /**
+ * True if this field's indexed form should be also stored
+ * into term vectors.
+ * <p>
+ * This builds a miniature inverted-index for this field which
+ * can be accessed in a document-oriented way from
+ * {@link IndexReader#getTermVector(int,String)}.
+ * <p>
+ * This option is illegal if {@link #indexed()} returns false.
+ */
public boolean storeTermVectors();
- /** True if term vector offsets should be indexed */
+ /**
+ * True if this field's token character offsets should also
+ * be stored into term vectors.
+ * <p>
+ * This option is illegal if term vectors are not enabled for the field
+ * ({@link #storeTermVectors()} is false)
+ */
public boolean storeTermVectorOffsets();
- /** True if term vector positions should be indexed */
+ /**
+ * True if this field's token positions should also be stored
+ * into the term vectors.
+ * <p>
+ * This option is illegal if term vectors are not enabled for the field
+ * ({@link #storeTermVectors()} is false).
+ */
public boolean storeTermVectorPositions();
- /** True if term vector payloads should be indexed */
+ /**
+ * True if this field's token payloads should also be stored
+ * into the term vectors.
+ * <p>
+ * This option is illegal if term vector positions are not enabled
+ * for the field ({@link #storeTermVectors()} is false).
+ */
public boolean storeTermVectorPayloads();
- /** True if norms should not be indexed */
+ /**
+ * True if normalization values should be omitted for the field.
+ * <p>
+ * This saves memory, but at the expense of scoring quality (length normalization
+ * will be disabled), and if you omit norms, you cannot use index-time boosts.
+ */
public boolean omitNorms();
/** {@link IndexOptions}, describing what should be
* recorded into the inverted index */
public IndexOptions indexOptions();
- /** DocValues type; if non-null then the field's value
- * will be indexed into docValues */
- public DocValues.Type docValueType();
+ /**
+ * DocValues {@link DocValues.Type}: if non-null then the field's value
+ * will be indexed into docValues.
+ */
+ public DocValues.Type docValueType();
}