Class PhraseItem

    • Constructor Detail

      • PhraseItem

        public PhraseItem()
        Creates an empty phrase
      • PhraseItem

        public PhraseItem​(java.lang.String indexName)
        Creates an empty phrase which will search the given index
      • PhraseItem

        public PhraseItem​(java.lang.String[] words)
        Creates a phrase containing the given words
    • Method Detail

      • getItemType

        public Item.ItemType getItemType()
        Description copied from class: Item
        Return the enumerated type of this item.
        Specified by:
        getItemType in class Item
      • getName

        public java.lang.String getName()
        Description copied from class: Item
        Returns the name of this item
        Specified by:
        getName in class Item
      • setExplicit

        public void setExplicit​(boolean explicit)
        Sets whether this was explicitly written as a phrase using quotes by the user
      • isExplicit

        public boolean isExplicit()
        Returns whether this was explicitly written as a phrase using quotes by the user Default is false
      • addItem

        public void addItem​(Item item)
        Adds subitem. The word will have its index name set to the index name of this phrase. If the item is a word, it will simply be added, if the item is a phrase, each of the words of the phrase will be added.
        Overrides:
        addItem in class CompositeItem
        Throws:
        java.lang.IllegalArgumentException - if the given item is not a WordItem or PhraseItem
      • addItem

        public void addItem​(int index,
                            Item item)
        Description copied from class: CompositeItem
        Inserts the item at a position and increases the index of existing items starting on this position by one
        Overrides:
        addItem in class CompositeItem
      • setItem

        public Item setItem​(int index,
                            Item item)
        Description copied from class: CompositeItem
        Replaces the item at the given index
        Overrides:
        setItem in class CompositeItem
        Parameters:
        index - the (0-base) index of the item to replace
        item - the new item
        Returns:
        the old item at this position. The parent of the old item is not cleared
      • extractSingleChild

        public java.util.Optional<Item> extractSingleChild()
        Description copied from class: CompositeItem
        Will return its single child if itself can safely be omitted.
        Overrides:
        extractSingleChild in class CompositeItem
        Returns:
        a valid Item or empty Optional if it can not be done
      • getWordItem

        public WordItem getWordItem​(int index)
        Returns a subitem as a word item
        Parameters:
        index - the (0-base) index of the item to return
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no subitem at index
      • getBlockItem

        public BlockItem getBlockItem​(int index)
        Returns a subitem as a block item,
        Parameters:
        index - the (0-base) index of the item to return
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no subitem at index
      • encodeThis

        protected void encodeThis​(java.nio.ByteBuffer buffer)
        Description copied from class: CompositeItem
        Encodes just this item, not it's usual subitems, to the given buffer.
        Overrides:
        encodeThis in class CompositeIndexedItem
      • encode

        public int encode​(java.nio.ByteBuffer buffer)
        Overrides:
        encode in class CompositeItem
      • shouldParenthize

        protected boolean shouldParenthize()
        Returns false, no parenthezes for phrases
        Overrides:
        shouldParenthize in class CompositeItem
      • appendHeadingString

        protected void appendHeadingString​(java.lang.StringBuilder buffer)
        Phrase items uses a empty heading instead of "PHRASE "
        Overrides:
        appendHeadingString in class Item
      • appendBodyString

        protected void appendBodyString​(java.lang.StringBuilder buffer)
        Description copied from class: Item
        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.
        Overrides:
        appendBodyString in class CompositeItem
      • getIndexedString

        public java.lang.String getIndexedString()
        Description copied from interface: IndexedItem
        Return the searchable term contents of this item.
        Specified by:
        getIndexedString in interface IndexedItem
        Specified by:
        getIndexedString in class CompositeIndexedItem
        Returns:
        a string representation of what is presumably stored in an index which will match this item
      • getNumWords

        public int getNumWords()
        Returns:
        how many phrase words does this item contain