diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/Item.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/Item.java | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/Item.java b/container-search/src/main/java/com/yahoo/prelude/query/Item.java index 92b321adb70..06fe07d3895 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/Item.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/Item.java @@ -11,7 +11,6 @@ import com.yahoo.text.Utf8; import java.nio.ByteBuffer; import java.util.Objects; -import java.util.Optional; /** @@ -20,7 +19,7 @@ import java.util.Optional; * Items are in general mutable and not thread safe. * They can be deeply cloned by calling clone(). * Their identity is defined by their content - * (i.e the field value of two items decide if they are equal). + * (i.e. the field value of two items decide if they are equal). * * @author bratseth * @author havardpe @@ -60,7 +59,8 @@ public abstract class Item implements Cloneable { NEAREST_NEIGHBOR(26), GEO_LOCATION_TERM(27), TRUE(28), - FALSE(29); + FALSE(29), + MULTI_TERM(30); public final int code; @@ -233,36 +233,34 @@ public abstract class Item implements Cloneable { public abstract int encode(ByteBuffer buffer); protected void encodeThis(ByteBuffer buffer) { - int FEAT_SHIFT = 5; - int CODE_MASK = 0x1f; - int FEAT_MASK = 0xe0; - int FEAT_WEIGHT = 0x01; - int FEAT_UNIQUEID = 0x02; - int FEAT_FLAGS = 0x04; + byte CODE_MASK = 0b00011111; + byte FEAT_WEIGHT = 0b00100000; + byte FEAT_UNIQUEID = 0b01000000; + byte FEAT_FLAGS = -0b10000000; - int features = 0; + byte type = (byte) (getCode() & CODE_MASK); + if (type != getCode()) + throw new IllegalStateException("must increase number of bytes in serialization format for queries"); if (weight != DEFAULT_WEIGHT) { - features |= FEAT_WEIGHT; + type |= FEAT_WEIGHT; } if (hasUniqueID()) { - features |= FEAT_UNIQUEID; + type |= FEAT_UNIQUEID; } byte flags = getFlagsFeature(); if (flags != 0) { - features |= FEAT_FLAGS; + type |= FEAT_FLAGS; } - byte type = (byte)(((getCode() & CODE_MASK) - | ((features << FEAT_SHIFT) & FEAT_MASK)) & 0xff); buffer.put(type); - if ((features & FEAT_WEIGHT) != 0) { + if ((type & FEAT_WEIGHT) != 0) { IntegerCompressor.putCompressedNumber(weight, buffer); } - if ((features & FEAT_UNIQUEID) != 0) { + if ((type & FEAT_UNIQUEID) != 0) { IntegerCompressor.putCompressedPositiveNumber(uniqueID, buffer); } - if (flags != 0) { + if ((type & FEAT_FLAGS) != 0) { buffer.put(flags); } } @@ -297,7 +295,7 @@ public abstract class Item implements Cloneable { /** Utility method for turning a string into utf-8 bytes */ - protected static final byte[] getBytes(String string) { + protected static byte[] getBytes(String string) { return Utf8.toBytes(string); } public static void putString(String s, ByteBuffer buffer) { @@ -322,7 +320,7 @@ public abstract class Item implements Cloneable { public String toString() { StringBuilder buffer = new StringBuilder(); - if (shouldParenthize()) { + if (shouldParenthesize()) { buffer.append("("); } if (isFilter()) { @@ -330,7 +328,7 @@ public abstract class Item implements Cloneable { } appendHeadingString(buffer); appendBodyString(buffer); - if (shouldParenthize()) { + if (shouldParenthesize()) { buffer.append(")"); } @@ -343,10 +341,10 @@ public abstract class Item implements Cloneable { } /** - * Returns whether this item should be parethized when printed. + * Returns whether this item should be parenthesized when printed. * Default is false - no parentheses */ - protected boolean shouldParenthize() { + protected boolean shouldParenthesize() { return false; } @@ -376,7 +374,7 @@ public abstract class Item implements Cloneable { // note: connectedItem and connectedBacklink references are corrected in CompositeItem.clone() return clone; } catch (CloneNotSupportedException e) { - throw new RuntimeException("Someone made Item unclonable"); + throw new RuntimeException("Someone made Item uncloneable"); } } |