Class Item

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    CompositeItem, FalseItem, NullItem, PureWeightedItem, SimpleTaggableItem

    public abstract class Item
    extends java.lang.Object
    implements java.lang.Cloneable

    A term of the query language. As "term" is also the common term (sorry) for a literal to be found (or not) in a search index, the term item is used for query language terms.

    The query is represented as a composite tree of Item subclasses. This allow arbitrary complex combinations of ands, nots, phrases and so on.

    Items are in general mutable and not thread safe.

    Author:
    bratseth, havardpe
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Item.ItemCreator
      The definitions in Item.ItemCreator must match the ones in searchlib/src/searchlib/parsequery/parse.h
      static class  Item.ItemType
      The definitions in Item.ItemType must match the ones in searchlib/src/vespa/searchlib/parsequery/parse.h
    • Constructor Summary

      Constructors 
      Constructor Description
      Item()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addAnnotation​(java.lang.String key, java.lang.Object value)
      Annotate this item
      protected abstract void appendBodyString​(java.lang.StringBuilder buffer)
      Override to append the item body in the canonical query language of this item.
      protected void appendHeadingString​(java.lang.StringBuilder buffer)
      Appends the heading of this string.
      Item clone()
      Returns a deep copy of this item
      void disclose​(Discloser discloser)  
      abstract int encode​(java.nio.ByteBuffer buffer)  
      protected void encodeThis​(java.nio.ByteBuffer buffer)  
      boolean equals​(java.lang.Object object)
      Returns whether this item is of the same class and contains the same state as the given item
      java.lang.Object getAnnotation​(java.lang.String annotation)
      Returns an annotation on this item, or null if the annotation is not set
      protected static byte[] getBytes​(java.lang.String string)
      Utility method for turning a string into utf-8 bytes
      int getCode()
      Returns the int code of this item
      Item.ItemCreator getCreator()
      Returns the item creator value.
      abstract Item.ItemType getItemType()
      Return the enumerated type of this item.
      java.lang.String getLabel()
      Returns the label for this item.
      com.yahoo.language.Language getLanguage()
      Returns the language of any natural language text below this item, or Language.UNKNOWN if not set.
      abstract java.lang.String getName()
      Returns the name of this item
      CompositeItem getParent()
      Returns the parent in the query tree, or null if this node has no parent
      abstract int getTermCount()  
      int getWeight()
      Returns the relative importance of this term.
      boolean hasAnnotation​(java.lang.String annotation)
      Returns whether this has an annotation
      boolean hasConnectivityBackLink()
      DO NOT USE
      int hashCode()  
      protected boolean hasUniqueID()  
      boolean isFilter()
      Returns whether this is a filter term
      boolean isFromSpecialToken()  
      boolean isProtected()
      Returns whether this is to be protected from change/remove by query rewriters.
      boolean isRanked()
      Returns whether or not this item should affect ranking.
      boolean isRoot()
      Returns true if this is the root item - that is if the parent is the QueryTree (or null for legacy reasons)
      static void putBytes​(byte[] bytes, java.nio.ByteBuffer buffer)  
      static void putString​(java.lang.String s, java.nio.ByteBuffer buffer)  
      void setCreator​(Item.ItemCreator creator)
      Sets the item creator value.
      void setFilter​(boolean filter)
      Sets whether this is a filter term.
      void setFromSpecialToken​(boolean fromSpecialToken)  
      protected void setHasUniqueID​(boolean hasUniqueID)  
      abstract void setIndexName​(java.lang.String index)
      Sets the index name of this item
      void setLabel​(java.lang.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.
      void setLanguage​(com.yahoo.language.Language language)
      Sets the language of any natural language text below this item.
      void setParent​(CompositeItem parent)
      Sets the parent in the tree.
      void setPositionData​(boolean usePositionData)
      Sets whether or not position data should be used when ranking this term item.
      void setProtected​(boolean isProtected)
      Set whether this should be protected from change/remove by query rewriters
      void setRanked​(boolean isRanked)
      Sets whether or not this term item should affect ranking.
      void setWeight​(int w)
      Sets the relative importance of this term
      protected boolean shouldParenthize()
      Returns whether or not this item should be parethized when printed.
      java.lang.String toString()
      Returns the canonical query language string of this item.
      boolean usePositionData()
      Returns whether or not position data should be used when ranking this item
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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​(java.lang.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 java.lang.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​(java.lang.String key,
                                  java.lang.Object value)
        Annotate this item
        Parameters:
        key - the annotation key
        value - the value, or null to set a valueless annotation
      • getAnnotation

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

        public boolean hasAnnotation​(java.lang.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​(java.nio.ByteBuffer buffer)
      • encodeThis

        protected void encodeThis​(java.nio.ByteBuffer buffer)
      • getBytes

        protected static final byte[] getBytes​(java.lang.String string)
        Utility method for turning a string into utf-8 bytes
      • putString

        public static void putString​(java.lang.String s,
                                     java.nio.ByteBuffer buffer)
      • putBytes

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

        public abstract int getTermCount()
      • toString

        public java.lang.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.

        TODO: Change the output query language into a canonical form of the input query language

        Overrides:
        toString in class java.lang.Object
      • shouldParenthize

        protected boolean shouldParenthize()
        Returns whether or not this item should be parethized when printed. Default is false - no parentheses
      • appendHeadingString

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

        protected abstract void appendBodyString​(java.lang.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 java.lang.Object
      • equals

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

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

        protected boolean hasUniqueID()
      • setHasUniqueID

        protected void setHasUniqueID​(boolean hasUniqueID)
      • setLabel

        public void setLabel​(java.lang.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 java.lang.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 or not 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 or not 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 or not 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)