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 2011/02/09 10:36:03 UTC
svn commit: r1068809 [14/36] - in /lucene/dev/branches/docvalues: ./
dev-tools/eclipse/ dev-tools/idea/.idea/ dev-tools/idea/.idea/copyright/
dev-tools/idea/lucene/ dev-tools/idea/lucene/contrib/ant/
dev-tools/idea/lucene/contrib/queryparser/ dev-tools...
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanFirstQuery.java Wed Feb 9 09:35:27 2011
@@ -38,7 +38,7 @@ public class SpanFirstQuery extends Span
@Override
protected AcceptStatus acceptPosition(Spans spans) throws IOException {
- assert spans.start() != spans.end();
+ assert spans.start() != spans.end() : "start equals end: " + spans.start();
if (spans.start() >= end)
return AcceptStatus.NO_AND_ADVANCE;
else if (spans.end() <= end)
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanMultiTermQueryWrapper.java Wed Feb 9 09:35:27 2011
@@ -20,12 +20,14 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopTermsRewrite;
import org.apache.lucene.search.ScoringRewrite;
import org.apache.lucene.search.BooleanClause.Occur; // javadocs only
+import org.apache.lucene.util.PerReaderTermState;
/**
* Wraps any {@link MultiTermQuery} as a {@link SpanQuery},
@@ -87,7 +89,7 @@ public class SpanMultiTermQueryWrapper<Q
}
@Override
- public Spans getSpans(IndexReader reader) throws IOException {
+ public Spans getSpans(AtomicReaderContext context) throws IOException {
throw new UnsupportedOperationException("Query should have been rewritten");
}
@@ -153,7 +155,7 @@ public class SpanMultiTermQueryWrapper<Q
}
@Override
- protected void addClause(SpanOrQuery topLevel, Term term, int docCount, float boost) {
+ protected void addClause(SpanOrQuery topLevel, Term term, int docCount, float boost, PerReaderTermState states) {
final SpanTermQuery q = new SpanTermQuery(term);
q.setBoost(boost);
topLevel.addClause(q);
@@ -202,7 +204,7 @@ public class SpanMultiTermQueryWrapper<Q
}
@Override
- protected void addClause(SpanOrQuery topLevel, Term term, int docFreq, float boost) {
+ protected void addClause(SpanOrQuery topLevel, Term term, int docFreq, float boost, PerReaderTermState states) {
final SpanTermQuery q = new SpanTermQuery(term);
q.setBoost(boost);
topLevel.addClause(q);
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearPayloadCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearPayloadCheckQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearPayloadCheckQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearPayloadCheckQuery.java Wed Feb 9 09:35:27 2011
@@ -72,6 +72,7 @@ public class SpanNearPayloadCheckQuery e
return AcceptStatus.NO;
}
+ @Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
buffer.append("spanPayCheck(");
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Wed Feb 9 09:35:27 2011
@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.ToStringUtils;
@@ -116,16 +117,16 @@ public class SpanNearQuery extends SpanQ
}
@Override
- public Spans getSpans(final IndexReader reader) throws IOException {
+ public Spans getSpans(final AtomicReaderContext context) throws IOException {
if (clauses.size() == 0) // optimize 0-clause case
- return new SpanOrQuery(getClauses()).getSpans(reader);
+ return new SpanOrQuery(getClauses()).getSpans(context);
if (clauses.size() == 1) // optimize 1-clause case
- return clauses.get(0).getSpans(reader);
+ return clauses.get(0).getSpans(context);
return inOrder
- ? (Spans) new NearSpansOrdered(this, reader, collectPayloads)
- : (Spans) new NearSpansUnordered(this, reader);
+ ? (Spans) new NearSpansOrdered(this, context, collectPayloads)
+ : (Spans) new NearSpansUnordered(this, context);
}
@Override
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Wed Feb 9 09:35:27 2011
@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;
*/
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.ToStringUtils;
@@ -74,12 +75,12 @@ public class SpanNotQuery extends SpanQu
}
@Override
- public Spans getSpans(final IndexReader reader) throws IOException {
+ public Spans getSpans(final AtomicReaderContext context) throws IOException {
return new Spans() {
- private Spans includeSpans = include.getSpans(reader);
+ private Spans includeSpans = include.getSpans(context);
private boolean moreInclude = true;
- private Spans excludeSpans = exclude.getSpans(reader);
+ private Spans excludeSpans = exclude.getSpans(context);
private boolean moreExclude = excludeSpans.next();
@Override
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Wed Feb 9 09:35:27 2011
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.ToStringUtils;
@@ -162,9 +163,9 @@ public class SpanOrQuery extends SpanQue
}
@Override
- public Spans getSpans(final IndexReader reader) throws IOException {
+ public Spans getSpans(final AtomicReaderContext context) throws IOException {
if (clauses.size() == 1) // optimize 1-clause case
- return (clauses.get(0)).getSpans(reader);
+ return (clauses.get(0)).getSpans(context);
return new Spans() {
private SpanQueue queue = null;
@@ -173,7 +174,7 @@ public class SpanOrQuery extends SpanQue
queue = new SpanQueue(clauses.size());
Iterator<SpanQuery> i = clauses.iterator();
while (i.hasNext()) {
- Spans spans = i.next().getSpans(reader);
+ Spans spans = i.next().getSpans(context);
if ( ((target == -1) && spans.next())
|| ((target != -1) && spans.skipTo(target))) {
queue.add(spans);
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPayloadCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPayloadCheckQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPayloadCheckQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPayloadCheckQuery.java Wed Feb 9 09:35:27 2011
@@ -74,6 +74,7 @@ public class SpanPayloadCheckQuery exten
return AcceptStatus.YES;
}
+ @Override
public String toString(String field) {
StringBuilder buffer = new StringBuilder();
buffer.append("spanPayCheck(");
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java Wed Feb 9 09:35:27 2011
@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
@@ -80,8 +81,8 @@ public abstract class SpanPositionCheckQ
protected abstract AcceptStatus acceptPosition(Spans spans) throws IOException;
@Override
- public Spans getSpans(final IndexReader reader) throws IOException {
- return new PositionCheckSpan(reader);
+ public Spans getSpans(final AtomicReaderContext context) throws IOException {
+ return new PositionCheckSpan(context);
}
@@ -105,8 +106,8 @@ public abstract class SpanPositionCheckQ
protected class PositionCheckSpan extends Spans {
private Spans spans;
- public PositionCheckSpan(IndexReader reader) throws IOException {
- spans = match.getSpans(reader);
+ public PositionCheckSpan(AtomicReaderContext context) throws IOException {
+ spans = match.getSpans(context);
}
@Override
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanQuery.java Wed Feb 9 09:35:27 2011
@@ -19,7 +19,7 @@ package org.apache.lucene.search.spans;
import java.io.IOException;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Weight;
@@ -28,7 +28,7 @@ import org.apache.lucene.search.Weight;
public abstract class SpanQuery extends Query {
/** Expert: Returns the matches for this query in an index. Used internally
* to search for spans. */
- public abstract Spans getSpans(IndexReader reader) throws IOException;
+ public abstract Spans getSpans(AtomicReaderContext context) throws IOException;
/** Returns the name of the field matched by this query.*/
public abstract String getField();
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java Wed Feb 9 09:35:27 2011
@@ -36,10 +36,12 @@ public class SpanScorer extends Scorer {
protected int doc;
protected float freq;
-
+ protected final Similarity similarity;
+
protected SpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms)
throws IOException {
- super(similarity, weight);
+ super(weight);
+ this.similarity = similarity;
this.spans = spans;
this.norms = norms;
this.value = weight.getValue();
@@ -81,7 +83,7 @@ public class SpanScorer extends Scorer {
freq = 0.0f;
do {
int matchLength = spans.end() - spans.start();
- freq += getSimilarity().sloppyFreq(matchLength);
+ freq += similarity.sloppyFreq(matchLength);
more = spans.next();
} while (more && (doc == spans.doc()));
return true;
@@ -92,8 +94,8 @@ public class SpanScorer extends Scorer {
@Override
public float score() throws IOException {
- float raw = getSimilarity().tf(freq) * value; // raw score
- return norms == null? raw : raw * getSimilarity().decodeNormValue(norms[doc]); // normalize
+ float raw = similarity.tf(freq) * value; // raw score
+ return norms == null? raw : raw * similarity.decodeNormValue(norms[doc]); // normalize
}
@Override
@@ -109,7 +111,7 @@ public class SpanScorer extends Scorer {
int expDoc = advance(doc);
float phraseFreq = (expDoc == doc) ? freq : 0.0f;
- tfExplanation.setValue(getSimilarity().tf(phraseFreq));
+ tfExplanation.setValue(similarity.tf(phraseFreq));
tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");
return tfExplanation;
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Wed Feb 9 09:35:27 2011
@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;
*/
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.util.ToStringUtils;
@@ -80,7 +81,8 @@ public class SpanTermQuery extends SpanQ
}
@Override
- public Spans getSpans(final IndexReader reader) throws IOException {
+ public Spans getSpans(final AtomicReaderContext context) throws IOException {
+ final IndexReader reader = context.reader;
final DocsAndPositionsEnum postings = reader.termPositionsEnum(reader.getDeletedDocs(),
term.field(),
term.bytes());
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java Wed Feb 9 09:35:27 2011
@@ -17,7 +17,7 @@ package org.apache.lucene.search.spans;
* limitations under the License.
*/
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.search.Explanation.IDFExplanation;
@@ -42,7 +42,7 @@ public class SpanWeight extends Weight {
public SpanWeight(SpanQuery query, IndexSearcher searcher)
throws IOException {
- this.similarity = query.getSimilarity(searcher);
+ this.similarity = searcher.getSimilarityProvider().get(query.getField());
this.query = query;
terms=new HashSet<Term>();
@@ -72,13 +72,13 @@ public class SpanWeight extends Weight {
}
@Override
- public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
- return new SpanScorer(query.getSpans(reader), this, similarity, reader
+ public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException {
+ return new SpanScorer(query.getSpans(context), this, similarity, context.reader
.norms(query.getField()));
}
@Override
- public Explanation explain(IndexReader reader, int doc)
+ public Explanation explain(AtomicReaderContext context, int doc)
throws IOException {
ComplexExplanation result = new ComplexExplanation();
@@ -111,12 +111,12 @@ public class SpanWeight extends Weight {
fieldExpl.setDescription("fieldWeight("+field+":"+query.toString(field)+
" in "+doc+"), product of:");
- Explanation tfExpl = ((SpanScorer)scorer(reader, true, false)).explain(doc);
+ Explanation tfExpl = ((SpanScorer)scorer(context, ScorerContext.def())).explain(doc);
fieldExpl.addDetail(tfExpl);
fieldExpl.addDetail(idfExpl);
Explanation fieldNormExpl = new Explanation();
- byte[] fieldNorms = reader.norms(field);
+ byte[] fieldNorms = context.reader.norms(field);
float fieldNorm =
fieldNorms!=null ? similarity.decodeNormValue(fieldNorms[doc]) : 1.0f;
fieldNormExpl.setValue(fieldNorm);
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/Spans.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/search/spans/Spans.java Wed Feb 9 09:35:27 2011
@@ -83,4 +83,5 @@ public abstract class Spans {
* @return true if there is a payload available at this position that can be loaded
*/
public abstract boolean isPayloadAvailable();
+
}
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/BufferedIndexInput.java Wed Feb 9 09:35:27 2011
@@ -144,6 +144,68 @@ public abstract class BufferedIndexInput
}
}
+ @Override
+ public short readShort() throws IOException {
+ if (2 <= (bufferLength-bufferPosition)) {
+ return (short) (((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF));
+ } else {
+ return super.readShort();
+ }
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ if (4 <= (bufferLength-bufferPosition)) {
+ return ((buffer[bufferPosition++] & 0xFF) << 24) | ((buffer[bufferPosition++] & 0xFF) << 16)
+ | ((buffer[bufferPosition++] & 0xFF) << 8) | (buffer[bufferPosition++] & 0xFF);
+ } else {
+ return super.readInt();
+ }
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ if (8 <= (bufferLength-bufferPosition)) {
+ final int i1 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) |
+ ((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff);
+ final int i2 = ((buffer[bufferPosition++] & 0xff) << 24) | ((buffer[bufferPosition++] & 0xff) << 16) |
+ ((buffer[bufferPosition++] & 0xff) << 8) | (buffer[bufferPosition++] & 0xff);
+ return (((long)i1) << 32) | (i2 & 0xFFFFFFFFL);
+ } else {
+ return super.readLong();
+ }
+ }
+
+ @Override
+ public int readVInt() throws IOException {
+ if (5 <= (bufferLength-bufferPosition)) {
+ byte b = buffer[bufferPosition++];
+ int i = b & 0x7F;
+ for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+ b = buffer[bufferPosition++];
+ i |= (b & 0x7F) << shift;
+ }
+ return i;
+ } else {
+ return super.readVInt();
+ }
+ }
+
+ @Override
+ public long readVLong() throws IOException {
+ if (9 <= bufferLength-bufferPosition) {
+ byte b = buffer[bufferPosition++];
+ long i = b & 0x7F;
+ for (int shift = 7; (b & 0x80) != 0; shift += 7) {
+ b = buffer[bufferPosition++];
+ i |= (b & 0x7FL) << shift;
+ }
+ return i;
+ } else {
+ return super.readVLong();
+ }
+ }
+
private void refill() throws IOException {
long start = bufferStart + bufferPosition;
long end = start + bufferSize;
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/DataInput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/DataInput.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/DataInput.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/DataInput.java Wed Feb 9 09:35:27 2011
@@ -79,7 +79,7 @@ public abstract class DataInput implemen
* supported.
* @see DataOutput#writeVInt(int)
*/
- public final int readVInt() throws IOException {
+ public int readVInt() throws IOException {
byte b = readByte();
int i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
@@ -99,7 +99,7 @@ public abstract class DataInput implemen
/** Reads a long stored in variable-length format. Reads between one and
* nine bytes. Smaller values take fewer bytes. Negative numbers are not
* supported. */
- public final long readVLong() throws IOException {
+ public long readVLong() throws IOException {
byte b = readByte();
long i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/FSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/FSLockFactory.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/FSLockFactory.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/FSLockFactory.java Wed Feb 9 09:35:27 2011
@@ -33,7 +33,7 @@ public abstract class FSLockFactory exte
/**
* Set the lock directory. This method can be only called
* once to initialize the lock directory. It is used by {@link FSDirectory}
- * to set the lock directory to itsself.
+ * to set the lock directory to itself.
* Subclasses can also use this method to set the directory
* in the constructor.
*/
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/NativeFSLockFactory.java Wed Feb 9 09:35:27 2011
@@ -60,7 +60,7 @@ public class NativeFSLockFactory extends
* Create a NativeFSLockFactory instance, with null (unset)
* lock directory. When you pass this factory to a {@link FSDirectory}
* subclass, the lock directory is automatically set to the
- * directory itsself. Be sure to create one instance for each directory
+ * directory itself. Be sure to create one instance for each directory
* your create!
*/
public NativeFSLockFactory() throws IOException {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/RAMInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/RAMInputStream.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/RAMInputStream.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/RAMInputStream.java Wed Feb 9 09:35:27 2011
@@ -83,6 +83,7 @@ class RAMInputStream extends IndexInput
}
private final void switchCurrentBuffer(boolean enforceEOF) throws IOException {
+ bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
if (currentBufferIndex >= file.numBuffers()) {
// end of file reached, no more buffers left
if (enforceEOF)
@@ -95,7 +96,6 @@ class RAMInputStream extends IndexInput
} else {
currentBuffer = file.getBuffer(currentBufferIndex);
bufferPosition = 0;
- bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex;
long buflen = length - bufferStart;
bufferLength = buflen > BUFFER_SIZE ? BUFFER_SIZE : (int) buflen;
}
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/SimpleFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/SimpleFSLockFactory.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/SimpleFSLockFactory.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/store/SimpleFSLockFactory.java Wed Feb 9 09:35:27 2011
@@ -57,7 +57,7 @@ public class SimpleFSLockFactory extends
* Create a SimpleFSLockFactory instance, with null (unset)
* lock directory. When you pass this factory to a {@link FSDirectory}
* subclass, the lock directory is automatically set to the
- * directory itsself. Be sure to create one instance for each directory
+ * directory itself. Be sure to create one instance for each directory
* your create!
*/
public SimpleFSLockFactory() throws IOException {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ArrayUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ArrayUtil.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ArrayUtil.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ArrayUtil.java Wed Feb 9 09:35:27 2011
@@ -647,7 +647,7 @@ public final class ArrayUtil {
/**
* Sorts the given array slice using the {@link Comparator}. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small arrays!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays!
* @param fromIndex start index (inclusive)
* @param toIndex end index (exclusive)
*/
@@ -657,7 +657,7 @@ public final class ArrayUtil {
/**
* Sorts the given array using the {@link Comparator}. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small arrays!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays!
*/
public static <T> void insertionSort(T[] a, Comparator<? super T> comp) {
insertionSort(a, 0, a.length, comp);
@@ -665,7 +665,7 @@ public final class ArrayUtil {
/**
* Sorts the given array slice in natural order. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small arrays!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays!
* @param fromIndex start index (inclusive)
* @param toIndex end index (exclusive)
*/
@@ -675,7 +675,7 @@ public final class ArrayUtil {
/**
* Sorts the given array in natural order. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small arrays!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small arrays!
*/
public static <T extends Comparable<? super T>> void insertionSort(T[] a) {
insertionSort(a, 0, a.length);
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeImpl.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeImpl.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeImpl.java Wed Feb 9 09:35:27 2011
@@ -20,6 +20,8 @@ package org.apache.lucene.util;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.lang.ref.WeakReference;
+import java.util.LinkedList;
/**
* Base class for Attributes that can be added to a
@@ -37,72 +39,80 @@ public abstract class AttributeImpl impl
public abstract void clear();
/**
- * The default implementation of this method accesses all declared
- * fields of this object and prints the values in the following syntax:
+ * This method returns the current attribute values as a string in the following format
+ * by calling the {@link #reflectWith(AttributeReflector)} method:
*
+ * <ul>
+ * <li><em>iff {@code prependAttClass=true}:</em> {@code "AttributeClass#key=value,AttributeClass#key=value"}
+ * <li><em>iff {@code prependAttClass=false}:</em> {@code "key=value,key=value"}
+ * </ul>
+ *
+ * @see #reflectWith(AttributeReflector)
+ */
+ public final String reflectAsString(final boolean prependAttClass) {
+ final StringBuilder buffer = new StringBuilder();
+ reflectWith(new AttributeReflector() {
+ public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
+ if (buffer.length() > 0) {
+ buffer.append(',');
+ }
+ if (prependAttClass) {
+ buffer.append(attClass.getName()).append('#');
+ }
+ buffer.append(key).append('=').append((value == null) ? "null" : value);
+ }
+ });
+ return buffer.toString();
+ }
+
+ /**
+ * This method is for introspection of attributes, it should simply
+ * add the key/values this attribute holds to the given {@link AttributeReflector}.
+ *
+ * <p>The default implementation calls {@link AttributeReflector#reflect} for all
+ * non-static fields from the implementing class, using the field name as key
+ * and the field value as value. The Attribute class is also determined by reflection.
+ * Please note that the default implementation can only handle single-Attribute
+ * implementations.
+ *
+ * <p>Custom implementations look like this (e.g. for a combined attribute implementation):
* <pre>
- * public String toString() {
- * return "start=" + startOffset + ",end=" + endOffset;
+ * public void reflectWith(AttributeReflector reflector) {
+ * reflector.reflect(CharTermAttribute.class, "term", term());
+ * reflector.reflect(PositionIncrementAttribute.class, "positionIncrement", getPositionIncrement());
* }
* </pre>
- *
- * This method may be overridden by subclasses.
- */
- @Override
- public String toString() {
- StringBuilder buffer = new StringBuilder();
- Class<?> clazz = this.getClass();
- Field[] fields = clazz.getDeclaredFields();
+ *
+ * <p>If you implement this method, make sure that for each invocation, the same set of {@link Attribute}
+ * interfaces and keys are passed to {@link AttributeReflector#reflect} in the same order, but possibly
+ * different values. So don't automatically exclude e.g. {@code null} properties!
+ *
+ * @see #reflectAsString(boolean)
+ */
+ public void reflectWith(AttributeReflector reflector) {
+ final Class<? extends AttributeImpl> clazz = this.getClass();
+ final LinkedList<WeakReference<Class<? extends Attribute>>> interfaces = AttributeSource.getAttributeInterfaces(clazz);
+ if (interfaces.size() != 1) {
+ throw new UnsupportedOperationException(clazz.getName() +
+ " implements more than one Attribute interface, the default reflectWith() implementation cannot handle this.");
+ }
+ final Class<? extends Attribute> interf = interfaces.getFirst().get();
+ final Field[] fields = clazz.getDeclaredFields();
try {
for (int i = 0; i < fields.length; i++) {
- Field f = fields[i];
+ final Field f = fields[i];
if (Modifier.isStatic(f.getModifiers())) continue;
f.setAccessible(true);
- Object value = f.get(this);
- if (buffer.length()>0) {
- buffer.append(',');
- }
- if (value == null) {
- buffer.append(f.getName() + "=null");
- } else {
- buffer.append(f.getName() + "=" + value);
- }
+ reflector.reflect(interf, f.getName(), f.get(this));
}
} catch (IllegalAccessException e) {
// this should never happen, because we're just accessing fields
// from 'this'
throw new RuntimeException(e);
}
-
- return buffer.toString();
}
/**
- * Subclasses must implement this method and should compute
- * a hashCode similar to this:
- * <pre>
- * public int hashCode() {
- * int code = startOffset;
- * code = code * 31 + endOffset;
- * return code;
- * }
- * </pre>
- *
- * see also {@link #equals(Object)}
- */
- @Override
- public abstract int hashCode();
-
- /**
- * All values used for computation of {@link #hashCode()}
- * should be checked here for equality.
- *
- * see also {@link Object#equals(Object)}
- */
- @Override
- public abstract boolean equals(Object other);
-
- /**
* Copies the values from this Attribute into the passed-in
* target attribute. The target implementation must support all the
* Attributes this implementation supports.
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeSource.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeSource.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/AttributeSource.java Wed Feb 9 09:35:27 2011
@@ -180,20 +180,9 @@ public class AttributeSource {
private static final WeakHashMap<Class<? extends AttributeImpl>,LinkedList<WeakReference<Class<? extends Attribute>>>> knownImplClasses =
new WeakHashMap<Class<? extends AttributeImpl>,LinkedList<WeakReference<Class<? extends Attribute>>>>();
- /** <b>Expert:</b> Adds a custom AttributeImpl instance with one or more Attribute interfaces.
- * <p><font color="red"><b>Please note:</b> It is not guaranteed, that <code>att</code> is added to
- * the <code>AttributeSource</code>, because the provided attributes may already exist.
- * You should always retrieve the wanted attributes using {@link #getAttribute} after adding
- * with this method and cast to your class.
- * The recommended way to use custom implementations is using an {@link AttributeFactory}.
- * </font></p>
- */
- public void addAttributeImpl(final AttributeImpl att) {
- final Class<? extends AttributeImpl> clazz = att.getClass();
- if (attributeImpls.containsKey(clazz)) return;
- LinkedList<WeakReference<Class<? extends Attribute>>> foundInterfaces;
+ static LinkedList<WeakReference<Class<? extends Attribute>>> getAttributeInterfaces(final Class<? extends AttributeImpl> clazz) {
synchronized(knownImplClasses) {
- foundInterfaces = knownImplClasses.get(clazz);
+ LinkedList<WeakReference<Class<? extends Attribute>>> foundInterfaces = knownImplClasses.get(clazz);
if (foundInterfaces == null) {
// we have a strong reference to the class instance holding all interfaces in the list (parameter "att"),
// so all WeakReferences are never evicted by GC
@@ -210,7 +199,23 @@ public class AttributeSource {
actClazz = actClazz.getSuperclass();
} while (actClazz != null);
}
+ return foundInterfaces;
}
+ }
+
+ /** <b>Expert:</b> Adds a custom AttributeImpl instance with one or more Attribute interfaces.
+ * <p><font color="red"><b>Please note:</b> It is not guaranteed, that <code>att</code> is added to
+ * the <code>AttributeSource</code>, because the provided attributes may already exist.
+ * You should always retrieve the wanted attributes using {@link #getAttribute} after adding
+ * with this method and cast to your class.
+ * The recommended way to use custom implementations is using an {@link AttributeFactory}.
+ * </font></p>
+ */
+ public final void addAttributeImpl(final AttributeImpl att) {
+ final Class<? extends AttributeImpl> clazz = att.getClass();
+ if (attributeImpls.containsKey(clazz)) return;
+ final LinkedList<WeakReference<Class<? extends Attribute>>> foundInterfaces =
+ getAttributeInterfaces(clazz);
// add all interfaces of this AttributeImpl to the maps
for (WeakReference<Class<? extends Attribute>> curInterfaceRef : foundInterfaces) {
@@ -233,7 +238,7 @@ public class AttributeSource {
* already in this AttributeSource and returns it. Otherwise a
* new instance is created, added to this AttributeSource and returned.
*/
- public <A extends Attribute> A addAttribute(Class<A> attClass) {
+ public final <A extends Attribute> A addAttribute(Class<A> attClass) {
AttributeImpl attImpl = attributes.get(attClass);
if (attImpl == null) {
if (!(attClass.isInterface() && Attribute.class.isAssignableFrom(attClass))) {
@@ -248,7 +253,7 @@ public class AttributeSource {
}
/** Returns true, iff this AttributeSource has any attributes */
- public boolean hasAttributes() {
+ public final boolean hasAttributes() {
return !this.attributes.isEmpty();
}
@@ -256,7 +261,7 @@ public class AttributeSource {
* The caller must pass in a Class<? extends Attribute> value.
* Returns true, iff this AttributeSource contains the passed-in Attribute.
*/
- public boolean hasAttribute(Class<? extends Attribute> attClass) {
+ public final boolean hasAttribute(Class<? extends Attribute> attClass) {
return this.attributes.containsKey(attClass);
}
@@ -271,7 +276,7 @@ public class AttributeSource {
* available. If you want to only use the attribute, if it is available (to optimize
* consuming), use {@link #hasAttribute}.
*/
- public <A extends Attribute> A getAttribute(Class<A> attClass) {
+ public final <A extends Attribute> A getAttribute(Class<A> attClass) {
AttributeImpl attImpl = attributes.get(attClass);
if (attImpl == null) {
throw new IllegalArgumentException("This AttributeSource does not have the attribute '" + attClass.getName() + "'.");
@@ -319,7 +324,7 @@ public class AttributeSource {
* Resets all Attributes in this AttributeSource by calling
* {@link AttributeImpl#clear()} on each Attribute implementation.
*/
- public void clearAttributes() {
+ public final void clearAttributes() {
if (hasAttributes()) {
if (currentState == null) {
computeCurrentState();
@@ -334,7 +339,7 @@ public class AttributeSource {
* Captures the state of all Attributes. The return value can be passed to
* {@link #restoreState} to restore the state of this or another AttributeSource.
*/
- public State captureState() {
+ public final State captureState() {
if (!hasAttributes()) {
return null;
}
@@ -360,7 +365,7 @@ public class AttributeSource {
* reset its value to the default, in which case the caller should first
* call {@link TokenStream#clearAttributes()} on the targetStream.
*/
- public void restoreState(State state) {
+ public final void restoreState(State state) {
if (state == null) return;
do {
@@ -431,21 +436,53 @@ public class AttributeSource {
return false;
}
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder().append('(');
+ /**
+ * This method returns the current attribute values as a string in the following format
+ * by calling the {@link #reflectWith(AttributeReflector)} method:
+ *
+ * <ul>
+ * <li><em>iff {@code prependAttClass=true}:</em> {@code "AttributeClass#key=value,AttributeClass#key=value"}
+ * <li><em>iff {@code prependAttClass=false}:</em> {@code "key=value,key=value"}
+ * </ul>
+ *
+ * @see #reflectWith(AttributeReflector)
+ */
+ public final String reflectAsString(final boolean prependAttClass) {
+ final StringBuilder buffer = new StringBuilder();
+ reflectWith(new AttributeReflector() {
+ public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
+ if (buffer.length() > 0) {
+ buffer.append(',');
+ }
+ if (prependAttClass) {
+ buffer.append(attClass.getName()).append('#');
+ }
+ buffer.append(key).append('=').append((value == null) ? "null" : value);
+ }
+ });
+ return buffer.toString();
+ }
+
+ /**
+ * This method is for introspection of attributes, it should simply
+ * add the key/values this AttributeSource holds to the given {@link AttributeReflector}.
+ *
+ * <p>This method iterates over all Attribute implementations and calls the
+ * corresponding {@link AttributeImpl#reflectWith} method.</p>
+ *
+ * @see AttributeImpl#reflectWith
+ */
+ public final void reflectWith(AttributeReflector reflector) {
if (hasAttributes()) {
if (currentState == null) {
computeCurrentState();
}
for (State state = currentState; state != null; state = state.next) {
- if (state != currentState) sb.append(',');
- sb.append(state.attribute.toString());
+ state.attribute.reflectWith(reflector);
}
}
- return sb.append(')').toString();
}
-
+
/**
* Performs a clone of all {@link AttributeImpl} instances returned in a new
* {@code AttributeSource} instance. This method can be used to e.g. create another TokenStream
@@ -453,7 +490,7 @@ public class AttributeSource {
* You can also use it as a (non-performant) replacement for {@link #captureState}, if you need to look
* into / modify the captured state.
*/
- public AttributeSource cloneAttributes() {
+ public final AttributeSource cloneAttributes() {
final AttributeSource clone = new AttributeSource(this.factory);
if (hasAttributes()) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRef.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRef.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRef.java Wed Feb 9 09:35:27 2011
@@ -210,6 +210,7 @@ public final class BytesRef implements C
}
/** Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65] */
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('[');
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRefHash.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRefHash.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRefHash.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/BytesRefHash.java Wed Feb 9 09:35:27 2011
@@ -38,7 +38,7 @@ import org.apache.lucene.util.ByteBlockP
* <p>
* Note: The maximum capacity {@link BytesRef} instance passed to
* {@link #add(BytesRef)} must not be longer than {@link ByteBlockPool#BYTE_BLOCK_SIZE}-2.
- * The internal storage is limited to 2GB totalbyte storage.
+ * The internal storage is limited to 2GB total byte storage.
* </p>
*
* @lucene.internal
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/CollectionUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/CollectionUtil.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/CollectionUtil.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/CollectionUtil.java Wed Feb 9 09:35:27 2011
@@ -140,7 +140,7 @@ public final class CollectionUtil {
/**
* Sorts the given random access {@link List} using the {@link Comparator}.
* The list must implement {@link RandomAccess}. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small lists!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small lists!
* @throws IllegalArgumentException if list is e.g. a linked list without random access.
*/
public static <T> void insertionSort(List<T> list, Comparator<? super T> comp) {
@@ -150,7 +150,7 @@ public final class CollectionUtil {
/**
* Sorts the given random access {@link List} in natural order.
* The list must implement {@link RandomAccess}. This method uses the insertion sort
- * algorithm. It is only recommened to use this algorithm for partially sorted small lists!
+ * algorithm. It is only recommended to use this algorithm for partially sorted small lists!
* @throws IllegalArgumentException if list is e.g. a linked list without random access.
*/
public static <T extends Comparable<? super T>> void insertionSort(List<T> list) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/Constants.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/Constants.java Wed Feb 9 09:35:27 2011
@@ -70,6 +70,9 @@ public final class Constants {
return s.toString();
}
+ // NOTE: we track per-segment version as a String with the "X.Y" format, e.g.
+ // "4.0", "3.1", "3.0". Therefore when we change this constant, we should keep
+ // the format.
public static final String LUCENE_MAIN_VERSION = ident("4.0");
public static final String LUCENE_VERSION;
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/DoubleBarrelLRUCache.java Wed Feb 9 09:35:27 2011
@@ -45,6 +45,7 @@ import java.util.Map;
final public class DoubleBarrelLRUCache<K extends DoubleBarrelLRUCache.CloneableKey,V> {
public static abstract class CloneableKey {
+ @Override
abstract public Object clone();
}
@@ -73,7 +74,7 @@ final public class DoubleBarrelLRUCache<
secondary = cache2;
}
- // Try primary frist
+ // Try primary first
V result = primary.get(key);
if (result == null) {
// Not found -- try secondary
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IOUtils.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IOUtils.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IOUtils.java Wed Feb 9 09:35:27 2011
@@ -34,7 +34,7 @@ public final class IOUtils {
* Closeable resource1 = null, resource2 = null, resource3 = null;
* ExpectedException priorE = null;
* try {
- * resource1 = ...; resource2 = ...; resource3 = ...; // Aquisition may throw ExpectedException
+ * resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
* ..do..stuff.. // May throw ExpectedException
* } catch (ExpectedException e) {
* priorE = e;
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IntsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IntsRef.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IntsRef.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/IntsRef.java Wed Feb 9 09:35:27 2011
@@ -123,6 +123,7 @@ public final class IntsRef implements Co
}
}
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('[');
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/NumericUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/NumericUtils.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/NumericUtils.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/NumericUtils.java Wed Feb 9 09:35:27 2011
@@ -22,8 +22,6 @@ import org.apache.lucene.document.Numeri
import org.apache.lucene.search.NumericRangeFilter;
import org.apache.lucene.search.NumericRangeQuery; // for javadocs
-// TODO: Remove the commented out methods before release!
-
/**
* This is a helper class to generate prefix-encoded representations for numerical values
* and supplies converters to represent float/double values as sortable integers/longs.
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ReaderUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ReaderUtil.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ReaderUtil.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/ReaderUtil.java Wed Feb 9 09:35:27 2011
@@ -22,6 +22,9 @@ import java.util.List;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader.CompositeReaderContext;
+import org.apache.lucene.index.IndexReader.ReaderContext;
/**
* Common util methods for dealing with {@link IndexReader}s.
@@ -44,6 +47,7 @@ public final class ReaderUtil {
this.readerIndex = readerIndex;
}
+ @Override
public String toString() {
return "slice start=" + start + " length=" + length + " readerIndex=" + readerIndex;
}
@@ -148,7 +152,94 @@ public final class ReaderUtil {
.toArray(new IndexReader[subReadersList.size()]);
return subReaders[subIndex];
}
+
+ public static ReaderContext buildReaderContext(IndexReader reader) {
+ return new ReaderContextBuilder(reader).build();
+ }
+
+ public static class ReaderContextBuilder {
+ private final IndexReader reader;
+ private final AtomicReaderContext[] leaves;
+ private int leafOrd = 0;
+ private int leafDocBase = 0;
+ public ReaderContextBuilder(IndexReader reader) {
+ this.reader = reader;
+ leaves = new AtomicReaderContext[numLeaves(reader)];
+ }
+
+ public ReaderContext build() {
+ return build(null, reader, 0, 0);
+ }
+
+ private ReaderContext build(CompositeReaderContext parent, IndexReader reader, int ord, int docBase) {
+ IndexReader[] sequentialSubReaders = reader.getSequentialSubReaders();
+ if (sequentialSubReaders == null) {
+ AtomicReaderContext atomic = new AtomicReaderContext(parent, reader, ord, docBase, leafOrd, leafDocBase);
+ leaves[leafOrd++] = atomic;
+ leafDocBase += reader.maxDoc();
+ return atomic;
+ } else {
+ ReaderContext[] children = new ReaderContext[sequentialSubReaders.length];
+ final CompositeReaderContext newParent;
+ if (parent == null) {
+ newParent = new CompositeReaderContext(reader, children, leaves);
+ } else {
+ newParent = new CompositeReaderContext(parent, reader, ord, docBase, children);
+ }
+
+ int newDocBase = 0;
+ for (int i = 0; i < sequentialSubReaders.length; i++) {
+ build(newParent, sequentialSubReaders[i], i, newDocBase);
+ newDocBase += sequentialSubReaders[i].maxDoc();
+ }
+ return newParent;
+ }
+ }
+
+ private int numLeaves(IndexReader reader) {
+ final int[] numLeaves = new int[1];
+ try {
+ new Gather(reader) {
+ @Override
+ protected void add(int base, IndexReader r) {
+ numLeaves[0]++;
+ }
+ }.run();
+ } catch (IOException ioe) {
+ // won't happen
+ throw new RuntimeException(ioe);
+ }
+ return numLeaves[0];
+ }
+
+ }
+ /**
+ * Returns the context's leaves or the context itself as the only element of
+ * the returned array. If the context's #leaves() method returns
+ * <code>null</code> the given context must be an instance of
+ * {@link AtomicReaderContext}
+ */
+ public static AtomicReaderContext[] leaves(ReaderContext context) {
+ assert context != null && context.isTopLevel : "context must be non-null & top-level";
+ final AtomicReaderContext[] leaves = context.leaves();
+ if (leaves == null) {
+ assert context.isAtomic : "top-level context without leaves must be atomic";
+ return new AtomicReaderContext[] { (AtomicReaderContext) context };
+ }
+ return leaves;
+ }
+
+ /**
+ * Walks up the reader tree and return the given context's top level reader
+ * context, or in other words the reader tree's root context.
+ */
+ public static ReaderContext getTopLevelContext(ReaderContext context) {
+ while (context.parent != null) {
+ context = context.parent;
+ }
+ return context;
+ }
/**
* Returns index of the searcher/reader for document <code>n</code> in the
@@ -175,4 +266,30 @@ public final class ReaderUtil {
}
return hi;
}
+
+ /**
+ * Returns index of the searcher/reader for document <code>n</code> in the
+ * array used to construct this searcher/reader.
+ */
+ public static int subIndex(int n, AtomicReaderContext[] leaves) { // find
+ // searcher/reader for doc n:
+ int size = leaves.length;
+ int lo = 0; // search starts array
+ int hi = size - 1; // for first element less than n, return its index
+ while (hi >= lo) {
+ int mid = (lo + hi) >>> 1;
+ int midValue = leaves[mid].docBase;
+ if (n < midValue)
+ hi = mid - 1;
+ else if (n > midValue)
+ lo = mid + 1;
+ else { // found a match
+ while (mid + 1 < size && leaves[mid + 1].docBase == midValue) {
+ mid++; // scan to last match
+ }
+ return mid;
+ }
+ }
+ return hi;
+ }
}
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SetOnce.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SetOnce.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SetOnce.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SetOnce.java Wed Feb 9 09:35:27 2011
@@ -49,7 +49,7 @@ public final class SetOnce<T> {
}
/**
- * Creates a new instnace with the internal object set to the given object.
+ * Creates a new instance with the internal object set to the given object.
* Note that any calls to {@link #set(Object)} afterwards will result in
* {@link AlreadySetException}
*
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SorterTemplate.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SorterTemplate.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SorterTemplate.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/SorterTemplate.java Wed Feb 9 09:35:27 2011
@@ -36,14 +36,14 @@ public abstract class SorterTemplate {
protected abstract void swap(int i, int j);
/** Compares slots {@code i} and {@code j} of you data.
- * Should be implemented like <code><em>valueOf(j)</em>.compareTo(<em>valueOf(i)</em>)</code> */
+ * Should be implemented like <code><em>valueOf(i)</em>.compareTo(<em>valueOf(j)</em>)</code> */
protected abstract int compare(int i, int j);
/** Implement this method, that stores the value of slot {@code i} as pivot value */
protected abstract void setPivot(int i);
/** Implements the compare function for the previously stored pivot value.
- * Should be implemented like <code>pivot.compareTo(<em>valueOf(i)</em>)</code> */
+ * Should be implemented like <code>pivot.compareTo(<em>valueOf(j)</em>)</code> */
protected abstract int comparePivot(int j);
/** Sorts via stable in-place InsertionSort algorithm
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java Wed Feb 9 09:35:27 2011
@@ -66,6 +66,13 @@ import org.apache.lucene.util.RamUsageEs
* assumed by the built-in automata operations.
*
* <p>
+ * <p>
+ * Note: This class has internal mutable state and is not thread safe. It is
+ * the caller's responsibility to ensure any necessary synchronization if you
+ * wish to use the same Automaton from multiple threads. In general it is instead
+ * recommended to use a {@link RunAutomaton} for multithreaded matching: it is immutable,
+ * thread safe, and much faster.
+ * </p>
* @lucene.experimental
*/
public class Automaton implements Serializable, Cloneable {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java Wed Feb 9 09:35:27 2011
@@ -483,10 +483,12 @@ final public class BasicOperations {
starts.count = 0;
}
+ @Override
public boolean equals(Object other) {
return ((PointTransitions) other).point == point;
}
+ @Override
public int hashCode() {
return point;
}
@@ -563,6 +565,7 @@ final public class BasicOperations {
find(1+t.max).ends.add(t);
}
+ @Override
public String toString() {
StringBuilder s = new StringBuilder();
for(int i=0;i<count;i++) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/ByteRunAutomaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/ByteRunAutomaton.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/ByteRunAutomaton.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/ByteRunAutomaton.java Wed Feb 9 09:35:27 2011
@@ -20,7 +20,12 @@ package org.apache.lucene.util.automaton
public class ByteRunAutomaton extends RunAutomaton {
public ByteRunAutomaton(Automaton a) {
- super(new UTF32ToUTF8().convert(a), 256, true);
+ this(a, false);
+ }
+
+ /** expert: if utf8 is true, the input is already byte-based */
+ public ByteRunAutomaton(Automaton a, boolean utf8) {
+ super(utf8 ? a : new UTF32ToUTF8().convert(a), 256, true);
}
/**
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/RunAutomaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/RunAutomaton.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/RunAutomaton.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/RunAutomaton.java Wed Feb 9 09:35:27 2011
@@ -45,7 +45,6 @@ public abstract class RunAutomaton imple
// getCharClass(c)]
final int[] points; // char interval start points
final int[] classmap; // map from char number to class class
- final Automaton automaton;
/**
* Returns a string representation of this automaton.
@@ -113,13 +112,6 @@ public abstract class RunAutomaton imple
final int getCharClass(int c) {
return SpecialOperations.findIndex(c, points);
}
-
- /**
- * @return the automaton
- */
- public Automaton getAutomaton() {
- return automaton;
- }
/**
* Constructs a new <code>RunAutomaton</code> from a deterministic
@@ -160,7 +152,6 @@ public abstract class RunAutomaton imple
} else {
classmap = null;
}
- this.automaton = a;
}
/**
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/SortedIntSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/SortedIntSet.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/SortedIntSet.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/SortedIntSet.java Wed Feb 9 09:35:27 2011
@@ -159,10 +159,12 @@ final class SortedIntSet {
return new FrozenIntSet(c, hashCode, state);
}
+ @Override
public int hashCode() {
return hashCode;
}
+ @Override
public boolean equals(Object _other) {
if (_other == null) {
return false;
@@ -186,6 +188,7 @@ final class SortedIntSet {
return true;
}
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder().append('[');
for(int i=0;i<upto;i++) {
@@ -215,10 +218,12 @@ final class SortedIntSet {
this.hashCode = 683+num;
}
+ @Override
public int hashCode() {
return hashCode;
}
+ @Override
public boolean equals(Object _other) {
if (_other == null) {
return false;
@@ -256,6 +261,7 @@ final class SortedIntSet {
return false;
}
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder().append('[');
for(int i=0;i<values.length;i++) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java Wed Feb 9 09:35:27 2011
@@ -26,7 +26,8 @@ import java.util.ArrayList;
// TODO
// - do we really need the .bits...? if not we can make util in UnicodeUtil to convert 1 char into a BytesRef
-final class UTF32ToUTF8 {
+/** @lucene.internal */
+public final class UTF32ToUTF8 {
// Unicode boundaries for UTF8 bytes 1,2,3,4
private static final int[] startCodes = new int[] {0, 128, 2048, 65536};
@@ -105,6 +106,7 @@ final class UTF32ToUTF8 {
}
}
+ @Override
public String toString() {
StringBuilder b = new StringBuilder();
for(int i=0;i<len;i++) {
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/FST.java Wed Feb 9 09:35:27 2011
@@ -490,7 +490,7 @@ public class FST<T> {
}
}
- // Not private beacaus NodeHash needs access:
+ // Not private because NodeHash needs access:
Arc<T> readFirstRealArc(int address, Arc<T> arc) throws IOException {
final BytesReader in = getBytesReader(address);
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/PairOutputs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/PairOutputs.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/PairOutputs.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/automaton/fst/PairOutputs.java Wed Feb 9 09:35:27 2011
@@ -55,6 +55,7 @@ public class PairOutputs<A,B> extends Ou
}
}
+ @Override
public int hashCode() {
return output1.hashCode() + output2.hashCode();
}
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed32.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed32.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed32.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed32.java Wed Feb 9 09:35:27 2011
@@ -214,6 +214,7 @@ class Packed32 extends PackedInts.Reader
Arrays.fill(blocks, 0);
}
+ @Override
public String toString() {
return "Packed32(bitsPerValue=" + bitsPerValue + ", maxPos=" + maxPos
+ ", elements.length=" + blocks.length + ")";
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed64.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed64.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed64.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/Packed64.java Wed Feb 9 09:35:27 2011
@@ -199,6 +199,7 @@ class Packed64 extends PackedInts.Reader
| ((value << shifts[base + 2]) & writeMasks[base+2]);
}
+ @Override
public String toString() {
return "Packed64(bitsPerValue=" + bitsPerValue + ", size="
+ size() + ", maxPos=" + maxPos
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedInts.java Wed Feb 9 09:35:27 2011
@@ -251,7 +251,7 @@ public class PackedInts {
/** Returns how many bits are required to hold values up
* to and including maxValue
- * @param maxValue the maximum value tha should be representable.
+ * @param maxValue the maximum value that should be representable.
* @return the amount of bits needed to represent values from 0 to maxValue.
* @lucene.internal
*/
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedWriter.java?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedWriter.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/PackedWriter.java Wed Feb 9 09:35:27 2011
@@ -106,6 +106,7 @@ class PackedWriter extends PackedInts.Wr
}
}
+ @Override
public String toString() {
return "PackedWriter(written " + written + "/" + valueCount + " with "
+ bitsPerValue + " bits/value)";
Modified: lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/package.html?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/package.html (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/org/apache/lucene/util/packed/package.html Wed Feb 9 09:35:27 2011
@@ -1,4 +1,20 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<html>
<head></head>
<body bgcolor="white">
Modified: lucene/dev/branches/docvalues/lucene/src/java/overview.html
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/java/overview.html?rev=1068809&r1=1068808&r2=1068809&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/lucene/src/java/overview.html (original)
+++ lucene/dev/branches/docvalues/lucene/src/java/overview.html Wed Feb 9 09:35:27 2011
@@ -45,48 +45,36 @@ to check if the results are what we expe
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- = Java2Html Converter 5.0 [2006-03-04] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
-<div align="left" class="java">
-<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
- <tr>
- <!-- start source code -->
- <td nowrap="nowrap" valign="top" align="left">
- <code>
-<font color="#ffffff"> </font><font color="#000000">Analyzer analyzer = </font><font color="#7f0055"><b>new </b></font><font color="#000000">StandardAnalyzer</font><font color="#000000">(</font><font color="#000000">Version.LUCENE_CURRENT</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"></font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">// Store the index in memory:</font><br />
-<font color="#ffffff"> </font><font color="#000000">Directory directory = </font><font color="#7f0055"><b>new </b></font><font color="#000000">RAMDirectory</font><font color="#000000">()</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">// To store an index on disk, use this instead:</font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">//Directory directory = FSDirectory.open("/tmp/testindex");</font><br />
-<font color="#ffffff"> </font><font color="#000000">IndexWriter iwriter = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexWriter</font><font color="#000000">(</font><font color="#000000">directory, analyzer, true,</font><br />
-<font color="#ffffff"> </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexWriter.MaxFieldLength</font><font color="#000000">(</font><font color="#990000">25000</font><font color="#000000">))</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">Document doc = </font><font color="#7f0055"><b>new </b></font><font color="#000000">Document</font><font color="#000000">()</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">String text = </font><font color="#2a00ff">"This is the text to be indexed."</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">doc.add</font><font color="#000000">(</font><font color="#7f0055"><b>new </b></font><font color="#000000">Field</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">, text, Field.Store.YES,</font><br />
-<font color="#ffffff"> </font><font color="#000000">Field.Index.ANALYZED</font><font color="#000000">))</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">iwriter.addDocument</font><font color="#000000">(</font><font color="#000000">doc</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">iwriter.close</font><font color="#000000">()</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">// Now search the index:</font><br />
-<font color="#ffffff"> </font><font color="#000000">IndexSearcher isearcher = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexSearcher</font><font color="#000000">(</font><font color="#000000">directory, </font><font color="#7f0055"><b>true</b></font><font color="#000000">)</font><font color="#000000">; </font><font color="#3f7f5f">// read-only=true</font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">// Parse a simple query that searches for "text":</font><br />
-<font color="#ffffff"> </font><font color="#000000">QueryParser parser = </font><font color="#7f0055"><b>new </b></font><font color="#000000">QueryParser</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">, analyzer</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">Query query = parser.parse</font><font color="#000000">(</font><font color="#2a00ff">"text"</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">ScoreDoc</font><font color="#000000">[] </font><font color="#000000">hits = isearcher.search</font><font color="#000000">(</font><font color="#000000">query, null, </font><font color="#990000">1000</font><font color="#000000">)</font><font color="#000000">.scoreDocs;</font><br />
-<font color="#ffffff"> </font><font color="#000000">assertEquals</font><font color="#000000">(</font><font color="#990000">1</font><font color="#000000">, hits.length</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#3f7f5f">// Iterate through the results:</font><br />
-<font color="#ffffff"> </font><font color="#7f0055"><b>for </b></font><font color="#000000">(</font><font color="#7f0055"><b>int </b></font><font color="#000000">i = </font><font color="#990000">0</font><font color="#000000">; i < hits.length; i++</font><font color="#000000">) {</font><br />
-<font color="#ffffff"> </font><font color="#000000">Document hitDoc = isearcher.doc</font><font color="#000000">(</font><font color="#000000">hits</font><font color="#000000">[</font><font color="#000000">i</font><font color="#000000">]</font><font color="#000000">.doc</font><font color="#000000">)</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">assertEquals</font><font color="#000000">(</font><font color="#2a00ff">"This is the text to be indexed."</font><font color="#000000">, hitDoc.get</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">))</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">}</font><br />
-<font color="#ffffff"> </font><font color="#000000">isearcher.close</font><font color="#000000">()</font><font color="#000000">;</font><br />
-<font color="#ffffff"> </font><font color="#000000">directory.close</font><font color="#000000">()</font><font color="#000000">;</font></code>
-
- </td>
- <!-- end source code -->
- </tr>
+<pre class="prettyprint">
+ Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
-</table>
-</div>
+ // Store the index in memory:
+ Directory directory = new RAMDirectory();
+ // To store an index on disk, use this instead:
+ //Directory directory = FSDirectory.open("/tmp/testindex");
+ IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
+ new IndexWriter.MaxFieldLength(25000));
+ Document doc = new Document();
+ String text = "This is the text to be indexed.";
+ doc.add(new Field("fieldname", text, Field.Store.YES,
+ Field.Index.ANALYZED));
+ iwriter.addDocument(doc);
+ iwriter.close();
+
+ // Now search the index:
+ IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
+ // Parse a simple query that searches for "text":
+ QueryParser parser = new QueryParser("fieldname", analyzer);
+ Query query = parser.parse("text");
+ ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
+ assertEquals(1, hits.length);
+ // Iterate through the results:
+ for (int i = 0; i < hits.length; i++) {
+ Document hitDoc = isearcher.doc(hits[i].doc);
+ assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
+ }
+ isearcher.close();
+ directory.close();</pre>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
Copied: lucene/dev/branches/docvalues/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (from r1068464, lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java?p2=lucene/dev/branches/docvalues/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java&p1=lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java&r1=1068464&r2=1068809&rev=1068809&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/dev/branches/docvalues/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java Wed Feb 9 09:35:27 2011
@@ -245,6 +245,37 @@ public class _TestUtil {
sb.appendCodePoint(nextInt(r, blockStarts[block], blockEnds[block]));
return sb.toString();
}
+
+ public static String randomUnicodeString(Random r, int minLength, int maxLength) {
+ if(minLength > maxLength)
+ throw new IllegalArgumentException("minLength must be >= maxLength");
+ final boolean lenEqual = minLength==maxLength;
+ final int end = lenEqual?minLength:minLength + r.nextInt(maxLength-minLength+1);
+ if (end == 0) {
+ // allow 0 length
+ return "";
+ }
+
+ // TODO(simonw): check this
+ final int fixedPlane = 5;//minLength % 5;
+ final char[] buffer = new char[end];
+ for (int i = 0; i < end; i++) {
+ int t = lenEqual? fixedPlane: r.nextInt(5);
+ //buffer[i] = (char) (97 + r.nextInt(26));
+ if (0 == t && i < end - 1 && !lenEqual) {
+ // Make a surrogate pair
+ // High surrogate
+ buffer[i++] = (char) nextInt(r, 0xd800, 0xdbff);
+ // Low surrogate
+ buffer[i] = (char) nextInt(r, 0xdc00, 0xdfff);
+ }
+ else if (t <= 1) buffer[i] = (char) r.nextInt(0x80);
+ else if (2 == t) buffer[i] = (char) nextInt(r, 0x80, 0x800);
+ else if (3 == t) buffer[i] = (char) nextInt(r, 0x800, 0xd7ff);
+ else if (4 == t) buffer[i] = (char) nextInt(r, 0xe000, 0xffff);
+ }
+ return new String(buffer, 0, end);
+ }
public static CodecProvider alwaysCodec(final Codec c) {
CodecProvider p = new CodecProvider() {