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 |
---|---|
private static QueryProfileType |
argumentType |
private QueryContext |
context
The context, or null if there is no context
|
private static long |
defaultTimeout |
private static long |
dumpTimeout |
static com.yahoo.processing.request.CompoundName |
GROUPING_SESSION_CACHE |
private boolean |
groupingSessionCache
Whether or not grouping should use a session cache
|
private int |
hits
The number of hits to return
|
static com.yahoo.processing.request.CompoundName |
HITS |
private com.yahoo.container.jdisc.HttpRequest |
httpRequest
The synchronous view of the JDisc request causing this query.
|
private static Logger |
log |
private Model |
model
The query query and/or query program declaration
|
static com.yahoo.processing.request.CompoundName |
NO_CACHE |
private boolean |
noCache
Whether this query is forbidden to access cached information
|
private int |
offset
The offset from the most relevant hits found from this query
|
static com.yahoo.processing.request.CompoundName |
OFFSET |
private Presentation |
presentation
How results of this query should be presented
|
private static Map<String,com.yahoo.processing.request.CompoundName> |
propertyAliases
The aliases of query properties, these are always the same
|
private Ranking |
ranking
The ranking requested in this query
|
private UniqueRequestId |
requestId
Used for downstream session caches
|
static com.yahoo.processing.request.CompoundName |
SEARCH_CHAIN |
private long |
startTime
The time this query was created
|
private long |
timeout
The timeout of the query, in milliseconds
|
static com.yahoo.processing.request.CompoundName |
TIMEOUT |
static com.yahoo.processing.request.CompoundName |
TRACE_LEVEL |
private int |
traceLevel
The query context level, 0 means no tracing
|
Modifier | 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(Query query) |
private |
Query(Query query,
long startTime) |
|
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 |
---|---|
private static void |
addAliases(QueryProfileType arguments,
Map<String,com.yahoo.processing.request.CompoundName> aliases) |
static void |
addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) |
private void |
appendQueryProfileProperties(CompiledQueryProfile profile,
Set<String> mentioned,
StringBuilder b) |
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
|
private void |
commaSeparated(StringBuilder yql,
Set<String> fields) |
private void |
copyPropertiesTo(Query clone) |
private Map<String,Boolean> |
createCacheSettingMap() |
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.
|
private static String |
getPrefix(QueryProfileType type) |
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
|
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.
|
private void |
init(Map<String,String> requestMap,
CompiledQueryProfile queryProfile) |
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.
|
private String |
queryTreeText() |
boolean |
requestHasProperty(String name) |
private Map<String,String> |
requestProperties() |
void |
resetTimeout()
Resets the start time of the query.
|
private void |
serializeSorting(StringBuilder yql) |
void |
setCompress(boolean ignored)
Deprecated.
this is ignored
|
private void |
setFieldsFrom(Properties properties,
Map<String,String> context)
Calls properties().set on each value in the given properties which is declared in this query or
one of its dependent objects.
|
private void |
setFrom(Properties originalProperties,
QueryProfileType arguments,
Map<String,String> context)
For each field in the given query profile type, take the corresponding value from originalProperties
(if any) set it to properties().
|
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.
|
private void |
setPropertiesFromRequestMap(Map<String,String> requestMap,
Properties properties)
Calls properties.set on all entries in requestMap
|
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.
|
private void |
traceProperties()
Traces how properties was resolved and from where.
|
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+.
|
private int offset
private int hits
private int traceLevel
private static final long dumpTimeout
private static final long defaultTimeout
private long timeout
private boolean noCache
private boolean groupingSessionCache
private final com.yahoo.container.jdisc.HttpRequest httpRequest
private QueryContext context
private UniqueRequestId requestId
private Ranking ranking
private Model model
private Presentation presentation
private static Logger log
private long startTime
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
private static QueryProfileType argumentType
public Query()
public Query(String query)
?query=test&offset=10&hits=13
The query must be uri encoded.public 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)
request
- the HTTP request from which this is createdpublic Query(Query query)
private Query(Query query, long startTime)
public static QueryProfileType getArgumentType()
private static void addAliases(QueryProfileType arguments, Map<String,com.yahoo.processing.request.CompoundName> aliases)
private static String getPrefix(QueryProfileType type)
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry)
private void init(Map<String,String> requestMap, CompiledQueryProfile queryProfile)
public static Query createNewQuery(Query query)
private void setFieldsFrom(Properties properties, Map<String,String> context)
private void setFrom(Properties originalProperties, QueryProfileType arguments, Map<String,String> context)
private void setPropertiesFromRequestMap(Map<String,String> requestMap, Properties properties)
public Properties properties()
properties
in class com.yahoo.processing.Request
private void traceProperties()
private void appendQueryProfileProperties(CompiledQueryProfile profile, Set<String> mentioned, StringBuilder b)
public String validate()
public long getStartTime()
public long getDurationTime()
public long getTimeLeft()
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.private String queryTreeText()
public String yqlRepresentation()
yqlRepresentation(Tuple2, boolean)
private void commaSeparated(StringBuilder yql, Set<String> fields)
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 treeprivate void serializeSorting(StringBuilder yql)
public QueryContext getContext(boolean create)
public int hashCode()
public boolean equals(Object other)
public Query clone()
clone
in class com.yahoo.processing.Request
private void copyPropertiesTo(Query clone)
public Presentation getPresentation()
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.