Package com.yahoo.prelude.query
Class PhraseItem
- java.lang.Object
-
- All Implemented Interfaces:
HasIndexItem
,IndexedItem
,TaggableItem
,java.lang.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(java.lang.String indexName)
Creates an empty phrase which will search the given indexPhraseItem(java.lang.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(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)
Phrase items uses a empty heading instead of "PHRASE "void
disclose(Discloser discloser)
int
encode(java.nio.ByteBuffer buffer)
protected void
encodeThis(java.nio.ByteBuffer buffer)
Encodes just this item, not it's usual subitems, to the given buffer.protected int
encodingArity()
java.util.Optional<Item>
extractSingleChild()
Will return its single child if itself can safely be omitted.BlockItem
getBlockItem(int index)
Returns a subitem as a block item,java.lang.String
getIndexedString()
Return the searchable term contents of this item.Item.ItemType
getItemType()
Return the enumerated type of this item.java.lang.String
getName()
Returns the name of this itemint
getNumWords()
WordItem
getWordItem(int index)
Returns a subitem as a word itemboolean
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(java.lang.String index)
Sets the name of the index to searchItem
setItem(int index, Item item)
Replaces the item at the given indexprotected boolean
shouldParenthize()
Returns false, no parenthezes for phrases-
Methods inherited from class com.yahoo.prelude.query.CompositeIndexedItem
appendIndexString, equals, getIndexName, hashCode
-
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
-
getName
public java.lang.String getName()
Description copied from class:Item
Returns the name of this item
-
setIndexName
public void setIndexName(java.lang.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:
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 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 java.util.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:
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 classCompositeIndexedItem
-
encode
public int encode(java.nio.ByteBuffer buffer)
- Overrides:
encode
in classCompositeItem
-
shouldParenthize
protected boolean shouldParenthize()
Returns false, no parenthezes for phrases- Overrides:
shouldParenthize
in classCompositeItem
-
appendHeadingString
protected void appendHeadingString(java.lang.StringBuilder buffer)
Phrase items uses a empty heading instead of "PHRASE "- Overrides:
appendHeadingString
in classItem
-
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 classCompositeItem
-
getIndexedString
public java.lang.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()
- Returns:
- how many phrase words does this item contain
-
disclose
public void disclose(Discloser discloser)
- Overrides:
disclose
in classCompositeIndexedItem
-
-