Apache Lucene open-source search software
added JavaDoc to DocValues
Simon Willnauer5c2158a97f83
diff --git a/lucene/src/java/org/apache/lucene/index/values/DocValues.java b/lucene/src/java/org/apache/lucene/index/values/DocValues.javaindex 4de684ce526..e9afea38ebb 100644--- a/lucene/src/java/org/apache/lucene/index/values/DocValues.java+++ b/lucene/src/java/org/apache/lucene/index/values/DocValues.java@@ -20,47 +20,131 @@ import java.io.Closeable;import java.io.IOException;import java.util.Comparator;+import org.apache.lucene.index.Fields;+import org.apache.lucene.index.FieldsEnum;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.util.AttributeSource;import org.apache.lucene.util.BytesRef;++/***+ * @see FieldsEnum#docValues()+ * @see Fields#docValues(String)* @lucene.experimental*/public abstract class DocValues implements Closeable {public static final DocValues[] EMPTY_ARRAY = new DocValues[0];+private SourceCache cache = new SourceCache.DirectSourceCache();+ /**+ * Returns an iterator that steps through all documents values for this+ * {@link DocValues} field instance. {@link DocValuesEnum} will skip document+ * without a value if applicable.+ */public DocValuesEnum getEnum() throws IOException {return getEnum(null);}+ /**+ * Returns an iterator that steps through all documents values for this+ * {@link DocValues} field instance. {@link DocValuesEnum} will skip document+ * without a value if applicable.+ * <p>+ * If an {@link AttributeSource} is supplied to this method the+ * {@link DocValuesEnum} will use the given source to access implementation+ * related attributes.+ */public abstract DocValuesEnum getEnum(AttributeSource attrSource)throws IOException;+ /**+ * Loads a new {@link Source} instance for this {@link DocValues} field+ * instance. Source instances returned from this method are not cached. It is+ * the callers responsibility to maintain the instance and release its+ * resources once the source is not needed anymore.+ * <p>+ * This method will return null iff this {@link DocValues} represent a+ * {@link SortedSource}.+ * <p>+ * For managed {@link Source} instances see {@link #getSource()}.+ *+ * @see #getSource()+ * @see #setCache(SourceCache)+ */public abstract Source load() throws IOException;+ /**+ * Returns a {@link Source} instance through the current {@link SourceCache}.+ * Iff no {@link Source} has been loaded into the cache so far the source will+ * be loaded through {@link #load()} and passed to the {@link SourceCache}.+ * The caller of this method should not close the obtained {@link Source}+ * instance unless it is not needed for the rest of its life time.+ * <p>+ * {@link Source} instances obtained from this method are closed / released+ * from the cache once this {@link DocValues} instance is closed by the+ * {@link IndexReader}, {@link Fields} or {@link FieldsEnum} the+ * {@link DocValues} was created from.+ * <p>+ * This method will return null iff this {@link DocValues} represent a+ * {@link SortedSource}.+ */public Source getSource() throws IOException {return cache.load(this);}+ /**+ * Returns a {@link SortedSource} instance for this {@link DocValues} field+ * instance like {@link #getSource()}.+ * <p>+ * This method will return null iff this {@link DocValues} represent a+ * {@link Source} instead of a {@link SortedSource}.+ */public SortedSource getSortedSorted(Comparator<BytesRef> comparator)throws IOException {- return cache.laodSorted(this, comparator);+ return cache.loadSorted(this, comparator);}+ /**+ * Loads and returns a {@link SortedSource} instance for this+ * {@link DocValues} field instance like {@link #load()}.+ * <p>+ * This method will return null iff this {@link DocValues} represent a+ * {@link Source} instead of a {@link SortedSource}.+ */public SortedSource loadSorted(Comparator<BytesRef> comparator)throws IOException {throw new UnsupportedOperationException();}+ /**+ * Returns the {@link Type} of this {@link DocValues} instance+ */public abstract Type type();+ /**+ * Closes this {@link DocValues} instance. This method should only be called+ * by the creator of this {@link DocValues} instance. API users should not+ * close {@link DocValues} instances.+ */public void close() throws IOException {this.cache.close(this);}-++ /**+ * Sets the {@link SourceCache} used by this {@link DocValues} instance. This+ * method should be called before {@link #load()} or+ * {@link #loadSorted(Comparator)} is called. All {@link Source} or+ * {@link SortedSource} instances in the currently used cache will be closed+ * before the new cache is installed.+ * <p>+ * Note: All instances previously obtained from {@link #load()} or+ * {@link #loadSorted(Comparator)} will be closed.+ */public void setCache(SourceCache cache) {+ assert cache != null : "cache must not be null";synchronized (this.cache) {this.cache.close(this);this.cache = cache;@@ -68,9 +152,12 @@ public abstract class DocValues implements Closeable {}/**- * Source of integer (returned as java long), per document. The underlying- * implementation may use different numbers of bits per value; long is only- * used since it can handle all precisions.+ * Source of per document values like long, double or {@link BytesRef}+ * depending on the {@link DocValues} fields {@link Type}. Source+ * implementations provide random access semantics similar to array lookups+ * and typically are entirely memory resident.+ * <p>+ * {@link Source} defines 3 {@link Type} //TODO finish this*/public static abstract class Source {protected final MissingValue missingValue = new MissingValue();@@ -98,11 +185,11 @@ public abstract class DocValues implements Closeable {public DocValuesEnum getEnum() throws IOException {return getEnum(null);}-+public MissingValue getMissing() {return missingValue;}-+public abstract Type type();public abstract DocValuesEnum getEnum(AttributeSource attrSource)@@ -132,7 +219,7 @@ public abstract class DocValues implements Closeable {@Overridepublic int nextDoc() throws IOException {- if(pos == NO_MORE_DOCS)+ if (pos == NO_MORE_DOCS)return NO_MORE_DOCS;return advance(pos + 1);}@@ -168,14 +255,15 @@ public abstract class DocValues implements Closeable {public final LookupResult getByValue(BytesRef value) {return getByValue(value, new BytesRef());}+public abstract LookupResult getByValue(BytesRef value, BytesRef tmpRef);}-+public final static class MissingValue {public long longValue;public double doubleValue;public BytesRef bytesValue;-+public final void copy(MissingValue values) {longValue = values.longValue;doubleValue = values.doubleValue;diff --git a/lucene/src/java/org/apache/lucene/index/values/SourceCache.java b/lucene/src/java/org/apache/lucene/index/values/SourceCache.javaindex 07e33633b44..81ef54f4677 100644--- a/lucene/src/java/org/apache/lucene/index/values/SourceCache.java+++ b/lucene/src/java/org/apache/lucene/index/values/SourceCache.java@@ -31,7 +31,7 @@ import org.apache.lucene.util.BytesRef;public abstract class SourceCache {public abstract Source load(DocValues values) throws IOException;- public abstract SortedSource laodSorted(DocValues values,+ public abstract SortedSource loadSorted(DocValues values,Comparator<BytesRef> comp) throws IOException;public abstract void invalidate(DocValues values);@@ -50,7 +50,7 @@ public abstract class SourceCache {return ref;}- public synchronized SortedSource laodSorted(DocValues values,+ public synchronized SortedSource loadSorted(DocValues values,Comparator<BytesRef> comp) throws IOException {if (sortedRef == null)sortedRef = values.loadSorted(comp);