public abstract class Item extends Object implements 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.
Modifier and Type | Class and 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/searchlib/parsequery/parse.h
|
Modifier and Type | Field and Description |
---|---|
private com.yahoo.collections.CopyOnWriteHashMap<String,Object> |
annotations
The annotations made on this item
|
protected Item |
connectedBacklink |
protected Item |
connectedItem
Items for explicit connectivity
|
protected double |
connectivity |
private Item.ItemCreator |
creator |
static int |
DEFAULT_WEIGHT |
protected boolean |
explicitSignificance |
private boolean |
fromSpecialToken |
private boolean |
hasUniqueID
Whether the item should encode a unique ID
|
private boolean |
isProtected
Whether this item is eligible for change by query rewriters (false) or should be kept as-is (true)
|
private boolean |
isRanked
Whether or not this item should affect ranking.
|
private String |
label
Optional symbolic name for this item, requires unique id
|
private com.yahoo.language.Language |
language |
private CompositeItem |
parent
The parent in the query tree, or null if this is a root
|
protected double |
significance
Explicit term significance
|
protected int |
uniqueID
Unique identifier to address the item for external annotation
|
private boolean |
usePositionData
Whether or not position data should be used when ranking this item
|
private int |
weight
The relative importance of this term in the query.
|
Constructor and Description |
---|
Item() |
Modifier and Type | Method and Description |
---|---|
void |
addAnnotation(String key,
Object value)
Annotate this item
|
protected abstract void |
appendBodyString(StringBuilder buffer)
Override to append the item body in the canonical query language of this item.
|
protected void |
appendHeadingString(StringBuilder buffer)
Appends the heading of this string.
|
Item |
clone()
Returns a deep copy of this item
|
void |
disclose(Discloser discloser) |
abstract int |
encode(ByteBuffer buffer) |
protected void |
encodeThis(ByteBuffer buffer) |
boolean |
equals(Object object)
Returns whether this item is of the same class and
contains the same state as the given item
|
Object |
getAnnotation(String annotation)
Returns an annotation on this item, or null if the annotation is not set
|
protected static byte[] |
getBytes(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.
|
private byte |
getFlagsFeature()
Returns an integer that contains all feature flags for this item.
|
abstract Item.ItemType |
getItemType()
Return the enumerated type of this item.
|
String |
getLabel()
Obtain 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 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(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,
ByteBuffer buffer) |
static void |
putString(String s,
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(String index)
Sets the index name of this item
|
void |
setLabel(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.
|
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
|
public static final int DEFAULT_WEIGHT
private int weight
private boolean fromSpecialToken
private Item.ItemCreator creator
private CompositeItem parent
private com.yahoo.collections.CopyOnWriteHashMap<String,Object> annotations
private boolean isRanked
private boolean usePositionData
private boolean hasUniqueID
private String label
protected int uniqueID
protected Item connectedItem
protected Item connectedBacklink
protected double connectivity
protected double significance
protected boolean explicitSignificance
private boolean isProtected
private com.yahoo.language.Language language
public abstract void setIndexName(String index)
public final int getCode()
public abstract Item.ItemType getItemType()
public abstract String getName()
public void setFilter(boolean filter)
public boolean isFilter()
public Item.ItemCreator getCreator()
public void setCreator(Item.ItemCreator creator)
public void setWeight(int w)
public int getWeight()
public void addAnnotation(String key, Object value)
key
- the annotation keyvalue
- the value, or null to set a valueless annotationpublic Object getAnnotation(String annotation)
public boolean hasAnnotation(String annotation)
public void setProtected(boolean isProtected)
public boolean isProtected()
public void setParent(CompositeItem parent)
public CompositeItem getParent()
public abstract int encode(ByteBuffer buffer)
protected void encodeThis(ByteBuffer buffer)
private byte getFlagsFeature()
protected static final byte[] getBytes(String string)
public static void putString(String s, ByteBuffer buffer)
public static void putBytes(byte[] bytes, ByteBuffer buffer)
public abstract int getTermCount()
public 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
protected boolean shouldParenthize()
protected void appendHeadingString(StringBuilder buffer)
protected abstract void appendBodyString(StringBuilder buffer)
([itemName] [body])The body must be appended appended by this method.
public boolean equals(Object object)
protected boolean hasUniqueID()
protected void setHasUniqueID(boolean hasUniqueID)
public void setLabel(String label)
label
- label for this itempublic String getLabel()
public void setRanked(boolean isRanked)
public boolean isRanked()
public void setPositionData(boolean usePositionData)
public boolean usePositionData()
public void disclose(Discloser discloser)
public boolean isFromSpecialToken()
public void setFromSpecialToken(boolean fromSpecialToken)
public com.yahoo.language.Language getLanguage()
public void setLanguage(com.yahoo.language.Language language)
public boolean hasConnectivityBackLink()
public boolean isRoot()
Copyright © 2018. All rights reserved.