Class NotItem

All Implemented Interfaces:
Cloneable

public class NotItem extends CompositeItem
A composite item where the first item is positive and the following items are negative items where matches should exclude the document should from the result. The default positive item, if only negatives are added, is TrueItem: Meaning that all documents are matched except those matching the negative terms added.
Author:
bratseth
  • Constructor Details

    • NotItem

      public NotItem()
  • Method Details

    • 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 String getName()
      Description copied from class: Item
      Returns the name of this item
      Specified by:
      getName in class Item
    • addItem

      public void addItem(Item item)
      Adds an item. The first item is the positive, the rest are negative
      Overrides:
      addItem in class CompositeItem
    • addNegativeItem

      public void addNegativeItem(Item negative)
      Adds a negative item. Like addItem but skips the first position (position 0) if it is not already set.
    • negativeItems

      public List<Item> negativeItems()
      Returns the negative items of this: All child items except the first
    • getPositiveItem

      public Item getPositiveItem()
      Returns the positive item (the first subitem), or TrueItem if no positive items has been added.
    • setPositiveItem

      public Item setPositiveItem(Item item)
      Sets the positive item (the first item)
      Returns:
      the old positive item, or TrueItem if there was none
    • addPositiveItem

      public void addPositiveItem(Item item)
      Convenience method for adding a positive item. If a positive item is already present the positive item becomes an AndItem with the items added
    • removeItem

      public boolean removeItem(Item item)
      Description copied from class: CompositeItem
      Removes the given item. Does nothing if the item is not present.
      Overrides:
      removeItem in class CompositeItem
      Parameters:
      item - the item to remove
      Returns:
      whether the item was removed
    • removeItem

      public Item removeItem(int index)
      Description copied from class: CompositeItem
      Removes the item at the given index
      Overrides:
      removeItem in class CompositeItem
      Parameters:
      index - the index of the item to remove
      Returns:
      the removed item
    • appendHeadingString

      protected void appendHeadingString(StringBuilder buffer)
      Not items uses a empty heading instead of "NOT "
      Overrides:
      appendHeadingString in class Item
    • appendBodyString

      protected void appendBodyString(StringBuilder buffer)
      Overridden to skip the positive TrueItem and (otherwise) append "+" to the first item and "-" to the rest
      Overrides:
      appendBodyString in class CompositeItem
    • getTermCount

      public int getTermCount()
      Returns the number of actual *positive* terms in this
      Overrides:
      getTermCount in class CompositeItem