You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2011/12/07 00:43:33 UTC
svn commit: r1211231 - in /lucene/dev/branches/lucene3606/lucene:
contrib/memory/src/java/org/apache/lucene/index/memory/
src/java/org/apache/lucene/index/
Author: uschindler
Date: Tue Dec 6 23:43:33 2011
New Revision: 1211231
URL: http://svn.apache.org/viewvc?rev=1211231&view=rev
Log:
LUCENE-3606: More cleanup and make IR methods that simply call other abstract methods final
Modified:
lucene/dev/branches/lucene3606/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/MultiReader.java
lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/ParallelReader.java
Modified: lucene/dev/branches/lucene3606/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (original)
+++ lucene/dev/branches/lucene3606/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java Tue Dec 6 23:43:33 2011
@@ -767,11 +767,11 @@ public class MemoryIndex {
}
@Override
- public int docFreq(Term term) {
- Info info = getInfo(term.field());
+ public int docFreq(String field, BytesRef term) {
+ Info info = getInfo(field);
int freq = 0;
- if (info != null) freq = info.getPositions(term.bytes()) != null ? 1 : 0;
- if (DEBUG) System.err.println("MemoryIndexReader.docFreq: " + term + ", freq:" + freq);
+ if (info != null) freq = info.getPositions(term) != null ? 1 : 0;
+ if (DEBUG) System.err.println("MemoryIndexReader.docFreq: " + field + ":" + term + ", freq:" + freq);
return freq;
}
Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java (original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/DirectoryReader.java Tue Dec 6 23:43:33 2011
@@ -483,15 +483,6 @@ class DirectoryReader extends IndexReade
}
@Override
- public int docFreq(Term t) throws IOException {
- ensureOpen();
- int total = 0; // sum freqs in segments
- for (int i = 0; i < subReaders.length; i++)
- total += subReaders[i].docFreq(t);
- return total;
- }
-
- @Override
public int docFreq(String field, BytesRef term) throws IOException {
ensureOpen();
int total = 0; // sum freqs in segments
@@ -507,11 +498,6 @@ class DirectoryReader extends IndexReade
}
@Override
- public long getUniqueTermCount() throws IOException {
- return -1;
- }
-
- @Override
public Map<String,String> getCommitUserData() {
ensureOpen();
return segmentInfos.getUserData();
Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java (original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java Tue Dec 6 23:43:33 2011
@@ -342,12 +342,6 @@ public class FilterIndexReader extends I
}
@Override
- public int docFreq(Term t) throws IOException {
- ensureOpen();
- return in.docFreq(t);
- }
-
- @Override
public int docFreq(String field, BytesRef t) throws IOException {
ensureOpen();
return in.docFreq(field, t);
Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/IndexReader.java Tue Dec 6 23:43:33 2011
@@ -170,7 +170,7 @@ public abstract class IndexReader implem
static int DEFAULT_TERMS_INDEX_DIVISOR = 1;
/** Expert: returns the current refCount for this reader */
- public int getRefCount() {
+ public final int getRefCount() {
return refCount.get();
}
@@ -189,7 +189,7 @@ public abstract class IndexReader implem
* @see #decRef
* @see #tryIncRef
*/
- public void incRef() {
+ public final void incRef() {
ensureOpen();
refCount.incrementAndGet();
}
@@ -217,7 +217,7 @@ public abstract class IndexReader implem
* @see #decRef
* @see #incRef
*/
- public boolean tryIncRef() {
+ public final boolean tryIncRef() {
int count;
while ((count = refCount.get()) > 0) {
if (refCount.compareAndSet(count, count+1)) {
@@ -255,7 +255,7 @@ public abstract class IndexReader implem
*
* @see #incRef
*/
- public void decRef() throws IOException {
+ public final void decRef() throws IOException {
ensureOpen();
final int rc = refCount.getAndDecrement();
if (rc == 1) {
@@ -658,14 +658,14 @@ public abstract class IndexReader implem
* term vectors were not indexed. The returned Fields
* instance acts like a single-document inverted index
* (the docID will be 0). */
- abstract public Fields getTermVectors(int docID)
+ public abstract Fields getTermVectors(int docID)
throws IOException;
/** Retrieve term vector for this document and field, or
* null if term vectors were not indexed. The returned
* Fields instance acts like a single-document inverted
* index (the docID will be 0). */
- public Terms getTermVector(int docID, String field)
+ public final Terms getTermVector(int docID, String field)
throws IOException {
Fields vectors = getTermVectors(docID);
if (vectors == null) {
@@ -699,7 +699,7 @@ public abstract class IndexReader implem
public abstract int maxDoc();
/** Returns the number of deleted documents. */
- public int numDeletedDocs() {
+ public final int numDeletedDocs() {
return maxDoc() - numDocs();
}
@@ -732,7 +732,7 @@ public abstract class IndexReader implem
// TODO: we need a separate StoredField, so that the
// Document returned here contains that class not
// IndexableField
- public Document document(int docID) throws CorruptIndexException, IOException {
+ public final Document document(int docID) throws CorruptIndexException, IOException {
ensureOpen();
if (docID < 0 || docID >= maxDoc()) {
throw new IllegalArgumentException("docID must be >= 0 and < maxDoc=" + maxDoc() + " (got docID=" + docID + ")");
@@ -791,7 +791,7 @@ public abstract class IndexReader implem
* through them yourself. */
public abstract PerDocValues perDocValues() throws IOException;
- public int docFreq(Term term) throws IOException {
+ public final int docFreq(Term term) throws IOException {
return docFreq(term.field(), term.bytes());
}
@@ -822,7 +822,7 @@ public abstract class IndexReader implem
* field does not exists. This method does not take into
* account deleted documents that have not yet been merged
* away. */
- public long totalTermFreq(String field, BytesRef term) throws IOException {
+ public final long totalTermFreq(String field, BytesRef term) throws IOException {
final Fields fields = fields();
if (fields == null) {
return 0;
@@ -840,7 +840,7 @@ public abstract class IndexReader implem
}
/** This may return null if the field does not exist.*/
- public Terms terms(String field) throws IOException {
+ public final Terms terms(String field) throws IOException {
final Fields fields = fields();
if (fields == null) {
return null;
@@ -851,7 +851,7 @@ public abstract class IndexReader implem
/** Returns {@link DocsEnum} for the specified field &
* term. This may return null, if either the field or
* term does not exist. */
- public DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, boolean needsFreqs) throws IOException {
+ public final DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, boolean needsFreqs) throws IOException {
assert field != null;
assert term != null;
final Fields fields = fields();
@@ -871,7 +871,7 @@ public abstract class IndexReader implem
* field & term. This may return null, if either the
* field or term does not exist, or, positions were not
* indexed for this field. */
- public DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term) throws IOException {
+ public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term) throws IOException {
assert field != null;
assert term != null;
final Fields fields = fields();
@@ -892,7 +892,7 @@ public abstract class IndexReader implem
* {@link TermState}. This may return null, if either the field or the term
* does not exists or the {@link TermState} is invalid for the underlying
* implementation.*/
- public DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, TermState state, boolean needsFreqs) throws IOException {
+ public final DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, TermState state, boolean needsFreqs) throws IOException {
assert state != null;
assert field != null;
final Fields fields = fields();
@@ -912,7 +912,7 @@ public abstract class IndexReader implem
* {@link TermState}. This may return null, if either the field or the term
* does not exists, the {@link TermState} is invalid for the underlying
* implementation, or positions were not indexed for this field. */
- public DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term, TermState state) throws IOException {
+ public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term, TermState state) throws IOException {
assert state != null;
assert field != null;
final Fields fields = fields();
@@ -1109,12 +1109,6 @@ public abstract class IndexReader implem
* top-level context holds a <code>null</code> {@link CompositeReaderContext#leaves}
* reference. Only the top-level context maintains the convenience leaf-view
* for performance reasons.
- * <p>
- * NOTE: You should not try using sub-readers returned by this method to make
- * any changes (deleteDocument, etc.). While this might succeed for
- * one composite reader (like MultiReader), it will most likely lead to index
- * corruption for other readers (like DirectoryReader obtained through
- * {@link #open}. Use the top-level context's reader directly.
*
* @lucene.experimental
*/
@@ -1135,7 +1129,10 @@ public abstract class IndexReader implem
* Instead, you should call {@link
* #getSequentialSubReaders} and ask each sub reader for
* its unique term count. */
- public long getUniqueTermCount() throws IOException {
+ public final long getUniqueTermCount() throws IOException {
+ if (!getTopReaderContext().isAtomic) {
+ return -1;
+ }
final Fields fields = fields();
if (fields == null) {
return 0;
Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/MultiReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/MultiReader.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/MultiReader.java (original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/MultiReader.java Tue Dec 6 23:43:33 2011
@@ -83,11 +83,6 @@ public class MultiReader extends IndexRe
}
@Override
- public long getUniqueTermCount() throws IOException {
- throw new UnsupportedOperationException("");
- }
-
- @Override
public Fields fields() throws IOException {
throw new UnsupportedOperationException("please use MultiFields.getFields, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level Fields");
}
@@ -256,15 +251,6 @@ public class MultiReader extends IndexRe
public synchronized byte[] norms(String field) throws IOException {
throw new UnsupportedOperationException("please use MultiNorms.norms, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level norms");
}
-
- @Override
- public int docFreq(Term t) throws IOException {
- ensureOpen();
- int total = 0; // sum freqs in segments
- for (int i = 0; i < subReaders.length; i++)
- total += subReaders[i].docFreq(t);
- return total;
- }
@Override
public int docFreq(String field, BytesRef t) throws IOException {
Modified: lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/ParallelReader.java?rev=1211231&r1=1211230&r2=1211231&view=diff
==============================================================================
--- lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/dev/branches/lucene3606/lucene/src/java/org/apache/lucene/index/ParallelReader.java Tue Dec 6 23:43:33 2011
@@ -385,13 +385,6 @@ public class ParallelReader extends Inde
}
@Override
- public int docFreq(Term term) throws IOException {
- ensureOpen();
- IndexReader reader = fieldToReader.get(term.field());
- return reader==null ? 0 : reader.docFreq(term);
- }
-
- @Override
public int docFreq(String field, BytesRef term) throws IOException {
ensureOpen();
IndexReader reader = fieldToReader.get(field);