Class Item

  • All Implemented Interfaces:
    Cloneable
    Direct Known Subclasses:
    CompositeItem, FalseItem, NullItem, PureWeightedItem, SimpleTaggableItem, TrueItem

    public abstract class Item
    extends Object
    implements Cloneable
    An item in the tree which defines which documents will match a query. Item subclasses can be composed freely to create arbitrary complex matching trees. 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).
    Author:
    bratseth, havardpe
    • Field Detail

      • uniqueID

        protected int uniqueID
        Unique identifier to address the item for external annotation
      • connectedItem

        protected Item connectedItem
        Items for explicit connectivity
      • connectedBacklink

        protected Item connectedBacklink
      • connectivity

        protected double connectivity
      • significance

        protected double significance
        Explicit term significance
      • explicitSignificance

        protected boolean explicitSignificance
    • Constructor Detail

      • Item

        public Item()
    • Method Detail

      • setIndexName

        public abstract void setIndexName​(String index)
        Sets the index name of this item
      • getCode

        public final int getCode()
        Returns the int code of this item
      • getItemType

        public abstract Item.ItemType getItemType()
        Return the enumerated type of this item.
      • getName

        public abstract String getName()
        Returns the name of this item
      • setFilter

        public void setFilter​(boolean filter)
        Sets whether this is a filter term. This indicates that the term origins from the filter parameter in the search API. The search backend does not handle filter terms any different than non-filter terms.
      • isFilter

        public boolean isFilter()
        Returns whether this is a filter term
      • getCreator

        public Item.ItemCreator getCreator()
        Returns the item creator value.
      • setCreator

        public void setCreator​(Item.ItemCreator creator)
        Sets the item creator value.
      • setWeight

        public void setWeight​(int w)
        Sets the relative importance of this term
      • getWeight

        public int getWeight()
        Returns the relative importance of this term. Default is 100.
      • addAnnotation

        public void addAnnotation​(String key,
                                  Object value)
        Annotate this item
        Parameters:
        key - the annotation key
        value - the value, or null to set a valueless annotation
      • getAnnotation

        public Object getAnnotation​(String annotation)
        Returns an annotation on this item, or null if the annotation is not set
      • hasAnnotation

        public boolean hasAnnotation​(String annotation)
        Returns whether this has an annotation
      • setProtected

        public void setProtected​(boolean isProtected)
        Set whether this should be protected from change/remove by query rewriters
      • isProtected

        public boolean isProtected()
        Returns whether this is to be protected from change/remove by query rewriters. default is false
      • setParent

        public void setParent​(CompositeItem parent)
        Sets the parent in the tree. Do not use: Only to be called from CompositeItem/QueryTree
      • getParent

        public CompositeItem getParent()
        Returns the parent in the query tree, or null if this node has no parent
      • encode

        public abstract int encode​(ByteBuffer buffer)
      • encodeThis

        protected void encodeThis​(ByteBuffer buffer)
      • getBytes

        protected static byte[] getBytes​(String string)
        Utility method for turning a string into utf-8 bytes
      • putBytes

        public static void putBytes​(byte[] bytes,
                                    ByteBuffer buffer)
      • getTermCount

        public abstract int getTermCount()
      • toString

        public String toString()
        Returns the canonical query language string of this item. The canonical language represent an item by the string
         ([itemName] [body])
         
        where the body may recursively be other items.
        Overrides:
        toString in class Object
      • shouldParenthesize

        protected boolean shouldParenthesize()
        Returns whether this item should be parenthesized when printed. Default is false - no parentheses
      • appendHeadingString

        protected void appendHeadingString​(StringBuilder buffer)
        Appends the heading of this string. As default getName() followed by a space.
      • appendBodyString

        protected abstract void appendBodyString​(StringBuilder buffer)
        Override to append the item body in the canonical query language of this item. An item is usually represented by the string
         ([itemName] [body])
         
        The body must be appended appended by this method.
      • clone

        public Item clone()
        Returns a deep copy of this item
        Overrides:
        clone in class Object
      • equals

        public boolean equals​(Object o)
        Returns whether this item is of the same class and contains the same state as the given item.
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • hasUniqueID

        protected boolean hasUniqueID()
      • setHasUniqueID

        protected void setHasUniqueID​(boolean hasUniqueID)
      • setLabel

        public void setLabel​(String label)
        Label this item with a symbolic name which can later be used by the back-end to identify specific items for ranking purposes.
        Parameters:
        label - label for this item
      • getLabel

        public String getLabel()
        Returns the label for this item. This method will return null if no label has been set.
      • setRanked

        public void setRanked​(boolean isRanked)
        Sets whether this term item should affect ranking. If set to false this term is not exposed to the ranking framework in the search backend.
      • isRanked

        public boolean isRanked()
        Returns whether or not this item should affect ranking.
      • setPositionData

        public void setPositionData​(boolean usePositionData)
        Sets whether position data should be used when ranking this term item. If set to false the search backend uses fast bit vector data structures when matching on this term and only a few simple ranking features will be available when ranking this term. Note that setting this to false also saves a lot of CPU during matching as bit vector data structures are used.
      • usePositionData

        public boolean usePositionData()
        Returns whether position data should be used when ranking this item
      • disclose

        public void disclose​(Discloser discloser)
      • isFromSpecialToken

        public boolean isFromSpecialToken()
      • setFromSpecialToken

        public void setFromSpecialToken​(boolean fromSpecialToken)
      • getLanguage

        public com.yahoo.language.Language getLanguage()
        Returns the language of any natural language text below this item, or Language.UNKNOWN if not set.
      • setLanguage

        public void setLanguage​(com.yahoo.language.Language language)
        Sets the language of any natural language text below this item. This cannot be set to null but can be set to Language.UNKNOWN
      • hasConnectivityBackLink

        public boolean hasConnectivityBackLink()
        DO NOT USE
      • isRoot

        public boolean isRoot()
        Returns true if this is the root item - that is if the parent is the QueryTree (or null for legacy reasons)