Package com.yahoo.prelude.query
Class PhraseItem
-
- All Implemented Interfaces:
HasIndexItem
,IndexedItem
,TaggableItem
,Cloneable
- Direct Known Subclasses:
UriItem
public class PhraseItem extends CompositeIndexedItem
A term which contains a phrase - a collection of word terms- Author:
- bratseth, havardpe
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.yahoo.prelude.query.Item
Item.ItemCreator, Item.ItemType
-
-
Field Summary
-
Fields inherited from class com.yahoo.prelude.query.Item
connectedBacklink, connectedItem, connectivity, DEFAULT_WEIGHT, explicitSignificance, significance, uniqueID
-
-
Constructor Summary
Constructors Constructor Description PhraseItem()
Creates an empty phrasePhraseItem(String indexName)
Creates an empty phrase which will search the given indexPhraseItem(String[] words)
Creates a phrase containing the given words
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addItem(int index, Item item)
Inserts the item at a position and increases the index of existing items starting on this position by onevoid
addItem(Item item)
Adds subitem.protected void
appendBodyString(StringBuilder buffer)
Override to append the item body in the canonical query language of this item.protected void
appendHeadingString(StringBuilder buffer)
Phrase items uses a empty heading instead of "PHRASE "void
disclose(Discloser discloser)
int
encode(ByteBuffer buffer)
protected void
encodeThis(ByteBuffer buffer)
Encodes just this item, not it's usual subitems, to the given buffer.protected int
encodingArity()
boolean
equals(Object other)
Returns whether this item is of the same class and contains the same state as the given itemOptional<Item>
extractSingleChild()
Will return its single child if itself can safely be omitted.BlockItem
getBlockItem(int index)
Returns a subitem as a block item,String
getIndexedString()
Return the searchable term contents of this item.Item.ItemType
getItemType()
Return the enumerated type of this item.String
getName()
Returns the name of this itemint
getNumWords()
Returns how many phrase words does this item containWordItem
getWordItem(int index)
Returns a subitem as a word itemint
hashCode()
boolean
isExplicit()
Returns whether this was explicitly written as a phrase using quotes by the user Default is falsevoid
setExplicit(boolean explicit)
Sets whether this was explicitly written as a phrase using quotes by the uservoid
setIndexName(String index)
Sets the name of the index to searchItem
setItem(int index, Item item)
Replaces the item at the given index.protected boolean
shouldParenthize()
Returns false, no parenthezes for phrases-
Methods inherited from class com.yahoo.prelude.query.CompositeIndexedItem
appendIndexString, getIndexName
-
Methods inherited from class com.yahoo.prelude.query.CompositeTaggableItem
getConnectedItem, getConnectivity, getSignificance, getUniqueID, hasExplicitSignificance, hasUniqueID, setConnectivity, setExplicitSignificance, setSignificance, setUniqueID
-
Methods inherited from class com.yahoo.prelude.query.CompositeItem
adding, clone, ensureNotInSubtree, getItem, getItemCount, getItemIndex, getItemIterator, getTermCount, isLocked, items, lock, removeItem, removeItem
-
Methods inherited from class com.yahoo.prelude.query.Item
addAnnotation, getAnnotation, getBytes, getCode, getCreator, getLabel, getLanguage, getParent, getWeight, hasAnnotation, hasConnectivityBackLink, isFilter, isFromSpecialToken, isProtected, isRanked, isRoot, putBytes, putString, setCreator, setFilter, setFromSpecialToken, setHasUniqueID, setLabel, setLanguage, setParent, setPositionData, setProtected, setRanked, setWeight, toString, usePositionData
-
-
-
-
Method Detail
-
getItemType
public Item.ItemType getItemType()
Description copied from class:Item
Return the enumerated type of this item.- Specified by:
getItemType
in classItem
-
setIndexName
public void setIndexName(String index)
Description copied from class:CompositeIndexedItem
Sets the name of the index to search- Specified by:
setIndexName
in interfaceIndexedItem
- Overrides:
setIndexName
in classCompositeIndexedItem
-
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 classCompositeItem
- Throws:
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 classCompositeItem
-
setItem
public Item setItem(int index, Item item)
Description copied from class:CompositeItem
Replaces the item at the given index.- Overrides:
setItem
in classCompositeItem
- Parameters:
index
- the (0-base) index of the item to replaceitem
- the new item- Returns:
- the old item at this position. The parent of the old item is not cleared
-
extractSingleChild
public Optional<Item> extractSingleChild()
Description copied from class:CompositeItem
Will return its single child if itself can safely be omitted.- Overrides:
extractSingleChild
in classCompositeItem
- 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:
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:
IndexOutOfBoundsException
- if there is no subitem at index
-
encodeThis
protected void encodeThis(ByteBuffer buffer)
Description copied from class:CompositeItem
Encodes just this item, not it's usual subitems, to the given buffer.- Overrides:
encodeThis
in classCompositeIndexedItem
-
encode
public int encode(ByteBuffer buffer)
- Overrides:
encode
in classCompositeItem
-
shouldParenthize
protected boolean shouldParenthize()
Returns false, no parenthezes for phrases- Overrides:
shouldParenthize
in classCompositeItem
-
appendHeadingString
protected void appendHeadingString(StringBuilder buffer)
Phrase items uses a empty heading instead of "PHRASE "- Overrides:
appendHeadingString
in classItem
-
appendBodyString
protected void appendBodyString(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 classCompositeItem
-
getIndexedString
public String getIndexedString()
Description copied from interface:IndexedItem
Return the searchable term contents of this item.- Specified by:
getIndexedString
in interfaceIndexedItem
- Specified by:
getIndexedString
in classCompositeIndexedItem
- Returns:
- a string representation of what is presumably stored in an index which will match this item
-
encodingArity
protected int encodingArity()
- Overrides:
encodingArity
in classCompositeItem
-
getNumWords
public int getNumWords()
Description copied from interface:HasIndexItem
Returns how many phrase words does this item contain
-
disclose
public void disclose(Discloser discloser)
- Overrides:
disclose
in classCompositeIndexedItem
-
equals
public boolean equals(Object other)
Description copied from class:CompositeItem
Returns whether this item is of the same class and contains the same state as the given item- Overrides:
equals
in classCompositeIndexedItem
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classCompositeIndexedItem
-
-