public class Query extends com.yahoo.processing.Request implements Cloneable
The Query contains:
The properties has three sources
QueryProfile
- this provides
defaults for the parameters to Searcher components. Note that by using query profile types, the components may
define the set of parameters they support.
The identity of a query is determined by its content.
Modifier and Type | Class and Description |
---|---|
static class |
Query.Type
The type of the query
|
Modifier and Type | Field and Description |
---|---|
static com.yahoo.processing.request.CompoundName |
GROUPING_SESSION_CACHE |
static com.yahoo.processing.request.CompoundName |
HITS |
static List<com.yahoo.processing.request.CompoundName> |
nativeProperties
Returns an unmodifiable list of all the native properties under a Query
|
static com.yahoo.processing.request.CompoundName |
NO_CACHE |
static com.yahoo.processing.request.CompoundName |
OFFSET |
static com.yahoo.processing.request.CompoundName |
SEARCH_CHAIN |
static com.yahoo.processing.request.CompoundName |
TIMEOUT |
static com.yahoo.processing.request.CompoundName |
TRACE_LEVEL |
Constructor and Description |
---|
Query()
Constructs an empty (null) query
|
Query(com.yahoo.container.jdisc.HttpRequest request)
Creates a query from a request
|
Query(com.yahoo.container.jdisc.HttpRequest request,
CompiledQueryProfile queryProfile)
Creates a query from a request
|
Query(com.yahoo.container.jdisc.HttpRequest request,
Map<String,String> requestMap,
CompiledQueryProfile queryProfile)
Creates a query from a request
|
Query(Query query) |
Query(String query)
Construct a query from a string formatted in the http style, e.g
?query=test&offset=10&hits=13
The query must be uri encoded. |
Query(String query,
CompiledQueryProfile queryProfile)
Construct a query from a string formatted in the http style, e.g
?query=test&offset=10&hits=13
The query must be uri encoded. |
Modifier and Type | Method and Description |
---|---|
static void |
addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) |
void |
attachContext(Query query)
Set the context information for another query to be part of this query's
context information.
|
Query |
clone()
Returns a clone of this query
|
static Query |
createNewQuery(Query query)
Creates a new query from another query, but with time sensitive fields reset.
|
int |
encode(ByteBuffer buffer)
Encodes this query onto the given buffer
|
int |
encodeAsProperties(ByteBuffer buffer,
boolean encodeQueryData)
Encodes properties of this query.
|
boolean |
equals(Object other)
Returns whether the given query is equal to this
|
static QueryProfileType |
getArgumentType() |
boolean |
getCompress()
Deprecated.
this always returns false
|
QueryContext |
getContext(boolean create)
Returns the context of this query, possibly creating it if missing.
|
long |
getDurationTime()
Returns the time (in milliseconds) since the query was started/created
|
boolean |
getGroupingSessionCache()
Returns whether this query should use the grouping session cache.
|
int |
getHits()
Returns the number of hits requested by the submitter of this query.
|
com.yahoo.container.jdisc.HttpRequest |
getHttpRequest()
Return the HTTP request which caused this query.
|
Model |
getModel()
Returns the query representation model to be used for this query, never null
|
boolean |
getNoCache()
Returns whether this query should never be served from a cache.
|
int |
getOffset()
Returns the offset from the most relevant hits requested by the submitter
of this query.
|
Presentation |
getPresentation()
Returns the presentation to be used for this query, never null
|
Ranking |
getRanking()
Returns the ranking to be used for this query, never null
|
Select |
getSelect()
Returns the select to be used for this query, never null
|
SessionId |
getSessionId(boolean create)
Returns the unique and stable session id of this query.
|
long |
getStartTime()
Returns the time (in milliseconds since epoch) when this query was started
|
long |
getTimeLeft()
Get the appropriate timeout for the query.
|
long |
getTimeout()
Returns the number of milliseconds to wait for a response from a search backend
before timing it out.
|
int |
getTraceLevel()
Returns the context level of this query, 0 means no tracing
Higher numbers means increasingly more tracing
|
boolean |
hasEncodableProperties() |
int |
hashCode()
Returns a hash of this query based on (some of) its content.
|
boolean |
isTraceable(int level)
Returns the context level of this query, 0 means no tracing
Higher numbers means increasingly more tracing
|
void |
prepare()
Prepares this for binary serialization.
|
Properties |
properties()
Returns the properties of this query.
|
boolean |
requestHasProperty(String name)
Deprecated.
do not use
|
void |
resetTimeout()
Resets the start time of the query.
|
void |
setCompress(boolean ignored)
Deprecated.
this is ignored
|
void |
setGroupingSessionCache(boolean groupingSessionCache)
Sets whether this query should use the grouping session cache.
|
void |
setHits(int hits)
Sets the number of hits requested.
|
void |
setNoCache(boolean noCache)
Sets whether this query should never be server from a cache.
|
void |
setOffset(int offset)
Set the hit offset.
|
void |
setTimeout(long timeout)
Sets the number of milliseconds to wait for a response from a search backend
before time out.
|
void |
setTimeout(String timeoutString)
Sets timeout from a string which will be parsed as a
|
void |
setTraceLevel(int traceLevel)
Sets the context level of this query, 0 means no tracing
Higher numbers means increasingly more tracing
|
void |
setWindow(int offset,
int hits)
Convenience method to set both the offset and the number of hits to return
|
String |
toDetailString()
Returns a string describing this query in more detail
|
String |
toString()
Returns a string describing this query
|
void |
trace(boolean includeQuery,
int traceLevel,
Object... messages)
Adds a trace message to this query
if the trace level of the query is sufficiently high.
|
void |
trace(String message,
boolean includeQuery,
int traceLevel)
Adds a trace message to this query
if the trace level of the query is sufficiently high.
|
void |
trace(String message,
int traceLevel)
Adds a context message to this query and to the info log,
if the context level of the query is sufficiently high.
|
String |
validate()
Validates this query
|
String |
yqlRepresentation()
Serialize this query as YQL+.
|
String |
yqlRepresentation(com.yahoo.collections.Tuple2<String,com.yahoo.component.Version> segmenterVersion,
boolean includeHitsAndOffset)
Serialize this query as YQL+.
|
public static final com.yahoo.processing.request.CompoundName OFFSET
public static final com.yahoo.processing.request.CompoundName HITS
public static final com.yahoo.processing.request.CompoundName SEARCH_CHAIN
public static final com.yahoo.processing.request.CompoundName TRACE_LEVEL
public static final com.yahoo.processing.request.CompoundName NO_CACHE
public static final com.yahoo.processing.request.CompoundName GROUPING_SESSION_CACHE
public static final com.yahoo.processing.request.CompoundName TIMEOUT
public static final List<com.yahoo.processing.request.CompoundName> nativeProperties
public Query()
public Query(String query)
?query=test&offset=10&hits=13
The query must be uri encoded.public Query(com.yahoo.container.jdisc.HttpRequest request)
request
- the HTTP request from which this is createdpublic Query(String query, CompiledQueryProfile queryProfile)
?query=test&offset=10&hits=13
The query must be uri encoded.public Query(com.yahoo.container.jdisc.HttpRequest request, CompiledQueryProfile queryProfile)
request
- the HTTP request from which this is createdqueryProfile
- the query profile to use for this query, or null if none.public Query(com.yahoo.container.jdisc.HttpRequest request, Map<String,String> requestMap, CompiledQueryProfile queryProfile)
request
- the HTTP request from which this is created.requestMap
- the property map of the query.queryProfile
- the query profile to use for this query, or null if none.public Query(Query query)
public static QueryProfileType getArgumentType()
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry)
public static Query createNewQuery(Query query)
public Properties properties()
properties
in class com.yahoo.processing.Request
public String validate()
public long getStartTime()
public long getDurationTime()
public long getTimeLeft()
@Deprecated public boolean requestHasProperty(String name)
public long getTimeout()
Note: If Ranking.RANKFEATURES is turned on, this is hardcoded to 6 minutes.
public void setTimeout(long timeout)
public void setTimeout(String timeoutString)
public void resetTimeout()
public void setTraceLevel(int traceLevel)
public int getTraceLevel()
public final boolean isTraceable(int level)
public boolean getNoCache()
public void setNoCache(boolean noCache)
public boolean getGroupingSessionCache()
public void setGroupingSessionCache(boolean groupingSessionCache)
public int getOffset()
public int getHits()
public void setHits(int hits)
public void setOffset(int offset)
public void setWindow(int offset, int hits)
@Deprecated public void setCompress(boolean ignored)
@Deprecated public boolean getCompress()
public String toString()
public String toDetailString()
public int encode(ByteBuffer buffer)
buffer
- The buffer to encode the query topublic void trace(String message, int traceLevel)
message
- the message to addtraceLevel
- the context level of the message, this method will do nothing
if the traceLevel of the query is lower than this valuepublic void trace(String message, boolean includeQuery, int traceLevel)
message
- the message to addincludeQuery
- true to append the query root stringValue
at the end of the messagetraceLevel
- the context level of the message, this method will do nothing
if the traceLevel of the query is lower than this valuepublic void trace(boolean includeQuery, int traceLevel, Object... messages)
includeQuery
- true to append the query root stringValue at the end of the messagetraceLevel
- the context level of the message, this method will do nothing
if the traceLevel of the query is lower than this valuemessages
- the messages whose toStrings will be concatenated into the trace message.
Concatenation will only happen if the trace level is sufficiently high.public void attachContext(Query query) throws IllegalStateException
This method will always set the argument query's context level to the context level of this query.
query
- The query which should be traced as a part of this query.IllegalStateException
- If the query given as argument already has context
information.public String yqlRepresentation()
yqlRepresentation(Tuple2, boolean)
public String yqlRepresentation(@Nullable com.yahoo.collections.Tuple2<String,com.yahoo.component.Version> segmenterVersion, boolean includeHitsAndOffset)
segmenterVersion
- linguistics metadata used in federation, set to null if the
annotation is not necessaryincludeHitsAndOffset
- whether to include hits and offset parameters converted to a
offset/limit sliceRuntimeException
- if there is a problem serializing the query treepublic QueryContext getContext(boolean create)
public int hashCode()
public boolean equals(Object other)
public Query clone()
clone
in class com.yahoo.processing.Request
public Presentation getPresentation()
public Select getSelect()
public Ranking getRanking()
public Model getModel()
public com.yahoo.container.jdisc.HttpRequest getHttpRequest()
public SessionId getSessionId(boolean create)
create
- if true this is created if not already setpublic boolean hasEncodableProperties()
public int encodeAsProperties(ByteBuffer buffer, boolean encodeQueryData)
buffer
- the buffer to encode toencodeQueryData
- true to encode all properties, false to only include session information, not actual query datapublic void prepare()
This must be invoked after all changes have been made to this query before it is passed on to a receiving backend. Calling it is somewhat expensive, so it should only happen once. If a prepared query is cloned, it stays prepared.
Copyright © 2018. All rights reserved.