You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by rm...@apache.org on 2010/02/26 14:10:08 UTC
svn commit: r916666 [9/16] - in /lucene/java/branches/flex_1458: ./ contrib/
contrib/analyzers/common/
contrib/analyzers/common/src/java/org/apache/lucene/analysis/ar/
contrib/analyzers/common/src/java/org/apache/lucene/analysis/bg/
contrib/analyzers/c...
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/MultipleTermPositions.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/MultipleTermPositions.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/MultipleTermPositions.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/MultipleTermPositions.java Fri Feb 26 13:09:54 2010
@@ -17,14 +17,14 @@
* limitations under the License.
*/
-import org.apache.lucene.util.PriorityQueue;
-
import java.io.IOException;
import java.util.Arrays;
-
import java.util.LinkedList;
import java.util.List;
+import org.apache.lucene.util.PriorityQueue;
+import org.apache.lucene.util.ArrayUtil;
+
/**
* Allows you to iterate over the {@link TermPositions} for multiple {@link Term}s as
* a single {@link TermPositions}.
@@ -85,10 +85,8 @@
}
private void growArray() {
- int[] newArray = new int[_arraySize * 2];
- System.arraycopy(_array, 0, newArray, 0, _arraySize);
- _array = newArray;
- _arraySize *= 2;
+ _array = ArrayUtil.grow(_array, _arraySize+1);
+ _arraySize = _array.length;
}
}
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/NormsWriterPerField.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/NormsWriterPerField.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/NormsWriterPerField.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/NormsWriterPerField.java Fri Feb 26 13:09:54 2010
@@ -63,11 +63,13 @@
@Override
void finish() {
- assert docIDs.length == norms.length;
if (fieldInfo.isIndexed && !fieldInfo.omitNorms) {
if (docIDs.length <= upto) {
assert docIDs.length == upto;
docIDs = ArrayUtil.grow(docIDs, 1+upto);
+ }
+ if (norms.length <= upto) {
+ assert norms.length == upto;
norms = ArrayUtil.grow(norms, 1+upto);
}
final float norm = docState.similarity.computeNorm(fieldInfo.name, fieldState);
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfo.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfo.java Fri Feb 26 13:09:54 2010
@@ -34,8 +34,7 @@
* Information about a segment such as it's name, directory, and files related
* to the segment.
*
- * * <p><b>NOTE:</b> This API is new and still experimental
- * (subject to change suddenly in the next release)</p>
+ * @lucene.experimental
*/
public final class SegmentInfo {
@@ -558,6 +557,7 @@
*/
void write(IndexOutput output)
throws IOException {
+ assert delCount <= docCount: "delCount=" + delCount + " docCount=" + docCount + " segment=" + name;
output.writeString(name);
output.writeInt(docCount);
output.writeLong(delGen);
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfos.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentInfos.java Fri Feb 26 13:09:54 2010
@@ -41,8 +41,7 @@
* A collection of segmentInfo objects with methods for operating on
* those segments in relation to the file system.
*
- * <p><b>NOTE:</b> This API is new and still experimental
- * (subject to change suddenly in the next release)</p>
+ * @lucene.experimental
*/
public final class SegmentInfos extends Vector<SegmentInfo> {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentReader.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SegmentReader.java Fri Feb 26 13:09:54 2010
@@ -49,10 +49,8 @@
import org.apache.lucene.search.FieldCache; // not great (circular); used only to purge FieldCache entry on close
import org.apache.lucene.util.BytesRef;
-/** @version $Id */
/**
- * <p><b>NOTE:</b> This API is new and still experimental
- * (subject to change suddenly in the next release)</p>
+ * @lucene.experimental
*/
public class SegmentReader extends IndexReader implements Cloneable {
protected boolean readOnly;
@@ -205,7 +203,11 @@
storeCFSReader.close();
}
- // Force FieldCache to evict our entries at this point
+ // Force FieldCache to evict our entries at this
+ // point. If the exception occurred while
+ // initializing the core readers, then
+ // origInstance will be null, and we don't want
+ // to call FieldCache.purge (it leads to NPE):
if (origInstance != null) {
FieldCache.DEFAULT.purge(origInstance);
}
@@ -583,7 +585,7 @@
deletedDocsRef = new AtomicInteger(1);
assert checkDeletedCounts();
if (deletedDocs.size() != si.docCount) {
- throw new CorruptIndexException("document count mismatch: deleted docs count " + deletedDocs.size() + " vs segment doc count " + si.docCount);
+ throw new CorruptIndexException("document count mismatch: deleted docs count " + deletedDocs.size() + " vs segment doc count " + si.docCount + " segment=" + si.name);
}
} else
assert si.getDelCount() == 0;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java Fri Feb 26 13:09:54 2010
@@ -39,8 +39,7 @@
* snapshot held when a writer is closed will "survive"
* when the next writer is opened.
*
- * <p><b>WARNING</b>: This API is a new and experimental and
- * may suddenly change.</p> */
+ * @lucene.experimental */
public class SnapshotDeletionPolicy implements IndexDeletionPolicy {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/StoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/StoredFieldsWriter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/StoredFieldsWriter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/StoredFieldsWriter.java Fri Feb 26 13:09:54 2010
@@ -20,6 +20,7 @@
import java.io.IOException;
import org.apache.lucene.store.RAMOutputStream;
import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.RamUsageEstimator;
/** This is a DocFieldConsumer that writes stored fields. */
final class StoredFieldsWriter {
@@ -108,7 +109,7 @@
// enough space to recycle all outstanding PerDoc
// instances
assert allocCount == 1+docFreeList.length;
- docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)];
+ docFreeList = new PerDoc[ArrayUtil.oversize(allocCount, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
}
return new PerDoc();
} else
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsReader.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsReader.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsReader.java Fri Feb 26 13:09:54 2010
@@ -20,6 +20,7 @@
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.ArrayUtil;
import java.io.IOException;
import java.util.Arrays;
@@ -460,18 +461,14 @@
if (preUTF8) {
// Term stored as java chars
if (charBuffer.length < totalLength) {
- char[] newCharBuffer = new char[(int) (1.5*totalLength)];
- System.arraycopy(charBuffer, 0, newCharBuffer, 0, start);
- charBuffer = newCharBuffer;
+ charBuffer = ArrayUtil.grow(charBuffer, totalLength);
}
tvf.readChars(charBuffer, start, deltaLength);
term = new String(charBuffer, 0, totalLength);
} else {
// Term stored as utf8 bytes
if (byteBuffer.length < totalLength) {
- byte[] newByteBuffer = new byte[(int) (1.5*totalLength)];
- System.arraycopy(byteBuffer, 0, newByteBuffer, 0, start);
- byteBuffer = newByteBuffer;
+ byteBuffer = ArrayUtil.grow(byteBuffer, totalLength);
}
tvf.readBytes(byteBuffer, start, deltaLength);
term = new String(byteBuffer, 0, totalLength, "UTF-8");
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java Fri Feb 26 13:09:54 2010
@@ -20,6 +20,7 @@
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RAMOutputStream;
import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.RamUsageEstimator;
import java.io.IOException;
import java.util.Collection;
@@ -117,7 +118,7 @@
// enough space to recycle all outstanding PerDoc
// instances
assert allocCount == 1+docFreeList.length;
- docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)];
+ docFreeList = new PerDoc[ArrayUtil.oversize(allocCount, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
}
return new PerDoc();
} else
@@ -266,6 +267,8 @@
void addField(final int fieldNumber) {
if (numVectorFields == fieldNumbers.length) {
fieldNumbers = ArrayUtil.grow(fieldNumbers);
+ }
+ if (numVectorFields == fieldPointers.length) {
fieldPointers = ArrayUtil.grow(fieldPointers);
}
fieldNumbers[numVectorFields] = fieldNumber;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermsHash.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermsHash.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermsHash.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermsHash.java Fri Feb 26 13:09:54 2010
@@ -26,6 +26,7 @@
import java.io.IOException;
import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.RamUsageEstimator;
/** This class implements {@link InvertedDocConsumer}, which
* is passed each token produced by the analyzer on each
@@ -92,7 +93,7 @@
assert postingsFreeCount == postingsAllocCount: Thread.currentThread().getName() + ": postingsFreeCount=" + postingsFreeCount + " postingsAllocCount=" + postingsAllocCount + " consumer=" + consumer;
- final int newSize = ArrayUtil.getShrinkSize(postingsFreeList.length, postingsAllocCount);
+ final int newSize = ArrayUtil.getShrinkSize(postingsFreeList.length, postingsAllocCount, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
if (newSize != postingsFreeList.length) {
RawPostingList[] newArray = new RawPostingList[newSize];
System.arraycopy(postingsFreeList, 0, newArray, 0, postingsFreeCount);
@@ -225,7 +226,7 @@
if (newPostingsAllocCount > postingsFreeList.length)
// Pre-allocate the postingsFreeList so it's large
// enough to hold all postings we've given out
- postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
+ postingsFreeList = new RawPostingList[ArrayUtil.oversize(newPostingsAllocCount, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
}
postingsFreeCount -= numToCopy;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsWriterImpl.java Fri Feb 26 13:09:54 2010
@@ -26,6 +26,7 @@
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.RamUsageEstimator;
// TODO: we now pulse entirely according to docFreq of the
// term; it might be better to eg pulse by "net bytes used"
@@ -81,7 +82,7 @@
}
void reallocPositions(int minSize) {
- final Position[] newArray = new Position[ArrayUtil.getNextSize(minSize)];
+ final Position[] newArray = new Position[ArrayUtil.oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(positions, 0, newArray, 0, positions.length);
for(int i=positions.length;i<newArray.length;i++) {
newArray[i] = new Position();
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/standard/SimpleStandardTermsIndexReader.java Fri Feb 26 13:09:54 2010
@@ -23,6 +23,7 @@
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.index.codecs.Codec;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.util.ArrayUtil;
@@ -339,7 +340,7 @@
// New block
final byte[] newBlock = new byte[BYTE_BLOCK_SIZE];
if (blocks.length == blockUpto+1) {
- final int newSize = ArrayUtil.getNextSize(blockUpto+2);
+ final int newSize = ArrayUtil.oversize(blockUpto+2, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
final byte[][] newBlocks = new byte[newSize][];
System.arraycopy(blocks, 0, newBlocks, 0, blocks.length);
blocks = newBlocks;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Collector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Collector.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Collector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Collector.java Fri Feb 26 13:09:54 2010
@@ -116,8 +116,7 @@
* you need that behavior, use {@link
* PositiveScoresOnlyCollector}.</p>
*
- * <p><b>NOTE:</b> This API is experimental and might change
- * in incompatible ways in the next release.</p>
+ * @lucene.experimental
*
* @since 2.9
*/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/DefaultSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/DefaultSimilarity.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/DefaultSimilarity.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/DefaultSimilarity.java Fri Feb 26 13:09:54 2010
@@ -29,8 +29,7 @@
* FieldInvertState#getLength()} - {@link
* FieldInvertState#getNumOverlap()}.
*
- * <p><b>WARNING</b>: This API is new and experimental, and may suddenly
- * change.</p> */
+ * @lucene.experimental */
@Override
public float computeNorm(String field, FieldInvertState state) {
final int numTerms;
@@ -85,8 +84,7 @@
* norm. By default this is false, meaning overlap
* tokens are counted just like non-overlap tokens.
*
- * <p><b>WARNING</b>: This API is new and experimental, and may suddenly
- * change.</p>
+ * @lucene.experimental
*
* @see #computeNorm
*/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCache.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCache.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCache.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCache.java Fri Feb 26 13:09:54 2010
@@ -516,12 +516,7 @@
/**
* EXPERT: A unique Identifier/Description for each item in the FieldCache.
* Can be useful for logging/debugging.
- * <p>
- * <b>EXPERIMENTAL API:</b> This API is considered extremely advanced
- * and experimental. It may be removed or altered w/o warning in future
- * releases
- * of Lucene.
- * </p>
+ * @lucene.experimental
*/
public static abstract class CacheEntry {
public abstract Object getReaderKey();
@@ -586,12 +581,7 @@
* associated with it has garbage collected will prevent the Value itself
* from being garbage collected when the Cache drops the WeakReference.
* </p>
- * <p>
- * <b>EXPERIMENTAL API:</b> This API is considered extremely advanced
- * and experimental. It may be removed or altered w/o warning in future
- * releases
- * of Lucene.
- * </p>
+ * @lucene.experimental
*/
public abstract CacheEntry[] getCacheEntries();
@@ -604,12 +594,7 @@
* It should not be relied on for "Cache maintenance" in general
* application code.
* </p>
- * <p>
- * <b>EXPERIMENTAL API:</b> This API is considered extremely advanced
- * and experimental. It may be removed or altered w/o warning in future
- * releases
- * of Lucene.
- * </p>
+ * @lucene.experimental
*/
public abstract void purgeAllCaches();
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldCacheImpl.java Fri Feb 26 13:09:54 2010
@@ -61,27 +61,26 @@
caches.put(StringIndex.class, new StringIndexCache(this));
}
- public void purgeAllCaches() {
+ public synchronized void purgeAllCaches() {
init();
}
- public void purge(IndexReader r) {
+ public synchronized void purge(IndexReader r) {
for(Cache c : caches.values()) {
c.purge(r);
}
}
- public CacheEntry[] getCacheEntries() {
+ public synchronized CacheEntry[] getCacheEntries() {
List<CacheEntry> result = new ArrayList<CacheEntry>(17);
- for(final Class<?> cacheType: caches.keySet()) {
- Cache cache = caches.get(cacheType);
- for (final Object readerKey : cache.readerCache.keySet()) {
- // we've now materialized a hard ref
-
- // innerKeys was backed by WeakHashMap, sanity check
- // that it wasn't GCed before we made hard ref
- if (null != readerKey && cache.readerCache.containsKey(readerKey)) {
- Map<Entry, Object> innerCache = cache.readerCache.get(readerKey);
+ for(final Map.Entry<Class<?>,Cache> cacheEntry: caches.entrySet()) {
+ final Cache cache = cacheEntry.getValue();
+ final Class<?> cacheType = cacheEntry.getKey();
+ synchronized(cache.readerCache) {
+ for (final Map.Entry<Object,Map<Entry, Object>> readerCacheEntry : cache.readerCache.entrySet()) {
+ final Object readerKey = readerCacheEntry.getKey();
+ if (readerKey == null) continue;
+ final Map<Entry, Object> innerCache = readerCacheEntry.getValue();
for (final Map.Entry<Entry, Object> mapEntry : innerCache.entrySet()) {
Entry entry = mapEntry.getKey();
result.add(new CacheEntryImpl(readerKey, entry.field,
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparator.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparator.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparator.java Fri Feb 26 13:09:54 2010
@@ -79,8 +79,7 @@
* FieldDoc#fields} when returning the top results.
* </ul>
*
- * <b>NOTE:</b> This API is experimental and might change in
- * incompatible ways in the next release.
+ * @lucene.experimental
*/
public abstract class FieldComparator {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparatorSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparatorSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparatorSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldComparatorSource.java Fri Feb 26 13:09:54 2010
@@ -23,8 +23,7 @@
/**
* Provides a {@link FieldComparator} for custom field sorting.
*
- * <b>NOTE:</b> This API is experimental and might change in
- * incompatible ways in the next release.
+ * @lucene.experimental
*
*/
public abstract class FieldComparatorSource implements Serializable {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldValueHitQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldValueHitQueue.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldValueHitQueue.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FieldValueHitQueue.java Fri Feb 26 13:09:54 2010
@@ -26,11 +26,8 @@
* Uses <code>FieldCache.DEFAULT</code> for maintaining
* internal term lookup tables.
*
- * <b>NOTE:</b> This API is experimental and might change in
- * incompatible ways in the next release.
- *
+ * @lucene.experimental
* @since 2.9
- * @version $Id:
* @see Searcher#search(Query,Filter,int,Sort)
* @see FieldCache
*/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Filter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Filter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Filter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Filter.java Fri Feb 26 13:09:54 2010
@@ -23,21 +23,20 @@
import org.apache.lucene.util.DocIdBitSet;
/**
- * Abstract base class providing a mechanism to use a subset of an index
- * for restriction or permission of index search results.
- * <p>
+ * Abstract base class for restricting which documents may
+ * be returned during searching.
*/
public abstract class Filter implements java.io.Serializable {
/**
- * Creates a {@link DocIdSet} that provides the documents which should be
- * permitted or prohibited in search results. <b>NOTE:</b> null can be
- * returned if no documents will be accepted by this Filter.
+ * Creates a {@link DocIdSet} enumerating the documents that should be
+ * permitted in search results. <b>NOTE:</b> null can be
+ * returned if no documents are accepted by this Filter.
* <p>
- * Note: This method might be called more than once during a search if the
- * index has more than one segment. In such a case the {@link DocIdSet}
- * must be relative to the document base of the given reader. Yet, the
- * segment readers are passed in increasing document base order.
+ * Note: This method will be called once per segment in
+ * the index during searching. The returned {@link DocIdSet}
+ * must refer to document IDs for that segment, not for
+ * the top-level reader.
*
* @param reader a {@link IndexReader} instance opened on the index currently
* searched on. Note, it is likely that the provided reader does not
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyQuery.java Fri Feb 26 13:09:54 2010
@@ -31,7 +31,7 @@
* length of 0 - in this case, *every* term will be enumerated and
* cause an edit score calculation.
*
- * <p>This query uses {@link MultiTermQuery#TOP_TERMS_SCORING_BOOLEAN_REWRITE}
+ * <p>This query uses {@link MultiTermQuery.TopTermsScoringBooleanQueryRewrite}
* as default. So terms will be collected and scored according to their
* edit distance. Only the top terms are used for building the {@link BooleanQuery}.
* It is not recommended to change the rewrite mode for fuzzy queries.
@@ -40,6 +40,7 @@
public final static float defaultMinSimilarity = 0.5f;
public final static int defaultPrefixLength = 0;
+ public final static int defaultMaxExpansions = Integer.MAX_VALUE;
private float minimumSimilarity;
private int prefixLength;
@@ -60,13 +61,16 @@
* as the query term is considered similar to the query term if the edit distance
* between both terms is less than <code>length(term)*0.5</code>
* @param prefixLength length of common (non-fuzzy) prefix
+ * @param maxExpansions the maximum number of terms to match. If this number is
+ * greater than {@link BooleanQuery#getMaxClauseCount} when the query is rewritten,
+ * then the maxClauseCount will be used instead.
* @throws IllegalArgumentException if minimumSimilarity is >= 1 or < 0
* or if prefixLength < 0
*/
- public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) throws IllegalArgumentException {
+ public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength,
+ int maxExpansions) {
super(term.field());
this.term = term;
- setRewriteMethod(TOP_TERMS_SCORING_BOOLEAN_REWRITE);
if (minimumSimilarity >= 1.0f)
throw new IllegalArgumentException("minimumSimilarity >= 1");
@@ -74,6 +78,10 @@
throw new IllegalArgumentException("minimumSimilarity < 0");
if (prefixLength < 0)
throw new IllegalArgumentException("prefixLength < 0");
+ if (maxExpansions < 0)
+ throw new IllegalArgumentException("maxExpansions < 0");
+
+ setRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(maxExpansions));
if (term.text().length() > 1.0f / (1.0f - minimumSimilarity)) {
this.termLongEnough = true;
@@ -84,17 +92,24 @@
}
/**
- * Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0)}.
+ * Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, prefixLength, Integer.MAX_VALUE)}.
+ */
+ public FuzzyQuery(Term term, float minimumSimilarity, int prefixLength) {
+ this(term, minimumSimilarity, prefixLength, defaultMaxExpansions);
+ }
+
+ /**
+ * Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, minimumSimilarity, 0, Integer.MAX_VALUE)}.
*/
- public FuzzyQuery(Term term, float minimumSimilarity) throws IllegalArgumentException {
- this(term, minimumSimilarity, defaultPrefixLength);
+ public FuzzyQuery(Term term, float minimumSimilarity) {
+ this(term, minimumSimilarity, defaultPrefixLength, defaultMaxExpansions);
}
/**
- * Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0)}.
+ * Calls {@link #FuzzyQuery(Term, float) FuzzyQuery(term, 0.5f, 0, Integer.MAX_VALUE)}.
*/
public FuzzyQuery(Term term) {
- this(term, defaultMinSimilarity, defaultPrefixLength);
+ this(term, defaultMinSimilarity, defaultPrefixLength, defaultMaxExpansions);
}
/**
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyTermEnum.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyTermEnum.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/FuzzyTermEnum.java Fri Feb 26 13:09:54 2010
@@ -193,7 +193,7 @@
* @return the similarity, 0.0 or less indicates that it matches less than the required
* threshold and 1.0 indicates that the text and target are identical
*/
- private synchronized final float similarity(final String target) {
+ private float similarity(final String target) {
final int m = target.length();
final int n = text.length();
if (n == 0) {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/IndexSearcher.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/IndexSearcher.java Fri Feb 26 13:09:54 2010
@@ -86,9 +86,7 @@
/** Expert: directly specify the reader, subReaders and
* their docID starts.
*
- * <p><b>NOTE:</b> This API is experimental and
- * might change in incompatible ways in the next
- * release.</font></p> */
+ * @lucene.experimental */
public IndexSearcher(IndexReader reader, IndexReader[] subReaders, int[] docStarts) {
this.reader = reader;
this.subReaders = subReaders;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQuery.java Fri Feb 26 13:09:54 2010
@@ -55,7 +55,7 @@
* computing unhelpful scores, and it tries to pick the most
* performant rewrite method given the query. If you
* need scoring (like {@link FuzzyQuery}, use
- * {@link #TOP_TERMS_SCORING_BOOLEAN_REWRITE} which uses
+ * {@link TopTermsScoringBooleanQueryRewrite} which uses
* a priority queue to only collect competitive terms
* and not hit this limitation.
*
@@ -268,10 +268,41 @@
* @see #setRewriteMethod */
public final static RewriteMethod SCORING_BOOLEAN_QUERY_REWRITE = new ScoringBooleanQueryRewrite();
- private static final class TopTermsScoringBooleanQueryRewrite extends BooleanQueryRewrite {
+ /** A rewrite method that first translates each term into
+ * {@link BooleanClause.Occur#SHOULD} clause in a
+ * BooleanQuery, and keeps the scores as computed by the
+ * query.
+ *
+ * <p>This rewrite mode only uses the top scoring terms
+ * so it will not overflow the boolean max clause count.
+ * It is the default rewrite mode for {@link FuzzyQuery}.
+ *
+ * @see #setRewriteMethod */
+ public static final class TopTermsScoringBooleanQueryRewrite extends BooleanQueryRewrite {
+ private final int size;
+
+ /**
+ * Create a TopTermsScoringBooleanQueryRewrite for
+ * at most <code>size</code> terms.
+ * <p>
+ * NOTE: if {@link BooleanQuery#getMaxClauseCount} is smaller than
+ * <code>size</code>, then it will be used instead.
+ */
+ public TopTermsScoringBooleanQueryRewrite(int size) {
+ this.size = size;
+ }
+
+ /**
+ * Create a TopTermsScoringBooleanQueryRewrite that is limited
+ * to at most {@link BooleanQuery#getMaxClauseCount} terms.
+ */
+ public TopTermsScoringBooleanQueryRewrite() {
+ this(Integer.MAX_VALUE);
+ }
+
@Override
public Query rewrite(IndexReader reader, MultiTermQuery query) throws IOException {
- final int maxSize = BooleanQuery.getMaxClauseCount();
+ final int maxSize = Math.min(size, BooleanQuery.getMaxClauseCount());
final PriorityQueue<ScoreTerm> stQueue = new PriorityQueue<ScoreTerm>();
collectTerms(reader, query, new TermCollector() {
public boolean collect(Term t, float boost) {
@@ -301,10 +332,23 @@
query.incTotalNumberOfTerms(bq.clauses().size());
return bq;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 17;
+ int result = 1;
+ result = prime * result + size;
+ return result;
+ }
- // Make sure we are still a singleton even after deserializing
- protected Object readResolve() {
- return TOP_TERMS_SCORING_BOOLEAN_REWRITE;
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ TopTermsScoringBooleanQueryRewrite other = (TopTermsScoringBooleanQueryRewrite) obj;
+ if (size != other.size) return false;
+ return true;
}
private static class ScoreTerm implements Comparable<ScoreTerm> {
@@ -319,18 +363,6 @@
}
}
}
-
- /** A rewrite method that first translates each term into
- * {@link BooleanClause.Occur#SHOULD} clause in a
- * BooleanQuery, and keeps the scores as computed by the
- * query.
- *
- * <p>This rewrite mode only uses the top scoring terms
- * so it will not overflow the boolean max clause count.
- * It is the default rewrite mode for {@link FuzzyQuery}.
- *
- * @see #setRewriteMethod */
- public final static RewriteMethod TOP_TERMS_SCORING_BOOLEAN_REWRITE = new TopTermsScoringBooleanQueryRewrite();
private static class ConstantScoreBooleanQueryRewrite extends ScoringBooleanQueryRewrite implements Serializable {
@Override
Propchange: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Feb 26 13:09:54 2010
@@ -0,0 +1 @@
+/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:909334
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeFilter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeFilter.java Fri Feb 26 13:09:54 2010
@@ -39,9 +39,7 @@
* See {@link NumericRangeQuery} for details on how Lucene
* indexes and searches numeric valued fields.
*
- * <p><font color="red"><b>NOTE:</b> This API is experimental and
- * might change in incompatible ways in the next
- * release.</font>
+ * @lucene.experimental
*
* @since 2.9
**/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/NumericRangeQuery.java Fri Feb 26 13:09:54 2010
@@ -74,8 +74,7 @@
* BooleanQuery rewrite methods without changing
* BooleanQuery's default max clause count.
*
- * <p><font color="red"><b>NOTE:</b> This API is experimental and
- * might change in incompatible ways in the next release.</font>
+ * @lucene.experimental
*
* <br><h3>How it works</h3>
*
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/ParallelMultiSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/ParallelMultiSearcher.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/ParallelMultiSearcher.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/ParallelMultiSearcher.java Fri Feb 26 13:09:54 2010
@@ -175,7 +175,13 @@
searchables[i].search(weight, filter, hc);
}
}
-
+
+ @Override
+ public void close() throws IOException {
+ executor.shutdown();
+ super.close();
+ }
+
@Override
HashMap<Term, Integer> createDocFrequencyMap(Set<Term> terms) throws IOException {
final Term[] allTermsArray = terms.toArray(new Term[terms.size()]);
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Query.java Fri Feb 26 13:09:54 2010
@@ -101,6 +101,8 @@
Weight weight = query.createWeight(searcher);
float sum = weight.sumOfSquaredWeights();
float norm = getSimilarity(searcher).queryNorm(sum);
+ if (Float.isInfinite(norm) || Float.isNaN(norm))
+ norm = 1.0f;
weight.normalize(norm);
return weight;
}
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryWrapperFilter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryWrapperFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/QueryWrapperFilter.java Fri Feb 26 13:09:54 2010
@@ -31,8 +31,6 @@
* QueryFilter that matches, e.g., only documents modified within the last
* week. The QueryFilter and TermRangeQuery would only need to be reconstructed
* once per day.
- *
- * @version $Id:$
*/
public class QueryWrapperFilter extends Filter {
private Query query;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/Similarity.java Fri Feb 26 13:09:54 2010
@@ -602,8 +602,7 @@
* {@link FieldInvertState#getLength()} as the second argument, and
* then multiplies this value by {@link FieldInvertState#getBoost()}.</p>
*
- * <p><b>WARNING</b>: This API is new and experimental and may
- * suddenly change.</p>
+ * @lucene.experimental
*
* @param field field name
* @param state current processing state for this field
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SortField.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SortField.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SortField.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SortField.java Fri Feb 26 13:09:54 2010
@@ -365,8 +365,7 @@
/** Returns the {@link FieldComparator} to use for
* sorting.
*
- * <b>NOTE:</b> This API is experimental and might change in
- * incompatible ways in the next release.
+ * @lucene.experimental
*
* @param numHits number of top hits the queue will store
* @param sortPos position of this SortField within {@link
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanFilterResult.java Fri Feb 26 13:09:54 2010
@@ -23,8 +23,7 @@
/**
* The results of a SpanQueryFilter. Wraps the BitSet and the position information from the SpanQuery
*
- *<p/>
- * NOTE: This API is still experimental and subject to change.
+ * @lucene.experimental
*
**/
public class SpanFilterResult {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/SpanQueryFilter.java Fri Feb 26 13:09:54 2010
@@ -34,9 +34,6 @@
* <p/>
* This filter does not cache. See the {@link org.apache.lucene.search.CachingSpanFilter} for a wrapper that
* caches.
- *
- *
- * @version $Id:$
*/
public class SpanQueryFilter extends SpanFilter {
protected SpanQuery query;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopFieldCollector.java Fri Feb 26 13:09:54 2010
@@ -30,8 +30,7 @@
* See the {@link #create(org.apache.lucene.search.Sort, int, boolean, boolean, boolean, boolean)} method
* for instantiating a TopFieldCollector.
*
- * <p><b>NOTE:</b> This API is experimental and might change in
- * incompatible ways in the next release.</p>
+ * @lucene.experimental
*/
public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/TopScoreDocCollector.java Fri Feb 26 13:09:54 2010
@@ -29,10 +29,10 @@
* instance of this collector you should know in advance whether documents are
* going to be collected in doc Id order or not.
*
- * <p><b>NOTE</b>: The values Float.Nan,
- * Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are
- * not valid scores. This collector will not properly
- * collect hits with such scores.
+ * <p><b>NOTE</b>: The values {@link Float#NaN} and
+ * {Float#NEGATIVE_INFINITY} are not valid scores. This
+ * collector will not properly collect hits with such
+ * scores.
*/
public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
@@ -45,6 +45,11 @@
@Override
public void collect(int doc) throws IOException {
float score = scorer.score();
+
+ // This collector cannot handle these scores:
+ assert score != Float.NEGATIVE_INFINITY;
+ assert !Float.isNaN(score);
+
totalHits++;
if (score <= pqTop.score) {
// Since docs are returned in-order (i.e., increasing doc Id), a document
@@ -72,6 +77,10 @@
@Override
public void collect(int doc) throws IOException {
float score = scorer.score();
+
+ // This collector cannot handle NaN
+ assert !Float.isNaN(score);
+
totalHits++;
doc += docBase;
if (score < pqTop.score || (score == pqTop.score && doc > pqTop.doc)) {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ByteFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ByteFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ByteFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ByteFieldSource.java Fri Feb 26 13:09:54 2010
@@ -29,10 +29,7 @@
* using <code>getBytes()</code> and makes those values
* available as other numeric types, casting as needed.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* @see org.apache.lucene.search.function.FieldCacheSource for requirements
* on the field.
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/CustomScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/CustomScoreQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/CustomScoreQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/CustomScoreQuery.java Fri Feb 26 13:09:54 2010
@@ -40,12 +40,9 @@
* For most simple/convenient use cases this query is likely to be a
* {@link org.apache.lucene.search.function.FieldScoreQuery FieldScoreQuery}</li>
* </ol>
- * Subclasses can modify the computation by overriding {@link #customScore(int, float, float)}.
+ * Subclasses can modify the computation by overriding {@link #getCustomScoreProvider}.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*/
public class CustomScoreQuery extends Query {
@@ -83,7 +80,6 @@
* This parameter is optional - it can be null or even an empty array.
*/
public CustomScoreQuery(Query subQuery, ValueSourceQuery... valSrcQueries) {
- super();
this.subQuery = subQuery;
this.valSrcQueries = valSrcQueries!=null?
valSrcQueries : new ValueSourceQuery[0];
@@ -93,11 +89,23 @@
/*(non-Javadoc) @see org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader) */
@Override
public Query rewrite(IndexReader reader) throws IOException {
- subQuery = subQuery.rewrite(reader);
+ CustomScoreQuery clone = null;
+
+ final Query sq = subQuery.rewrite(reader);
+ if (sq != subQuery) {
+ clone = (CustomScoreQuery) clone();
+ clone.subQuery = sq;
+ }
+
for(int i = 0; i < valSrcQueries.length; i++) {
- valSrcQueries[i] = (ValueSourceQuery) valSrcQueries[i].rewrite(reader);
+ final ValueSourceQuery v = (ValueSourceQuery) valSrcQueries[i].rewrite(reader);
+ if (v != valSrcQueries[i]) {
+ if (clone == null) clone = (CustomScoreQuery) clone();
+ clone.valSrcQueries[i] = v;
+ }
}
- return this;
+
+ return (clone == null) ? this : clone;
}
/*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
@@ -142,7 +150,8 @@
}
CustomScoreQuery other = (CustomScoreQuery)o;
if (this.getBoost() != other.getBoost() ||
- !this.subQuery.equals(other.subQuery)||
+ !this.subQuery.equals(other.subQuery) ||
+ this.strict != other.strict ||
this.valSrcQueries.length != other.valSrcQueries.length) {
return false;
}
@@ -153,132 +162,17 @@
@Override
public int hashCode() {
return (getClass().hashCode() + subQuery.hashCode() + Arrays.hashCode(valSrcQueries))
- ^ Float.floatToIntBits(getBoost());
- }
-
- /**
- * Compute a custom score by the subQuery score and a number of
- * ValueSourceQuery scores.
- * <p>
- * Subclasses can override this method to modify the custom score.
- * <p>
- * If your custom scoring is different than the default herein you
- * should override at least one of the two customScore() methods.
- * If the number of ValueSourceQueries is always < 2 it is
- * sufficient to override the other
- * {@link #customScore(int, float, float) customScore()}
- * method, which is simpler.
- * <p>
- * The default computation herein is a multiplication of given scores:
- * <pre>
- * ModifiedScore = valSrcScore * valSrcScores[0] * valSrcScores[1] * ...
- * </pre>
- *
- * @param doc id of scored doc.
- * @param subQueryScore score of that doc by the subQuery.
- * @param valSrcScores scores of that doc by the ValueSourceQuery.
- * @return custom score.
- */
- public float customScore(int doc, float subQueryScore, float valSrcScores[]) {
- if (valSrcScores.length == 1) {
- return customScore(doc, subQueryScore, valSrcScores[0]);
- }
- if (valSrcScores.length == 0) {
- return customScore(doc, subQueryScore, 1);
- }
- float score = subQueryScore;
- for(int i = 0; i < valSrcScores.length; i++) {
- score *= valSrcScores[i];
- }
- return score;
- }
-
- /**
- * Compute a custom score by the subQuery score and the ValueSourceQuery score.
- * <p>
- * Subclasses can override this method to modify the custom score.
- * <p>
- * If your custom scoring is different than the default herein you
- * should override at least one of the two customScore() methods.
- * If the number of ValueSourceQueries is always < 2 it is
- * sufficient to override this customScore() method, which is simpler.
- * <p>
- * The default computation herein is a multiplication of the two scores:
- * <pre>
- * ModifiedScore = subQueryScore * valSrcScore
- * </pre>
- *
- * <p><b>NOTE</b>: The doc is relative to the current
- * reader, last passed to {@link #setNextReader}.
- *
- * @param doc id of scored doc.
- * @param subQueryScore score of that doc by the subQuery.
- * @param valSrcScore score of that doc by the ValueSourceQuery.
- * @return custom score.
- */
- public float customScore(int doc, float subQueryScore, float valSrcScore) {
- return subQueryScore * valSrcScore;
- }
-
- /**
- * Called when the scoring switches to another reader.
- *
- * @param reader
- * next IndexReader
- */
- public void setNextReader(IndexReader reader) throws IOException {
- }
-
- /**
- * Explain the custom score.
- * Whenever overriding {@link #customScore(int, float, float[])},
- * this method should also be overridden to provide the correct explanation
- * for the part of the custom scoring.
- *
- * @param doc doc being explained.
- * @param subQueryExpl explanation for the sub-query part.
- * @param valSrcExpls explanation for the value source part.
- * @return an explanation for the custom score
- */
- public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpls[]) {
- if (valSrcExpls.length == 1) {
- return customExplain(doc, subQueryExpl, valSrcExpls[0]);
- }
- if (valSrcExpls.length == 0) {
- return subQueryExpl;
- }
- float valSrcScore = 1;
- for (int i = 0; i < valSrcExpls.length; i++) {
- valSrcScore *= valSrcExpls[i].getValue();
- }
- Explanation exp = new Explanation( valSrcScore * subQueryExpl.getValue(), "custom score: product of:");
- exp.addDetail(subQueryExpl);
- for (int i = 0; i < valSrcExpls.length; i++) {
- exp.addDetail(valSrcExpls[i]);
- }
- return exp;
+ ^ Float.floatToIntBits(getBoost()) ^ (strict ? 1234 : 4321);
}
-
+
/**
- * Explain the custom score.
- * Whenever overriding {@link #customScore(int, float, float)},
- * this method should also be overridden to provide the correct explanation
- * for the part of the custom scoring.
- *
- * @param doc doc being explained.
- * @param subQueryExpl explanation for the sub-query part.
- * @param valSrcExpl explanation for the value source part.
- * @return an explanation for the custom score
+ * Returns a {@link CustomScoreProvider} that calculates the custom scores
+ * for the given {@link IndexReader}. The default implementation returns a default
+ * implementation as specified in the docs of {@link CustomScoreProvider}.
+ * @since 2.9.2
*/
- public Explanation customExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl) {
- float valSrcScore = 1;
- if (valSrcExpl != null) {
- valSrcScore *= valSrcExpl.getValue();
- }
- Explanation exp = new Explanation( valSrcScore * subQueryExpl.getValue(), "custom score: product of:");
- exp.addDetail(subQueryExpl);
- exp.addDetail(valSrcExpl);
- return exp;
+ protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) throws IOException {
+ return new CustomScoreProvider(reader);
}
//=========================== W E I G H T ============================
@@ -374,7 +268,7 @@
for(int i = 0; i < valSrcWeights.length; i++) {
valSrcExpls[i] = valSrcWeights[i].explain(reader, doc);
}
- Explanation customExp = customExplain(doc,subQueryExpl,valSrcExpls);
+ Explanation customExp = CustomScoreQuery.this.getCustomScoreProvider(reader).customExplain(doc,subQueryExpl,valSrcExpls);
float sc = getValue() * customExp.getValue();
Explanation res = new ComplexExplanation(
true, sc, CustomScoreQuery.this.toString() + ", product of:");
@@ -401,6 +295,7 @@
private Scorer subQueryScorer;
private Scorer[] valSrcScorers;
private IndexReader reader;
+ private final CustomScoreProvider provider;
private float vScores[]; // reused in score() to avoid allocating this array for each doc
// constructor
@@ -412,7 +307,7 @@
this.valSrcScorers = valSrcScorers;
this.reader = reader;
this.vScores = new float[valSrcScorers.length];
- setNextReader(reader);
+ this.provider = CustomScoreQuery.this.getCustomScoreProvider(reader);
}
@Override
@@ -437,7 +332,7 @@
for (int i = 0; i < valSrcScorers.length; i++) {
vScores[i] = valSrcScorers[i].score();
}
- return qWeight * customScore(subQueryScorer.docID(), subQueryScorer.score(), vScores);
+ return qWeight * provider.customScore(subQueryScorer.docID(), subQueryScorer.score(), vScores);
}
@Override
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/DocValues.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/DocValues.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/DocValues.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/DocValues.java Fri Feb 26 13:09:54 2010
@@ -25,10 +25,7 @@
* {@link org.apache.lucene.search.function.ValueSource ValueSuorce}
* for a particular field and reader.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
*
*/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldCacheSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldCacheSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldCacheSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldCacheSource.java Fri Feb 26 13:09:54 2010
@@ -34,10 +34,7 @@
* <p>
* Document with no tokens in this field are assigned the <code>Zero</code> value.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* <p><b>NOTE</b>: with the switch in 2.9 to segment-based
* searching, if {@link #getValues} is invoked with a
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldScoreQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldScoreQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FieldScoreQuery.java Fri Feb 26 13:09:54 2010
@@ -52,10 +52,7 @@
* otherwise, for instance if for each query a new index reader is opened, large penalties would be
* paid for loading the field values into memory over and over again!
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*/
public class FieldScoreQuery extends ValueSourceQuery {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FloatFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FloatFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FloatFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/FloatFieldSource.java Fri Feb 26 13:09:54 2010
@@ -29,10 +29,7 @@
* using <code>getFloats()</code> and makes those values
* available as other numeric types, casting as needed.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* @see org.apache.lucene.search.function.FieldCacheSource for requirements
* on the field.
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/IntFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/IntFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/IntFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/IntFieldSource.java Fri Feb 26 13:09:54 2010
@@ -29,10 +29,7 @@
* using <code>getInts()</code> and makes those values
* available as other numeric types, casting as needed.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* @see org.apache.lucene.search.function.FieldCacheSource for requirements
* on the field.
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/OrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/OrdFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/OrdFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/OrdFieldSource.java Fri Feb 26 13:09:54 2010
@@ -39,10 +39,7 @@
* when other documents are inserted or deleted,
* or if a MultiSearcher is used.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* <p><b>NOTE</b>: with the switch in 2.9 to segment-based
* searching, if {@link #getValues} is invoked with a
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ReverseOrdFieldSource.java Fri Feb 26 13:09:54 2010
@@ -40,10 +40,7 @@
* when other documents are inserted or deleted,
* or if a MultiSearcher is used.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* <p><b>NOTE</b>: with the switch in 2.9 to segment-based
* searching, if {@link #getValues} is invoked with a
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ShortFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ShortFieldSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ShortFieldSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ShortFieldSource.java Fri Feb 26 13:09:54 2010
@@ -29,10 +29,7 @@
* using <code>getShorts()</code> and makes those values
* available as other numeric types, casting as needed.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* @see org.apache.lucene.search.function.FieldCacheSource for requirements
* on the field.
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSource.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSource.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSource.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSource.java Fri Feb 26 13:09:54 2010
@@ -31,10 +31,7 @@
* <P>ValueSource implementations differ in RAM requirements: it would always be a factor
* of the number of documents, but for each document the number of bytes can be 1, 2, 4, or 8.
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
*
*/
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSourceQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSourceQuery.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSourceQuery.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/ValueSourceQuery.java Fri Feb 26 13:09:54 2010
@@ -37,10 +37,7 @@
* <p>
* Score is set as: Score(doc,query) = query.getBoost()<sup>2</sup> * valueSource(doc).
*
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>search.function</b> package is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*/
public class ValueSourceQuery extends Query {
ValueSource valSrc;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/package.html
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/package.html?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/package.html (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/function/package.html Fri Feb 26 13:09:54 2010
@@ -26,11 +26,7 @@
The <code>function</code> package provides tight control over documents scores.
</DIV>
<DIV>
-<font color="#FF0000">
-WARNING: The status of the <b>search.function</b> package is experimental. The APIs
-introduced here might change in the future and will not be supported anymore
-in such a case.
-</font>
+@lucene.experimental
</DIV>
<DIV>
Two types of queries are available in this package:
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java Fri Feb 26 13:09:54 2010
@@ -27,7 +27,11 @@
public class MaxPayloadFunction extends PayloadFunction {
@Override
public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
- return Math.max(currentPayloadScore, currentScore);
+ if (numPayloadsSeen == 0) {
+ return currentPayloadScore;
+ } else {
+ return Math.max(currentPayloadScore, currentScore);
+ }
}
@Override
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java Fri Feb 26 13:09:54 2010
@@ -23,9 +23,13 @@
**/
public class MinPayloadFunction extends PayloadFunction {
- @Override
- public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
- return Math.min(currentPayloadScore, currentScore);
+ @Override
+ public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
+ if (numPayloadsSeen == 0) {
+ return currentPayloadScore;
+ } else {
+ return Math.min(currentPayloadScore, currentScore);
+ }
}
@Override
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadFunction.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadFunction.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadFunction.java Fri Feb 26 13:09:54 2010
@@ -18,16 +18,15 @@
import java.io.Serializable;
-
/**
- * An abstract class that defines a way for Payload*Query instances
- * to transform the cumulative effects of payload scores for a document.
- *
+ * An abstract class that defines a way for Payload*Query instances to transform
+ * the cumulative effects of payload scores for a document.
+ *
* @see org.apache.lucene.search.payloads.PayloadTermQuery for more information
- *
- * <p/>
- * This class and its derivations are experimental and subject to change
- *
+ *
+ * @lucene.experimental This class and its derivations are experimental and subject to
+ * change
+ *
**/
public abstract class PayloadFunction implements Serializable {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/payloads/PayloadSpanUtil.java Fri Feb 26 13:09:54 2010
@@ -44,11 +44,7 @@
* Operates like Highlighter - IndexReader should only contain doc of interest,
* best to use MemoryIndex.
*
- * <p/>
- * <font color="#FF0000">
- * WARNING: The status of the <b>Payloads</b> feature is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
*/
public class PayloadSpanUtil {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/search/spans/Spans.java Fri Feb 26 13:09:54 2010
@@ -66,10 +66,7 @@
* <br>
* Note that the return type is a collection, thus the ordering should not be relied upon.
* <br/>
- * <p><font color="#FF0000">
- * WARNING: The status of the <b>Payloads</b> feature is experimental.
- * The APIs introduced here might change in the future and will not be
- * supported anymore in such a case.</font>
+ * @lucene.experimental
*
* @return a List of byte arrays containing the data of this payload, otherwise null if isPayloadAvailable is false
* @throws java.io.IOException
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexInput.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexInput.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexInput.java Fri Feb 26 13:09:54 2010
@@ -22,7 +22,10 @@
import java.util.zip.Checksum;
/** Writes bytes through to a primary IndexOutput, computing
- * checksum as it goes. Note that you cannot use seek(). */
+ * checksum as it goes. Note that you cannot use seek().
+ *
+ * @lucene.internal
+ */
public class ChecksumIndexInput extends IndexInput {
IndexInput main;
Checksum digest;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexOutput.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexOutput.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/ChecksumIndexOutput.java Fri Feb 26 13:09:54 2010
@@ -22,7 +22,10 @@
import java.util.zip.Checksum;
/** Writes bytes through to a primary IndexOutput, computing
- * checksum. Note that you cannot use seek().*/
+ * checksum. Note that you cannot use seek().
+ *
+ * @lucene.internal
+ */
public class ChecksumIndexOutput extends IndexOutput {
IndexOutput main;
Checksum digest;
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/FileSwitchDirectory.java Fri Feb 26 13:09:54 2010
@@ -31,8 +31,7 @@
* to this class, and must allow multiple threads to call
* contains at once.</p>
*
- * <p><b>NOTE</b>: this API is new and experimental and is
- * subject to suddenly change in the next release.
+ * @lucene.experimental
*/
public class FileSwitchDirectory extends Directory {
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/IndexInput.java Fri Feb 26 13:09:54 2010
@@ -22,6 +22,9 @@
import java.util.Map;
import java.util.HashMap;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.RamUsageEstimator;
+
/** Abstract base class for input from a file in a {@link Directory}. A
* random-access input stream. Used for all Lucene index input operations.
* @see Directory
@@ -122,16 +125,18 @@
if (preUTF8Strings)
return readModifiedUTF8String();
int length = readVInt();
- if (bytes == null || length > bytes.length)
- bytes = new byte[(int) (length*1.25)];
+ if (bytes == null || length > bytes.length) {
+ bytes = new byte[ArrayUtil.oversize(length, 1)];
+ }
readBytes(bytes, 0, length);
return new String(bytes, 0, length, "UTF-8");
}
private String readModifiedUTF8String() throws IOException {
int length = readVInt();
- if (chars == null || length > chars.length)
- chars = new char[length];
+ if (chars == null || length > chars.length) {
+ chars = new char[ArrayUtil.oversize(length, RamUsageEstimator.NUM_BYTES_CHAR)];
+ }
readChars(chars, 0, length);
return new String(chars, 0, length);
}
@@ -157,10 +162,11 @@
else if ((b & 0xE0) != 0xE0) {
buffer[i] = (char)(((b & 0x1F) << 6)
| (readByte() & 0x3F));
- } else
+ } else {
buffer[i] = (char)(((b & 0x0F) << 12)
| ((readByte() & 0x3F) << 6)
| (readByte() & 0x3F));
+ }
}
}
@@ -181,10 +187,9 @@
byte b = readByte();
if ((b & 0x80) == 0){
//do nothing, we only need one byte
- }
- else if ((b & 0xE0) != 0xE0) {
+ } else if ((b & 0xE0) != 0xE0) {
readByte();//read an additional byte
- } else{
+ } else {
//read two additional bytes.
readByte();
readByte();
Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java?rev=916666&r1=916665&r2=916666&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/store/NativeFSLockFactory.java Fri Feb 26 13:09:54 2010
@@ -159,12 +159,21 @@
/*
* The javadocs for FileChannel state that you should have
* a single instance of a FileChannel (per JVM) for all
- * locking against a given file. To ensure this, we have
- * a single (static) HashSet that contains the file paths
- * of all currently locked locks. This protects against
- * possible cases where different Directory instances in
- * one JVM (each with their own NativeFSLockFactory
- * instance) have set the same lock dir and lock prefix.
+ * locking against a given file (locks are tracked per
+ * FileChannel instance in Java 1.4/1.5). Even using the same
+ * FileChannel instance is not completely thread-safe with Java
+ * 1.4/1.5 though. To work around this, we have a single (static)
+ * HashSet that contains the file paths of all currently
+ * locked locks. This protects against possible cases
+ * where different Directory instances in one JVM (each
+ * with their own NativeFSLockFactory instance) have set
+ * the same lock dir and lock prefix. However, this will not
+ * work when LockFactorys are created by different
+ * classloaders (eg multiple webapps).
+ *
+ * TODO: Java 1.6 tracks system wide locks in a thread safe manner
+ * (same FileChannel instance or not), so we may want to
+ * change this when Lucene moves to Java 1.6.
*/
private static HashSet<String> LOCK_HELD = new HashSet<String>();