You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/01/18 23:38:59 UTC
svn commit: r1435384 [3/4] - in /lucene/dev/branches/lucene4547: ./
dev-tools/ dev-tools/maven/ dev-tools/maven/solr/core/src/test/
dev-tools/maven/solr/solrj/src/java/ dev-tools/maven/solr/solrj/src/test/
dev-tools/maven/solr/webapp/ dev-tools/scripts...
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntDecoder.java Fri Jan 18 22:38:56 2013
@@ -45,10 +45,13 @@ public class EightFlagsIntDecoder extend
}
@Override
- protected void doDecode(BytesRef buf, IntsRef values, int upto) {
- while (buf.offset < upto) {
+ public void decode(BytesRef buf, IntsRef values) {
+ values.offset = values.length = 0;
+ int upto = buf.offset + buf.length;
+ int offset = buf.offset;
+ while (offset < upto) {
// read indicator
- int indicator = buf.bytes[buf.offset++] & 0xFF;
+ int indicator = buf.bytes[offset++] & 0xFF;
int ordinal = 0;
int capacityNeeded = values.length + 8;
@@ -59,11 +62,21 @@ public class EightFlagsIntDecoder extend
// process indicator, until we read 8 values, or end-of-buffer
while (ordinal != 8) {
if (DECODE_TABLE[indicator][ordinal++] == 0) {
- if (buf.offset == upto) { // end of buffer
+ if (offset == upto) { // end of buffer
return;
}
- // decode the value from the stream.
- values.ints[values.length++] = VInt8.decode(buf) + 2;
+ // it is better if the decoding is inlined like so, and not e.g.
+ // in a utility method
+ int value = 0;
+ while (true) {
+ byte b = buf.bytes[offset++];
+ if (b >= 0) {
+ values.ints[values.length++] = ((value << 7) | b) + 2;
+ break;
+ } else {
+ value = (value << 7) | (b & 0x7F);
+ }
+ }
} else {
values.ints[values.length++] = 1;
}
@@ -73,7 +86,7 @@ public class EightFlagsIntDecoder extend
@Override
public String toString() {
- return "EightFlags (VInt8)";
+ return "EightFlags(VInt8)";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/EightFlagsIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -59,7 +59,9 @@ public class EightFlagsIntEncoder extend
}
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
+ public void encode(IntsRef values, BytesRef buf) {
+ buf.offset = buf.length = 0;
+ int upto = values.offset + values.length;
for (int i = values.offset; i < upto; i++) {
int value = values.ints[i];
if (value == 1) {
@@ -88,7 +90,7 @@ public class EightFlagsIntEncoder extend
@Override
public String toString() {
- return "EightFlags (VInt)";
+ return "EightFlags(VInt)";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntDecoder.java Fri Jan 18 22:38:56 2013
@@ -45,10 +45,13 @@ public class FourFlagsIntDecoder extends
}
@Override
- protected void doDecode(BytesRef buf, IntsRef values, int upto) {
- while (buf.offset < upto) {
+ public void decode(BytesRef buf, IntsRef values) {
+ values.offset = values.length = 0;
+ int upto = buf.offset + buf.length;
+ int offset = buf.offset;
+ while (offset < upto) {
// read indicator
- int indicator = buf.bytes[buf.offset++] & 0xFF;
+ int indicator = buf.bytes[offset++] & 0xFF;
int ordinal = 0;
int capacityNeeded = values.length + 4;
@@ -59,11 +62,21 @@ public class FourFlagsIntDecoder extends
while (ordinal != 4) {
byte decodeVal = DECODE_TABLE[indicator][ordinal++];
if (decodeVal == 0) {
- if (buf.offset == upto) { // end of buffer
+ if (offset == upto) { // end of buffer
return;
}
- // decode the value from the stream.
- values.ints[values.length++] = VInt8.decode(buf) + 4;
+ // it is better if the decoding is inlined like so, and not e.g.
+ // in a utility method
+ int value = 0;
+ while (true) {
+ byte b = buf.bytes[offset++];
+ if (b >= 0) {
+ values.ints[values.length++] = ((value << 7) | b) + 4;
+ break;
+ } else {
+ value = (value << 7) | (b & 0x7F);
+ }
+ }
} else {
values.ints[values.length++] = decodeVal;
}
@@ -73,7 +86,7 @@ public class FourFlagsIntDecoder extends
@Override
public String toString() {
- return "FourFlags (VInt8)";
+ return "FourFlags(VInt8)";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/FourFlagsIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -65,7 +65,9 @@ public class FourFlagsIntEncoder extends
}
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
+ public void encode(IntsRef values, BytesRef buf) {
+ buf.offset = buf.length = 0;
+ int upto = values.offset + values.length;
for (int i = values.offset; i < upto; i++) {
int value = values.ints[i];
if (value <= 3) {
@@ -94,7 +96,7 @@ public class FourFlagsIntEncoder extends
@Override
public String toString() {
- return "FourFlags (VInt)";
+ return "FourFlags(VInt)";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntDecoder.java Fri Jan 18 22:38:56 2013
@@ -28,43 +28,9 @@ import org.apache.lucene.util.IntsRef;
public abstract class IntDecoder {
/**
- * Performs the actual decoding. Values should be read from
- * {@link BytesRef#offset} up to {@code upto}. Also, {@code values} offset and
- * length are set to 0 and the encoder is expected to update
- * {@link IntsRef#length}, but not {@link IntsRef#offset}.
- *
- * <p>
- * <b>NOTE:</b> it is ok to use the buffer's offset as the current position in
- * the buffer (and modify it), it will be reset by
- * {@link #decode(BytesRef, IntsRef)}.
- */
- protected abstract void doDecode(BytesRef buf, IntsRef values, int upto);
-
- /**
- * Called before {@link #doDecode(BytesRef, IntsRef, int)} so that decoders
- * can reset their state.
- */
- protected void reset() {
- // do nothing by default
- }
-
- /**
* Decodes the values from the buffer into the given {@link IntsRef}. Note
* that {@code values.offset} and {@code values.length} are set to 0.
*/
- public final void decode(BytesRef buf, IntsRef values) {
- values.offset = values.length = 0; // must do that because we cannot grow() them otherwise
-
- // some decoders may use the buffer's offset as a position index, so save
- // current offset.
- int bufOffset = buf.offset;
-
- reset();
- doDecode(buf, values, buf.offset + buf.length);
- assert values.offset == 0 : "offset should not have been modified by the decoder.";
-
- // fix offset
- buf.offset = bufOffset;
- }
+ public abstract void decode(BytesRef buf, IntsRef values);
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoder.java Fri Jan 18 22:38:56 2013
@@ -32,31 +32,10 @@ public abstract class IntEncoder {
public IntEncoder() {}
/**
- * Performs the actual encoding. Values should be read from
- * {@link IntsRef#offset} up to {@code upto}. Also, it is guaranteed that
- * {@code buf's} offset and length are set to 0 and the encoder is expected to
- * update {@link BytesRef#length}, but not {@link BytesRef#offset}.
- */
- protected abstract void doEncode(IntsRef values, BytesRef buf, int upto);
-
- /**
- * Called before {@link #doEncode(IntsRef, BytesRef, int)} so that encoders
- * can reset their state.
- */
- protected void reset() {
- // do nothing by default
- }
-
- /**
* Encodes the values to the given buffer. Note that the buffer's offset and
* length are set to 0.
*/
- public final void encode(IntsRef values, BytesRef buf) {
- buf.offset = buf.length = 0;
- reset();
- doEncode(values, buf, values.offset + values.length);
- assert buf.offset == 0 : "offset should not have been modified by the encoder.";
- }
+ public abstract void encode(IntsRef values, BytesRef buf);
/**
* Returns an {@link IntDecoder} which can decode the values that were encoded
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoderFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoderFilter.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoderFilter.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/IntEncoderFilter.java Fri Jan 18 22:38:56 2013
@@ -31,9 +31,4 @@ public abstract class IntEncoderFilter e
this.encoder = encoder;
}
- @Override
- public void reset() {
- encoder.reset();
- }
-
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntDecoder.java Fri Jan 18 22:38:56 2013
@@ -42,14 +42,10 @@ public class NOnesIntDecoder extends Fou
}
@Override
- protected void reset() {
+ public void decode(BytesRef buf, IntsRef values) {
+ values.offset = values.length = 0;
internalBuffer.length = 0;
- super.reset();
- }
-
- @Override
- protected void doDecode(BytesRef buf, IntsRef values, int upto) {
- super.doDecode(buf, internalBuffer, upto);
+ super.decode(buf, internalBuffer);
if (values.ints.length < internalBuffer.length) {
// need space for internalBuffer.length to internalBuffer.length*N,
// grow mildly at first
@@ -84,7 +80,7 @@ public class NOnesIntDecoder extends Fou
@Override
public String toString() {
- return "NOnes (" + n + ") (" + super.toString() + ")";
+ return "NOnes(" + n + ") (" + super.toString() + ")";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/NOnesIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -65,19 +65,15 @@ public class NOnesIntEncoder extends Fou
}
@Override
- protected void reset() {
+ public void encode(IntsRef values, BytesRef buf) {
internalBuffer.length = 0;
- super.reset();
- }
-
- @Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
// make sure the internal buffer is large enough
if (values.length > internalBuffer.ints.length) {
internalBuffer.grow(values.length);
}
int onesCounter = 0;
+ int upto = values.offset + values.length;
for (int i = values.offset; i < upto; i++) {
int value = values.ints[i];
if (value == 1) {
@@ -102,7 +98,7 @@ public class NOnesIntEncoder extends Fou
--onesCounter;
internalBuffer.ints[internalBuffer.length++] = 1;
}
- super.doEncode(internalBuffer, buf, internalBuffer.length);
+ super.encode(internalBuffer, buf);
}
@Override
@@ -112,7 +108,7 @@ public class NOnesIntEncoder extends Fou
@Override
public String toString() {
- return "NOnes (" + n + ") (" + super.toString() + ")";
+ return "NOnes(" + n + ") (" + super.toString() + ")";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntDecoder.java Fri Jan 18 22:38:56 2013
@@ -1,7 +1,9 @@
package org.apache.lucene.util.encoding;
+import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.RamUsageEstimator;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,19 +27,24 @@ import org.apache.lucene.util.IntsRef;
*
* @lucene.experimental
*/
-public class SimpleIntDecoder extends IntDecoder {
+public final class SimpleIntDecoder extends IntDecoder {
@Override
- protected void doDecode(BytesRef buf, IntsRef values, int upto) {
- while (buf.offset < upto) {
- if (values.length == values.ints.length) {
- values.grow(values.length + 10); // grow by few items, however not too many
- }
+ public void decode(BytesRef buf, IntsRef values) {
+ values.offset = values.length = 0;
+ int numValues = buf.length / 4; // every value is 4 bytes
+ if (values.ints.length < numValues) { // offset and length are 0
+ values.ints = new int[ArrayUtil.oversize(numValues, RamUsageEstimator.NUM_BYTES_INT)];
+ }
+
+ int offset = buf.offset;
+ int upto = buf.offset + buf.length;
+ while (offset < upto) {
values.ints[values.length++] =
- ((buf.bytes[buf.offset++] & 0xFF) << 24) |
- ((buf.bytes[buf.offset++] & 0xFF) << 16) |
- ((buf.bytes[buf.offset++] & 0xFF) << 8) |
- (buf.bytes[buf.offset++] & 0xFF);
+ ((buf.bytes[offset++] & 0xFF) << 24) |
+ ((buf.bytes[offset++] & 0xFF) << 16) |
+ ((buf.bytes[offset++] & 0xFF) << 8) |
+ (buf.bytes[offset++] & 0xFF);
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SimpleIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -25,16 +25,18 @@ import org.apache.lucene.util.IntsRef;
*
* @lucene.experimental
*/
-public class SimpleIntEncoder extends IntEncoder {
+public final class SimpleIntEncoder extends IntEncoder {
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
+ public void encode(IntsRef values, BytesRef buf) {
+ buf.offset = buf.length = 0;
// ensure there's enough room in the buffer
int bytesNeeded = values.length * 4;
if (buf.bytes.length < bytesNeeded) {
buf.grow(bytesNeeded);
}
+ int upto = values.offset + values.length;
for (int i = values.offset; i < upto; i++) {
int value = values.ints[i];
buf.bytes[buf.length++] = (byte) (value >>> 24);
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SortingIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SortingIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SortingIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/SortingIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -28,7 +28,7 @@ import org.apache.lucene.util.IntsRef;
*
* @lucene.experimental
*/
-public class SortingIntEncoder extends IntEncoderFilter {
+public final class SortingIntEncoder extends IntEncoderFilter {
/** Initializes with the given encoder. */
public SortingIntEncoder(IntEncoder encoder) {
@@ -36,9 +36,9 @@ public class SortingIntEncoder extends I
}
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
- Arrays.sort(values.ints, values.offset, upto);
- encoder.doEncode(values, buf, upto);
+ public void encode(IntsRef values, BytesRef buf) {
+ Arrays.sort(values.ints, values.offset, values.offset + values.length);
+ encoder.encode(values, buf);
}
@Override
@@ -48,7 +48,7 @@ public class SortingIntEncoder extends I
@Override
public String toString() {
- return "Sorting (" + encoder.toString() + ")";
+ return "Sorting(" + encoder.toString() + ")";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/UniqueValuesIntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/UniqueValuesIntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/UniqueValuesIntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/UniqueValuesIntEncoder.java Fri Jan 18 22:38:56 2013
@@ -36,9 +36,10 @@ public final class UniqueValuesIntEncode
}
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
+ public void encode(IntsRef values, BytesRef buf) {
int prev = values.ints[values.offset];
int idx = values.offset + 1;
+ int upto = values.offset + values.length;
for (int i = idx; i < upto; i++) {
if (values.ints[i] != prev) {
values.ints[idx++] = values.ints[i];
@@ -46,7 +47,7 @@ public final class UniqueValuesIntEncode
}
}
values.length = idx - values.offset;
- encoder.doEncode(values, buf, idx);
+ encoder.encode(values, buf);
}
@Override
@@ -56,7 +57,7 @@ public final class UniqueValuesIntEncode
@Override
public String toString() {
- return "Unique (" + encoder.toString() + ")";
+ return "Unique(" + encoder.toString() + ")";
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntDecoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntDecoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntDecoder.java Fri Jan 18 22:38:56 2013
@@ -1,7 +1,9 @@
package org.apache.lucene.util.encoding;
+import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
+import org.apache.lucene.util.RamUsageEstimator;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,15 +27,32 @@ import org.apache.lucene.util.IntsRef;
*
* @lucene.experimental
*/
-public class VInt8IntDecoder extends IntDecoder {
+public final class VInt8IntDecoder extends IntDecoder {
@Override
- protected void doDecode(BytesRef buf, IntsRef values, int upto) {
- while (buf.offset < upto) {
- if (values.length == values.ints.length) {
- values.grow(values.length + 10); // grow by few items, however not too many
+ public void decode(BytesRef buf, IntsRef values) {
+ values.offset = values.length = 0;
+
+ // grow the buffer up front, even if by a large number of values (buf.length)
+ // that saves the need to check inside the loop for every decoded value if
+ // the buffer needs to grow.
+ if (values.ints.length < buf.length) {
+ values.ints = new int[ArrayUtil.oversize(buf.length, RamUsageEstimator.NUM_BYTES_INT)];
+ }
+
+ // it is better if the decoding is inlined like so, and not e.g.
+ // in a utility method
+ int upto = buf.offset + buf.length;
+ int value = 0;
+ int offset = buf.offset;
+ while (offset < upto) {
+ byte b = buf.bytes[offset++];
+ if (b >= 0) {
+ values.ints[values.length++] = (value << 7) | b;
+ value = 0;
+ } else {
+ value = (value << 7) | (b & 0x7F);
}
- values.ints[values.length++] = VInt8.decode(buf);
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntEncoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntEncoder.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntEncoder.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/java/org/apache/lucene/util/encoding/VInt8IntEncoder.java Fri Jan 18 22:38:56 2013
@@ -47,17 +47,47 @@ import org.apache.lucene.util.IntsRef;
*
* @lucene.experimental
*/
-public class VInt8IntEncoder extends IntEncoder {
+public final class VInt8IntEncoder extends IntEncoder {
@Override
- protected void doEncode(IntsRef values, BytesRef buf, int upto) {
+ public void encode(IntsRef values, BytesRef buf) {
+ buf.offset = buf.length = 0;
int maxBytesNeeded = 5 * values.length; // at most 5 bytes per VInt
if (buf.bytes.length < maxBytesNeeded) {
buf.grow(maxBytesNeeded);
}
+ int upto = values.offset + values.length;
for (int i = values.offset; i < upto; i++) {
- VInt8.encode(values.ints[i], buf);
+ // it is better if the encoding is inlined like so, and not e.g.
+ // in a utility method
+ int value = values.ints[i];
+ if ((value & ~0x7F) == 0) {
+ buf.bytes[buf.length] = (byte) value;
+ buf.length++;
+ } else if ((value & ~0x3FFF) == 0) {
+ buf.bytes[buf.length] = (byte) (0x80 | ((value & 0x3F80) >> 7));
+ buf.bytes[buf.length + 1] = (byte) (value & 0x7F);
+ buf.length += 2;
+ } else if ((value & ~0x1FFFFF) == 0) {
+ buf.bytes[buf.length] = (byte) (0x80 | ((value & 0x1FC000) >> 14));
+ buf.bytes[buf.length + 1] = (byte) (0x80 | ((value & 0x3F80) >> 7));
+ buf.bytes[buf.length + 2] = (byte) (value & 0x7F);
+ buf.length += 3;
+ } else if ((value & ~0xFFFFFFF) == 0) {
+ buf.bytes[buf.length] = (byte) (0x80 | ((value & 0xFE00000) >> 21));
+ buf.bytes[buf.length + 1] = (byte) (0x80 | ((value & 0x1FC000) >> 14));
+ buf.bytes[buf.length + 2] = (byte) (0x80 | ((value & 0x3F80) >> 7));
+ buf.bytes[buf.length + 3] = (byte) (value & 0x7F);
+ buf.length += 4;
+ } else {
+ buf.bytes[buf.length] = (byte) (0x80 | ((value & 0xF0000000) >> 28));
+ buf.bytes[buf.length + 1] = (byte) (0x80 | ((value & 0xFE00000) >> 21));
+ buf.bytes[buf.length + 2] = (byte) (0x80 | ((value & 0x1FC000) >> 14));
+ buf.bytes[buf.length + 3] = (byte) (0x80 | ((value & 0x3F80) >> 7));
+ buf.bytes[buf.length + 4] = (byte) (value & 0x7F);
+ buf.length += 5;
+ }
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Fri Jan 18 22:38:56 2013
@@ -43,6 +43,7 @@ import org.apache.lucene.store.Directory
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util._TestUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -64,7 +65,7 @@ import org.junit.BeforeClass;
* limitations under the License.
*/
-/** Base faceted search test. */
+@SuppressCodecs({"SimpleText"})
public abstract class FacetTestBase extends LuceneTestCase {
/** Holds a search and taxonomy Directories pair. */
@@ -266,13 +267,12 @@ public abstract class FacetTestBase exte
FacetIndexingParams iParams = getFacetIndexingParams(Integer.MAX_VALUE);
String delim = String.valueOf(iParams.getFacetDelimChar());
Map<CategoryPath, Integer> res = new HashMap<CategoryPath, Integer>();
- HashSet<Term> handledTerms = new HashSet<Term>();
+ HashSet<String> handledTerms = new HashSet<String>();
for (CategoryListParams clp : iParams.getAllCategoryListParams()) {
- Term baseTerm = new Term(clp.getTerm().field());
- if (!handledTerms.add(baseTerm)) {
+ if (!handledTerms.add(clp.field)) {
continue; // already handled this term (for another list)
}
- Terms terms = MultiFields.getTerms(indexReader, baseTerm.field());
+ Terms terms = MultiFields.getTerms(indexReader, clp.field);
if (terms == null) {
continue;
}
@@ -297,7 +297,7 @@ public abstract class FacetTestBase exte
FacetResultNode topResNode = fr.getFacetResultNode();
FacetRequest freq = fr.getFacetRequest();
if (VERBOSE) {
- System.out.println(freq.getCategoryPath().toString()+ "\t\t" + topResNode);
+ System.out.println(freq.categoryPath.toString()+ "\t\t" + topResNode);
}
assertCountsAndCardinality(facetCountsTruth, topResNode, freq.getNumResults());
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java Fri Jan 18 22:38:56 2013
@@ -2,14 +2,9 @@ package org.apache.lucene.facet;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.TextField;
-import org.apache.lucene.facet.index.FacetFields;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.search.FacetsCollector;
import org.apache.lucene.facet.search.params.CountFacetRequest;
@@ -23,7 +18,6 @@ import org.apache.lucene.facet.taxonomy.
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
@@ -116,15 +110,6 @@ public class FacetTestUtils {
return collectors;
}
- public static void add(FacetIndexingParams iParams, RandomIndexWriter iw,
- TaxonomyWriter tw, String... strings) throws IOException {
- Document d = new Document();
- FacetFields facetFields = new FacetFields(tw, iParams);
- facetFields.addFields(d, Collections.singletonList(new CategoryPath(strings)));
- d.add(new TextField("content", "alpha", Field.Store.YES));
- iw.addDocument(d);
- }
-
public static class IndexTaxonomyReaderPair {
public DirectoryReader indexReader;
public DirectoryTaxonomyReader taxReader;
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/CategoryListParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/CategoryListParamsTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/CategoryListParamsTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/CategoryListParamsTest.java Fri Jan 18 22:38:56 2013
@@ -1,10 +1,12 @@
package org.apache.lucene.facet.index.params;
-import org.apache.lucene.index.Term;
-import org.junit.Test;
-
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.facet.index.params.CategoryListParams;
+import org.apache.lucene.util.encoding.DGapVInt8IntEncoder;
+import org.apache.lucene.util.encoding.IntDecoder;
+import org.apache.lucene.util.encoding.IntEncoder;
+import org.apache.lucene.util.encoding.SortingIntEncoder;
+import org.apache.lucene.util.encoding.UniqueValuesIntEncoder;
+import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -28,9 +30,11 @@ public class CategoryListParamsTest exte
@Test
public void testDefaultSettings() {
CategoryListParams clp = new CategoryListParams();
- assertEquals("wrong default term", new Term("$facets", "$fulltree$"), clp.getTerm());
- assertEquals("unexpected default encoder", "Sorting (Unique (DGap (VInt8)))", clp.createEncoder().toString());
- assertEquals("unexpected default decoder", "DGap (VInt8)", clp.createEncoder().createMatchingDecoder().toString());
+ assertEquals("wrong default field", "$facets", clp.field);
+ IntEncoder encoder = new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapVInt8IntEncoder()));
+ IntDecoder decoder = encoder.createMatchingDecoder();
+ assertEquals("unexpected default encoder", encoder.toString(), clp.createEncoder().toString());
+ assertEquals("unexpected default decoder", decoder.toString(), clp.createEncoder().createMatchingDecoder().toString());
}
/**
@@ -64,8 +68,8 @@ public class CategoryListParamsTest exte
clParams1.hashCode(), clParams2.hashCode());
// Test 2 CategoryListParams with the same specified Term
- clParams1 = new CategoryListParams(new Term("test"));
- clParams2 = new CategoryListParams(new Term("test"));
+ clParams1 = new CategoryListParams("test");
+ clParams2 = new CategoryListParams("test");
assertEquals(
"2 CategoryListParams with the same term should equal each other.",
clParams1, clParams2);
@@ -73,8 +77,8 @@ public class CategoryListParamsTest exte
clParams1.hashCode(), clParams2.hashCode());
// Test 2 CategoryListParams with DIFFERENT terms
- clParams1 = new CategoryListParams(new Term("test1"));
- clParams2 = new CategoryListParams(new Term("test2"));
+ clParams1 = new CategoryListParams("test1");
+ clParams2 = new CategoryListParams("test2");
assertFalse(
"2 CategoryListParams with the different terms should NOT equal each other.",
clParams1.equals(clParams2));
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java Fri Jan 18 22:38:56 2013
@@ -35,8 +35,7 @@ public class FacetIndexingParamsTest ext
assertNotNull("Missing default category list", dfip.getAllCategoryListParams());
assertEquals("all categories have the same CategoryListParams by default",
dfip.getCategoryListParams(null), dfip.getCategoryListParams(new CategoryPath("a")));
- assertEquals("Expected default category list term is $facets:$fulltree$",
- new Term("$facets", "$fulltree$"), dfip.getCategoryListParams(null).getTerm());
+ assertEquals("Expected default category list field is $facets", "$facets", dfip.getCategoryListParams(null).field);
String expectedDDText = "a"
+ dfip.getFacetDelimChar() + "b";
CategoryPath cp = new CategoryPath("a", "b");
@@ -48,13 +47,13 @@ public class FacetIndexingParamsTest ext
assertEquals("wrong drill-down term text", expectedDDText, new String(
buf, 0, numchars));
CategoryListParams clParams = dfip.getCategoryListParams(null);
- assertEquals("partition for all ordinals is the first", "$fulltree$",
- PartitionsUtils.partitionNameByOrdinal(dfip, clParams , 250));
+ assertEquals("partition for all ordinals is the first", "",
+ PartitionsUtils.partitionNameByOrdinal(dfip, 250));
assertEquals("for partition 0, the same name should be returned",
- "$fulltree$", PartitionsUtils.partitionName(clParams, 0));
+ "", PartitionsUtils.partitionName(0));
assertEquals(
"for any other, it's the concatenation of name + partition",
- "$fulltree$1", PartitionsUtils.partitionName(clParams, 1));
+ PartitionsUtils.PART_NAME_PREFIX + "1", PartitionsUtils.partitionName(1));
assertEquals("default partition number is always 0", 0,
PartitionsUtils.partitionNumber(dfip,100));
assertEquals("default partition size is unbounded", Integer.MAX_VALUE,
@@ -63,11 +62,9 @@ public class FacetIndexingParamsTest ext
@Test
public void testCategoryListParamsWithDefaultIndexingParams() {
- CategoryListParams clp = new CategoryListParams(
- new Term("clp", "value"));
+ CategoryListParams clp = new CategoryListParams("clp");
FacetIndexingParams dfip = new FacetIndexingParams(clp);
- assertEquals("Expected default category list term is " + clp.getTerm(),
- clp.getTerm(), dfip.getCategoryListParams(null).getTerm());
+ assertEquals("Expected default category list field is " + clp.field, clp.field, dfip.getCategoryListParams(null).field);
}
@Test
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java Fri Jan 18 22:38:56 2013
@@ -32,44 +32,31 @@ public class PerDimensionIndexingParamsT
public void testTopLevelSettings() {
FacetIndexingParams ifip = new PerDimensionIndexingParams(Collections.<CategoryPath, CategoryListParams>emptyMap());
assertNotNull("Missing default category list", ifip.getAllCategoryListParams());
- assertEquals(
- "Expected default category list term is $facets:$fulltree$",
- new Term("$facets", "$fulltree$"), ifip.getCategoryListParams(
- null).getTerm());
- String expectedDDText = "a"
- + ifip.getFacetDelimChar() + "b";
+ assertEquals("Expected default category list field is $facets", "$facets", ifip.getCategoryListParams(null).field);
+ String expectedDDText = "a" + ifip.getFacetDelimChar() + "b";
CategoryPath cp = new CategoryPath("a", "b");
- assertEquals("wrong drill-down term", new Term("$facets",
- expectedDDText), DrillDown.term(ifip,cp));
+ assertEquals("wrong drill-down term", new Term("$facets", expectedDDText), DrillDown.term(ifip,cp));
char[] buf = new char[20];
int numchars = ifip.drillDownTermText(cp, buf);
assertEquals("3 characters should be written", 3, numchars);
- assertEquals("wrong drill-down term text", expectedDDText, new String(
- buf, 0, numchars));
+ assertEquals("wrong drill-down term text", expectedDDText, new String(buf, 0, numchars));
CategoryListParams clParams = ifip.getCategoryListParams(null);
- assertEquals("partition for all ordinals is the first", "$fulltree$",
- PartitionsUtils.partitionNameByOrdinal(ifip, clParams , 250));
- assertEquals("for partition 0, the same name should be returned",
- "$fulltree$", PartitionsUtils.partitionName(clParams, 0));
- assertEquals(
- "for any other, it's the concatenation of name + partition",
- "$fulltree$1", PartitionsUtils.partitionName(clParams, 1));
- assertEquals("default partition number is always 0", 0,
- PartitionsUtils.partitionNumber(ifip,100));
-
- assertEquals("default partition size is unbounded", Integer.MAX_VALUE,
- ifip.getPartitionSize());
+ assertEquals("partition for all ordinals is the first", "", PartitionsUtils.partitionNameByOrdinal(ifip, 250));
+ assertEquals("for partition 0, the same name should be returned", "", PartitionsUtils.partitionName(0));
+ assertEquals("for any other, it's the concatenation of name + partition", PartitionsUtils.PART_NAME_PREFIX + "1", PartitionsUtils.partitionName(1));
+ assertEquals("default partition number is always 0", 0, PartitionsUtils.partitionNumber(ifip,100));
+ assertEquals("default partition size is unbounded", Integer.MAX_VALUE, ifip.getPartitionSize());
}
@Test
public void testCategoryListParamsAddition() {
- CategoryListParams clp = new CategoryListParams(new Term("clp", "value"));
+ CategoryListParams clp = new CategoryListParams("clp");
PerDimensionIndexingParams tlfip = new PerDimensionIndexingParams(
Collections.<CategoryPath,CategoryListParams> singletonMap(new CategoryPath("a"), clp));
- assertEquals("Expected category list term is " + clp.getTerm(),
- clp.getTerm(), tlfip.getCategoryListParams(new CategoryPath("a")).getTerm());
- assertNotSame("Unexpected default category list " + clp.getTerm(), clp, tlfip.getCategoryListParams(null));
+ assertEquals("Expected category list field is " + clp.field,
+ clp.field, tlfip.getCategoryListParams(new CategoryPath("a")).field);
+ assertNotSame("Unexpected default category list " + clp.field, clp, tlfip.getCategoryListParams(null));
}
}
\ No newline at end of file
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java Fri Jan 18 22:38:56 2013
@@ -1,23 +1,15 @@
package org.apache.lucene.facet.search;
-import java.io.IOException;
-import java.io.Reader;
import java.util.HashSet;
import java.util.Set;
-import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
-import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.TextField;
+import org.apache.lucene.document.StraightBytesDocValuesField;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
@@ -48,42 +40,6 @@ import org.junit.Test;
public class CategoryListIteratorTest extends LuceneTestCase {
- private static final class DataTokenStream extends TokenStream {
-
- private final PayloadAttribute payload = addAttribute(PayloadAttribute.class);
- private final BytesRef buf;
- private final IntEncoder encoder;
- private final CharTermAttribute term = addAttribute(CharTermAttribute.class);
-
- private int idx;
- private boolean exhausted = false;
-
- public DataTokenStream(String text, IntEncoder encoder) {
- this.encoder = encoder;
- term.setEmpty().append(text);
- buf = new BytesRef();
- payload.setPayload(buf);
- }
-
- public void setIdx(int idx) {
- this.idx = idx;
- exhausted = false;
- }
-
- @Override
- public boolean incrementToken() throws IOException {
- if (exhausted) {
- return false;
- }
-
- // must copy because encoders may change the buffer
- encoder.encode(IntsRef.deepCopyOf(data[idx]), buf);
- exhausted = true;
- return true;
- }
-
- }
-
static final IntsRef[] data = new IntsRef[] {
new IntsRef(new int[] { 1, 2 }, 0, 2),
new IntsRef(new int[] { 3, 4 }, 0, 2),
@@ -95,13 +51,13 @@ public class CategoryListIteratorTest ex
public void testPayloadCategoryListIteraor() throws Exception {
Directory dir = newDirectory();
final IntEncoder encoder = new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())));
- DataTokenStream dts = new DataTokenStream("1",encoder);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random(), MockTokenizer.KEYWORD, false)).setMergePolicy(newLogMergePolicy()));
+ BytesRef buf = new BytesRef();
for (int i = 0; i < data.length; i++) {
- dts.setIdx(i);
Document doc = new Document();
- doc.add(new TextField("f", dts));
+ encoder.encode(IntsRef.deepCopyOf(data[i]), buf);
+ doc.add(new StraightBytesDocValuesField("f", buf));
writer.addDocument(doc);
}
IndexReader reader = writer.getReader();
@@ -109,9 +65,9 @@ public class CategoryListIteratorTest ex
int totalCategories = 0;
IntsRef ordinals = new IntsRef();
- CategoryListIterator cli = new PayloadCategoryListIteraor(new Term("f","1"), encoder.createMatchingDecoder());
+ CategoryListIterator cli = new DocValuesCategoryListIterator("f", encoder.createMatchingDecoder());
for (AtomicReaderContext context : reader.leaves()) {
- cli.setNextReader(context);
+ assertTrue("failed to initalize iterator", cli.setNextReader(context));
int maxDoc = context.reader().maxDoc();
int dataIdx = context.docBase;
for (int doc = 0; doc < maxDoc; doc++, dataIdx++) {
@@ -136,24 +92,17 @@ public class CategoryListIteratorTest ex
public void testPayloadIteratorWithInvalidDoc() throws Exception {
Directory dir = newDirectory();
final IntEncoder encoder = new SortingIntEncoder(new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())));
- DataTokenStream dts = new DataTokenStream("1", encoder);
- // this test requires that no payloads ever be randomly present!
- final Analyzer noPayloadsAnalyzer = new Analyzer() {
- @Override
- public TokenStreamComponents createComponents(String fieldName, Reader reader) {
- return new TokenStreamComponents(new MockTokenizer(reader, MockTokenizer.KEYWORD, false));
- }
- };
// NOTE: test is wired to LogMP... because test relies on certain docids having payloads
RandomIndexWriter writer = new RandomIndexWriter(random(), dir,
- newIndexWriterConfig(TEST_VERSION_CURRENT, noPayloadsAnalyzer).setMergePolicy(newLogMergePolicy()));
+ newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
for (int i = 0; i < data.length; i++) {
Document doc = new Document();
if (i == 0) {
- dts.setIdx(i);
- doc.add(new TextField("f", dts)); // only doc 0 has payloads!
+ BytesRef buf = new BytesRef();
+ encoder.encode(IntsRef.deepCopyOf(data[i]), buf );
+ doc.add(new StraightBytesDocValuesField("f", buf));
} else {
- doc.add(new TextField("f", "1", Field.Store.NO));
+ doc.add(new StraightBytesDocValuesField("f", new BytesRef()));
}
writer.addDocument(doc);
writer.commit();
@@ -164,9 +113,9 @@ public class CategoryListIteratorTest ex
int totalCategories = 0;
IntsRef ordinals = new IntsRef();
- CategoryListIterator cli = new PayloadCategoryListIteraor(new Term("f","1"), encoder.createMatchingDecoder());
+ CategoryListIterator cli = new DocValuesCategoryListIterator("f", encoder.createMatchingDecoder());
for (AtomicReaderContext context : reader.leaves()) {
- cli.setNextReader(context);
+ assertTrue("failed to initalize iterator", cli.setNextReader(context));
int maxDoc = context.reader().maxDoc();
int dataIdx = context.docBase;
for (int doc = 0; doc < maxDoc; doc++, dataIdx++) {
@@ -176,13 +125,13 @@ public class CategoryListIteratorTest ex
}
cli.getOrdinals(doc, ordinals);
if (dataIdx == 0) {
- assertTrue("document 0 must have a payload", ordinals.length > 0);
+ assertTrue("document 0 must have ordinals", ordinals.length > 0);
for (int j = 0; j < ordinals.length; j++) {
assertTrue("expected category not found: " + ordinals.ints[j], values.contains(ordinals.ints[j]));
}
totalCategories += ordinals.length;
} else {
- assertTrue("only document 0 should have a payload", ordinals.length == 0);
+ assertTrue("only document 0 should have ordinals", ordinals.length == 0);
}
}
}
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java Fri Jan 18 22:38:56 2013
@@ -60,8 +60,8 @@ public class DrillDownTest extends Lucen
public DrillDownTest() {
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
- paramsMap.put(new CategoryPath("a"), new CategoryListParams(new Term("testing_facets_a", "a")));
- paramsMap.put(new CategoryPath("b"), new CategoryListParams(new Term("testing_facets_b", "b")));
+ paramsMap.put(new CategoryPath("a"), new CategoryListParams("testing_facets_a"));
+ paramsMap.put(new CategoryPath("b"), new CategoryListParams("testing_facets_b"));
nonDefaultParams = new PerDimensionIndexingParams(paramsMap);
}
@@ -113,8 +113,8 @@ public class DrillDownTest extends Lucen
}
@Test
- public void testTermDefault() {
- String defaultField = CategoryListParams.DEFAULT_TERM.field();
+ public void testDefaultField() {
+ String defaultField = CategoryListParams.DEFAULT_FIELD;
Term termA = DrillDown.term(defaultParams, new CategoryPath("a"));
assertEquals(new Term(defaultField, "a"), termA);
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java Fri Jan 18 22:38:56 2013
@@ -10,14 +10,18 @@ import java.util.Map;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.TextField;
import org.apache.lucene.facet.FacetTestUtils;
+import org.apache.lucene.facet.index.FacetFields;
import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
import org.apache.lucene.facet.search.params.CountFacetRequest;
import org.apache.lucene.facet.search.params.FacetRequest;
-import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.params.FacetRequest.ResultMode;
+import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath;
@@ -25,23 +29,19 @@ import org.apache.lucene.facet.taxonomy.
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
-import org.apache.lucene.index.DocsEnum;
+import org.apache.lucene.index.AtomicReader;
+import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.index.MultiFields;
import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util._TestUtil;
import org.junit.Test;
/*
@@ -63,6 +63,18 @@ import org.junit.Test;
public class TestMultipleCategoryLists extends LuceneTestCase {
+ private static final CategoryPath[] CATEGORIES = new CategoryPath[] {
+ new CategoryPath("Author", "Mark Twain"),
+ new CategoryPath("Author", "Stephen King"),
+ new CategoryPath("Author", "Kurt Vonnegut"),
+ new CategoryPath("Band", "Rock & Pop", "The Beatles"),
+ new CategoryPath("Band", "Punk", "The Ramones"),
+ new CategoryPath("Band", "Rock & Pop", "U2"),
+ new CategoryPath("Band", "Rock & Pop", "REM"),
+ new CategoryPath("Band", "Rock & Pop", "Dave Matthews Band"),
+ new CategoryPath("Composer", "Bach"),
+ };
+
@Test
public void testDefault() throws Exception {
Directory[][] dirs = getDirs();
@@ -72,9 +84,6 @@ public class TestMultipleCategoryLists e
// create and open a taxonomy writer
TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
- /**
- * Configure with no custom counting lists
- */
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(Collections.<CategoryPath, CategoryListParams>emptyMap());
seedIndex(iw, tw, iParams);
@@ -88,19 +97,14 @@ public class TestMultipleCategoryLists e
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
- FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
- searcher);
+ FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
- DocsEnum td = _TestUtil.docs(random(), ir, "$facets", new BytesRef("$fulltree$"), MultiFields.getLiveDocs(ir), null, DocsEnum.FLAG_NONE);
- assertTrue(td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+ assertOrdinalsExist("$facets", ir);
- tr.close();
- ir.close();
- iw.close();
- tw.close();
+ IOUtils.close(tr, ir, iw, tw);
IOUtils.close(dirs[0]);
}
@@ -111,12 +115,10 @@ public class TestMultipleCategoryLists e
RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
- TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
- OpenMode.CREATE);
+ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(
- Collections.singletonMap(new CategoryPath("Author"),
- new CategoryListParams(new Term("$author", "Authors"))));
+ Collections.singletonMap(new CategoryPath("Author"), new CategoryListParams("$author")));
seedIndex(iw, tw, iParams);
IndexReader ir = iw.getReader();
@@ -133,13 +135,10 @@ public class TestMultipleCategoryLists e
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
- assertPostingListExists("$facets", "$fulltree$", ir);
- assertPostingListExists("$author", "Authors", ir);
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$author", ir);
- tr.close();
- ir.close();
- iw.close();
- tw.close();
+ IOUtils.close(tr, ir, iw, tw);
IOUtils.close(dirs[0]);
}
@@ -150,12 +149,11 @@ public class TestMultipleCategoryLists e
RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
- TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
- OpenMode.CREATE);
+ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
- paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$music", "Bands")));
- paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$music", "Composers")));
+ paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
+ paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
@@ -168,26 +166,27 @@ public class TestMultipleCategoryLists e
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
- FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
- searcher);
+ FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
- assertPostingListExists("$facets", "$fulltree$", ir);
- assertPostingListExists("$music", "Bands", ir);
- assertPostingListExists("$music", "Composers", ir);
-
- tr.close();
- ir.close();
- iw.close();
- tw.close();
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$music", ir);
+ assertOrdinalsExist("$music", ir);
+
+ IOUtils.close(tr, ir, iw, tw);
IOUtils.close(dirs[0]);
}
- private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException {
- DocsEnum de = _TestUtil.docs(random(), ir, field, new BytesRef(text), null, null, DocsEnum.FLAG_NONE);
- assertTrue(de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+ private void assertOrdinalsExist(String field, IndexReader ir) throws IOException {
+ for (AtomicReaderContext context : ir.leaves()) {
+ AtomicReader r = context.reader();
+ if (r.getBinaryDocValues(field) != null) {
+ return; // not all segments must have this DocValues
+ }
+ }
+ fail("no ordinals found for " + field);
}
@Test
@@ -200,8 +199,8 @@ public class TestMultipleCategoryLists e
TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
- paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$bands", "Bands")));
- paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$composers", "Composers")));
+ paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$bands"));
+ paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$composers"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
@@ -214,18 +213,15 @@ public class TestMultipleCategoryLists e
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
- FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
- searcher);
+ FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
- assertPostingListExists("$facets", "$fulltree$", ir);
- assertPostingListExists("$bands", "Bands", ir);
- assertPostingListExists("$composers", "Composers", ir);
- tr.close();
- ir.close();
- iw.close();
- tw.close();
+ assertOrdinalsExist("$facets", ir);
+ assertOrdinalsExist("$bands", ir);
+ assertOrdinalsExist("$composers", ir);
+
+ IOUtils.close(tr, ir, iw, tw);
IOUtils.close(dirs[0]);
}
@@ -236,13 +232,12 @@ public class TestMultipleCategoryLists e
RandomIndexWriter iw = new RandomIndexWriter(random(), dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer
- TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
- OpenMode.CREATE);
+ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
Map<CategoryPath,CategoryListParams> paramsMap = new HashMap<CategoryPath,CategoryListParams>();
- paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$music", "music")));
- paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$music", "music")));
- paramsMap.put(new CategoryPath("Author"), new CategoryListParams(new Term("$literature", "Authors")));
+ paramsMap.put(new CategoryPath("Band"), new CategoryListParams("$music"));
+ paramsMap.put(new CategoryPath("Composer"), new CategoryListParams("$music"));
+ paramsMap.put(new CategoryPath("Author"), new CategoryListParams("$literature"));
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap);
seedIndex(iw, tw, iParams);
@@ -256,18 +251,14 @@ public class TestMultipleCategoryLists e
// prepare searcher to search against
IndexSearcher searcher = newSearcher(ir);
- FacetsCollector facetsCollector = performSearch(iParams, tr, ir,
- searcher);
+ FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher);
// Obtain facets results and hand-test them
assertCorrectResults(facetsCollector);
- assertPostingListExists("$music", "music", ir);
- assertPostingListExists("$literature", "Authors", ir);
+ assertOrdinalsExist("$music", ir);
+ assertOrdinalsExist("$literature", ir);
- tr.close();
- ir.close();
- iw.close();
- tw.close();
+ IOUtils.close(tr, ir, iw, tw);
IOUtils.close(dirs[0]);
}
@@ -275,14 +266,12 @@ public class TestMultipleCategoryLists e
return FacetTestUtils.createIndexTaxonomyDirs(1);
}
- private void assertCorrectResults(FacetsCollector facetsCollector)
- throws IOException {
+ private void assertCorrectResults(FacetsCollector facetsCollector) throws IOException {
List<FacetResult> res = facetsCollector.getFacetResults();
FacetResult results = res.get(0);
FacetResultNode resNode = results.getFacetResultNode();
- Iterable<? extends FacetResultNode> subResults = resNode
- .getSubResults();
+ Iterable<? extends FacetResultNode> subResults = resNode.getSubResults();
Iterator<? extends FacetResultNode> subIter = subResults.iterator();
checkResult(resNode, "Band", 5.0);
@@ -325,9 +314,8 @@ public class TestMultipleCategoryLists e
checkResult(subIter.next(), "Band/Rock & Pop/The Beatles", 1.0);
}
- private FacetsCollector performSearch(FacetIndexingParams iParams,
- TaxonomyReader tr, IndexReader ir,
- IndexSearcher searcher) throws IOException {
+ private FacetsCollector performSearch(FacetIndexingParams iParams, TaxonomyReader tr, IndexReader ir,
+ IndexSearcher searcher) throws IOException {
// step 1: collect matching documents into a collector
Query q = new MatchAllDocsQuery();
TopScoreDocCollector topDocsCollector = TopScoreDocCollector.create(10, true);
@@ -344,7 +332,6 @@ public class TestMultipleCategoryLists e
// Faceted search parameters indicate which facets are we interested in
FacetSearchParams facetSearchParams = new FacetSearchParams(facetRequests, iParams);
-
// perform documents search and facets accumulation
FacetsCollector facetsCollector = new FacetsCollector(facetSearchParams, ir, tr);
@@ -352,27 +339,19 @@ public class TestMultipleCategoryLists e
return facetsCollector;
}
- private void seedIndex(RandomIndexWriter iw, TaxonomyWriter tw,
- FacetIndexingParams iParams) throws IOException {
- FacetTestUtils.add(iParams, iw, tw, "Author", "Mark Twain");
- FacetTestUtils.add(iParams, iw, tw, "Author", "Stephen King");
- FacetTestUtils.add(iParams, iw, tw, "Author", "Kurt Vonnegut");
- FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop",
- "The Beatles");
- FacetTestUtils.add(iParams, iw, tw, "Band", "Punk", "The Ramones");
- FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop", "U2");
- FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop", "REM");
- FacetTestUtils.add(iParams, iw, tw, "Band", "Rock & Pop",
- "Dave Matthews Band");
- FacetTestUtils.add(iParams, iw, tw, "Composer", "Bach");
+ private void seedIndex(RandomIndexWriter iw, TaxonomyWriter tw, FacetIndexingParams iParams) throws IOException {
+ FacetFields facetFields = new FacetFields(tw, iParams);
+ for (CategoryPath cp : CATEGORIES) {
+ Document doc = new Document();
+ facetFields.addFields(doc, Collections.singletonList(cp));
+ doc.add(new TextField("content", "alpha", Field.Store.YES));
+ iw.addDocument(doc);
+ }
}
private static void checkResult(FacetResultNode sub, String label, double value) {
- assertEquals("Label of subresult " + sub.getLabel() + " was incorrect",
- label, sub.getLabel().toString());
- assertEquals(
- "Value for " + sub.getLabel() + " subresult was incorrect",
- value, sub.getValue(), 0.0);
+ assertEquals("Label of subresult " + sub.getLabel() + " was incorrect", label, sub.getLabel().toString());
+ assertEquals("Value for " + sub.getLabel() + " subresult was incorrect", value, sub.getValue(), 0.0);
}
}
\ No newline at end of file
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestStandardFacetsAccumulator.java Fri Jan 18 22:38:56 2013
@@ -93,6 +93,7 @@ public class TestStandardFacetsAccumulat
indexTwoDocs(indexWriter, null, false); // 4th segment, no content, or categories
indexTwoDocs(indexWriter, null, true); // 5th segment, with content, no categories
indexTwoDocs(indexWriter, facetFields, true); // 6th segment, with content, with categories
+ indexTwoDocs(indexWriter, null, true); // 7th segment, with content, no categories
IOUtils.close(indexWriter, taxoWriter);
DirectoryReader indexReader = DirectoryReader.open(indexDir);
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java Fri Jan 18 22:38:56 2013
@@ -178,7 +178,7 @@ public class TestTopKInEachNodeResultHan
}
FacetResult fr = facetResults.get(0); // a, depth=3, K=2
- boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ boolean hasDoctor = "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(9, fr.getNumValidDescendants());
FacetResultNode parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -219,7 +219,7 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(1); // a, depth=2, K=2. same result as before
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(9, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -239,7 +239,7 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(2); // a, depth=1, K=2
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(4, fr.getNumValidDescendants(), 4);
parentRes = fr.getFacetResultNode();
assertEquals(16.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -257,7 +257,7 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(3); // a/b, depth=3, K=2
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -272,7 +272,7 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(4); // a/b, depth=2, K=2
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -286,7 +286,7 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(5); // a/b, depth=1, K=2
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(4, fr.getNumValidDescendants());
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
@@ -300,13 +300,13 @@ public class TestTopKInEachNodeResultHan
}
fr = facetResults.get(6); // a/b, depth=0, K=2
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
assertEquals(0, fr.getNumValidDescendants()); // 0 descendants but rootnode
parentRes = fr.getFacetResultNode();
assertEquals(8.0, parentRes.getValue(), Double.MIN_VALUE);
assertEquals(0.0, parentRes.getResidue(), Double.MIN_VALUE);
assertEquals(0, parentRes.getNumSubResults());
- hasDoctor |= "Doctor".equals(fr.getFacetRequest().getCategoryPath().components[0]);
+ hasDoctor |= "Doctor".equals(fr.getFacetRequest().categoryPath.components[0]);
// doctor, depth=1, K=2
assertFalse("Shouldn't have found anything for a FacetRequest " +
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java Fri Jan 18 22:38:56 2013
@@ -85,12 +85,12 @@ public class TestTotalFacetCounts extend
TotalFacetCountsCache tfcc = TotalFacetCountsCache.getSingleton();
File tmpFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
- tfcc.store(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
+ tfcc.store(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams);
tfcc.clear(); // not really required because TFCC overrides on load(), but in the test we need not rely on this.
tfcc.load(tmpFile, readers[0].indexReader, readers[0].taxReader, iParams);
// now retrieve the one just loaded
- TotalFacetCounts totalCounts = tfcc.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TotalFacetCounts totalCounts = tfcc.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
int partition = 0;
for (int i=0; i<expectedCounts.length; i+=partitionSize) {
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java Fri Jan 18 22:38:56 2013
@@ -78,7 +78,7 @@ public class TestTotalFacetCountsCache e
@Override
public void run() {
try {
- tfc = TFC.getTotalCounts(r, tr, iParams, null);
+ tfc = TFC.getTotalCounts(r, tr, iParams);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -264,29 +264,29 @@ public class TestTotalFacetCountsCache e
// As this is the first time we have invoked the TotalFacetCountsManager,
// we should expect to compute and not read from disk.
TotalFacetCounts totalCounts =
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
int prevGen = assertRecomputed(totalCounts, 0, "after first attempt to get it!");
// Repeating same operation should pull from the cache - not recomputed.
assertTrue("Should be obtained from cache at 2nd attempt",totalCounts ==
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+ TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
// Repeat the same operation as above. but clear first - now should recompute again
initCache();
- totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 3rd attempt to get it!");
//store to file
File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
initCache();
- TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
- totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
+ totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after cache clear, 4th attempt to get it!");
//clear and load
initCache();
TFC.load(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
- totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertReadFromDisc(totalCounts, prevGen, "after 5th attempt to get it!");
// Add a new facet to the index, commit and refresh readers
@@ -306,12 +306,12 @@ public class TestTotalFacetCountsCache e
readers[0].indexReader = r2;
// now use the new reader - should recompute
- totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertRecomputed(totalCounts, prevGen, "after updating the index - 7th attempt!");
// try again - should not recompute
assertTrue("Should be obtained from cache at 8th attempt",totalCounts ==
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+ TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
readers[0].close();
outputFile.delete();
@@ -361,7 +361,7 @@ public class TestTotalFacetCountsCache e
// Create TFC and write cache to disk
File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
- TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TFC.store(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
// Make the taxonomy grow without touching the index
for (int i = 0; i < 10; i++) {
@@ -377,8 +377,7 @@ public class TestTotalFacetCountsCache e
// With the bug, this next call should result in an exception
TFC.load(outputFile, readers[0].indexReader, readers[0].taxReader, iParams);
- TotalFacetCounts totalCounts = TFC.getTotalCounts(
- readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TotalFacetCounts totalCounts = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
assertReadFromDisc(totalCounts, 0, "after reading from disk.");
outputFile.delete();
writers[0].close();
@@ -467,28 +466,25 @@ public class TestTotalFacetCountsCache e
// As this is the first time we have invoked the TotalFacetCountsManager, we
// should expect to compute.
TotalFacetCounts totalCounts0 =
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
int prevGen = -1;
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 1");
assertTrue("attempt 1b for same input [0] shout find it in cache",
- totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+ totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
// 2nd Reader - As this is the first time we have invoked the
// TotalFacetCountsManager, we should expect a state of NEW to be returned.
- TotalFacetCounts totalCounts1 =
- TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null);
+ TotalFacetCounts totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 2");
assertTrue("attempt 2b for same input [1] shout find it in cache",
- totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null));
+ totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams));
// Right now cache size is one, so first TFC is gone and should be recomputed
- totalCounts0 =
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ totalCounts0 = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 3");
// Similarly will recompute the second result
- totalCounts1 =
- TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null);
+ totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
prevGen = assertRecomputed(totalCounts1, prevGen, "after attempt 4");
// Now we set the cache size to two, meaning both should exist in the
@@ -496,17 +492,15 @@ public class TestTotalFacetCountsCache e
TFC.setCacheSize(2);
// Re-compute totalCounts0 (was evicted from the cache when the cache was smaller)
- totalCounts0 =
- TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null);
+ totalCounts0 = TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams);
prevGen = assertRecomputed(totalCounts0, prevGen, "after attempt 5");
// now both are in the larger cache and should not be recomputed
- totalCounts1 = TFC.getTotalCounts(readers[1].indexReader,
- readers[1].taxReader, iParams, null);
+ totalCounts1 = TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams);
assertTrue("with cache of size 2 res no. 0 should come from cache",
- totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams, null));
+ totalCounts0 == TFC.getTotalCounts(readers[0].indexReader, readers[0].taxReader, iParams));
assertTrue("with cache of size 2 res no. 1 should come from cache",
- totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null));
+ totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams));
writers[0].close();
writers[1].close();
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java Fri Jan 18 22:38:56 2013
@@ -32,12 +32,12 @@ public class FacetRequestTest extends Lu
@Test(expected=IllegalArgumentException.class)
public void testIllegalNumResults() throws Exception {
- new CountFacetRequest(new CategoryPath("a", "b"), 0);
+ assertNotNull(new CountFacetRequest(new CategoryPath("a", "b"), 0));
}
@Test(expected=IllegalArgumentException.class)
public void testIllegalCategoryPath() throws Exception {
- new CountFacetRequest(null, 1);
+ assertNotNull(new CountFacetRequest(null, 1));
}
@Test
Modified: lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java?rev=1435384&r1=1435383&r2=1435384&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (original)
+++ lucene/dev/branches/lucene4547/lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java Fri Jan 18 22:38:56 2013
@@ -1,13 +1,5 @@
package org.apache.lucene.facet.search.params;
-import org.apache.lucene.facet.index.params.FacetIndexingParams;
-import org.apache.lucene.facet.taxonomy.CategoryPath;
-import org.apache.lucene.facet.taxonomy.TaxonomyReader;
-import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
-import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
-import org.apache.lucene.facet.util.PartitionsUtils;
-import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;
@@ -31,28 +23,6 @@ import org.junit.Test;
public class FacetSearchParamsTest extends LuceneTestCase {
@Test
- public void testAddFacetRequest() throws Exception {
- FacetSearchParams fsp = new FacetSearchParams(new CountFacetRequest(new CategoryPath("a", "b"), 1));
- assertEquals("expected 1 facet request", 1, fsp.getFacetRequests().size());
- }
-
- @Test
- public void testPartitionSizeWithCategories() throws Exception {
- Directory dir = newDirectory();
- TaxonomyWriter tw = new DirectoryTaxonomyWriter(dir);
- tw.addCategory(new CategoryPath("a"));
- tw.commit();
- tw.close();
- TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
- assertEquals("unexpected partition offset for 1 categories", 2,
- PartitionsUtils.partitionOffset(FacetIndexingParams.ALL_PARENTS, 1, tr));
- assertEquals("unexpected partition size for 1 categories", 2,
- PartitionsUtils.partitionSize(FacetIndexingParams.ALL_PARENTS,tr));
- tr.close();
- dir.close();
- }
-
- @Test
public void testSearchParamsWithNullRequest() throws Exception {
try {
assertNull(new FacetSearchParams());