@InterfaceStability.Committed @InterfaceAudience.Public public class SearchQuery extends Object
Bucket
level to perform said query. Also has factory methods for all types of
fts queries (as in the various types a query body can have: term, match, conjunction, ...).Constructor and Description |
---|
SearchQuery(String indexName,
AbstractFtsQuery queryPart)
Prepare an FTS
SearchQuery on an index. |
Modifier and Type | Method and Description |
---|---|
SearchQuery |
addFacet(String facetName,
SearchFacet facet)
Adds one
SearchFacet to the query. |
static BooleanFieldQuery |
booleanField(boolean value)
Prepare a
BooleanFieldQuery body. |
static BooleanQuery |
booleans()
Prepare a
BooleanQuery body. |
SearchQuery |
clearFacets()
Clears all previously added
SearchFacet . |
SearchQuery |
clearHighlight()
Clears any previously configured highlighting.
|
static ConjunctionQuery |
conjuncts(AbstractFtsQuery... queries)
Prepare a
ConjunctionQuery body. |
SearchQuery |
consistentWith(Document... docs)
Sets the consistency to consider for this FTS query to AT_PLUS and
uses the mutation information from the given documents to parameterize
the consistency.
|
SearchQuery |
consistentWith(DocumentFragment... fragments)
Sets the consistency to consider for this FTS query to AT_PLUS and
uses the mutation information from the given document fragments to parameterize
the consistency.
|
SearchQuery |
consistentWith(MutationState mutationState)
Sets the consistency to consider for this FTS query to AT_PLUS and
uses the
MutationState directly to parameterize the consistency. |
static DateRangeQuery |
dateRange()
Prepare a
DateRangeQuery body. |
static DisjunctionQuery |
disjuncts(AbstractFtsQuery... queries)
Prepare a
DisjunctionQuery body. |
static DocIdQuery |
docId(String... docIds)
Prepare a
DocIdQuery body. |
SearchQuery |
explain()
Activates the explanation of each result hit in the response.
|
SearchQuery |
explain(boolean explain)
Activates or deactivates the explanation of each result hit in the response, according to the parameter.
|
JsonObject |
export()
Exports the whole query as a
JsonObject . |
SearchQuery |
fields(String... fields)
Configures the list of fields for which the whole value should be included in the response.
|
static GeoBoundingBoxQuery |
geoBoundingBox(double topLeftLon,
double topLeftLat,
double bottomRightLon,
double bottomRightLat)
Prepare a
GeoBoundingBoxQuery body. |
static GeoDistanceQuery |
geoDistance(double locationLon,
double locationLat,
String distance)
Prepare a
GeoDistanceQuery body. |
Map<String,SearchFacet> |
getFacets() |
String[] |
getFields() |
String[] |
getHighlightFields() |
HighlightStyle |
getHighlightStyle() |
Integer |
getLimit() |
Long |
getServerSideTimeout() |
Integer |
getSkip() |
SearchQuery |
highlight()
Configures the highlighting of matches in the response for all fields, using the server's default highlighting
style.
|
SearchQuery |
highlight(HighlightStyle style,
String... fields)
Configures the highlighting of matches in the response.
|
SearchQuery |
highlight(String... fields)
Configures the highlighting of matches in the response, for the specified fields and using the server's default
highlighting style.
|
String |
indexName() |
void |
injectParams(JsonObject queryJson)
Inject the top level parameters of a query into a prepared
JsonObject
that represents the root of the query. |
SearchQuery |
limit(int limit)
Add a limit to the query on the number of hits it can return.
|
static MatchQuery |
match(String match)
Prepare a
MatchQuery body. |
static MatchAllQuery |
matchAll()
Prepare a
MatchAllQuery body. |
static MatchNoneQuery |
matchNone()
Prepare a
MatchNoneQuery body. |
static MatchPhraseQuery |
matchPhrase(String matchPhrase)
Prepare a
MatchPhraseQuery body. |
static NumericRangeQuery |
numericRange()
Prepare a
NumericRangeQuery body. |
static PhraseQuery |
phrase(String... terms)
Prepare a
PhraseQuery body. |
static PrefixQuery |
prefix(String prefix)
Prepare a
PrefixQuery body. |
AbstractFtsQuery |
query() |
static QueryStringQuery |
queryString(String query)
Prepare a
QueryStringQuery body. |
static RegexpQuery |
regexp(String regexp)
Prepare a
RegexpQuery body. |
SearchQuery |
searchConsistency(SearchConsistency consistency)
Sets the unparameterized consistency to consider for this FTS query.
|
SearchQuery |
serverSideTimeout(long timeout,
TimeUnit unit)
Sets the server side timeout.
|
SearchQuery |
skip(int skip)
Set the number of hits to skip (eg.
|
SearchQuery |
sort(Object... sort)
Configures the list of fields (including special fields) which are used for sorting purposes.
|
static TermQuery |
term(String term)
Prepare a
TermQuery body. |
static TermRangeQuery |
termRange()
Prepare a
TermRangeQuery body. |
static WildcardQuery |
wildcard(String wildcard)
Prepare a
WildcardQuery body. |
public SearchQuery(String indexName, AbstractFtsQuery queryPart)
SearchQuery
on an index. Top level query parameters can be set after that
by using the fluent API.indexName
- the FTS index to search in.queryPart
- the body of the FTS query (eg. a match phrase query).public String indexName()
public AbstractFtsQuery query()
public JsonObject export()
JsonObject
.public void injectParams(JsonObject queryJson)
JsonObject
that represents the root of the query.queryJson
- the prepared JsonObject
for the whole query.public SearchQuery limit(int limit)
limit
- the maximum number of hits to return.public SearchQuery skip(int skip)
skip
- the number of results to skip.public SearchQuery explain()
public SearchQuery explain(boolean explain)
explain
- should the response include an explanation of each hit (true) or not (false)?public SearchQuery highlight(HighlightStyle style, String... fields)
fragments
in each hit
.
Note that to be highlighted, the fields must be stored in the FTS index.style
- the HighlightStyle
to apply.fields
- the optional fields on which to highlight. If none, all fields where there is a match are highlighted.public SearchQuery highlight(String... fields)
fragments
in each hit
.
Note that to be highlighted, the fields must be stored in the FTS index.fields
- the optional fields on which to highlight. If none, all fields where there is a match are highlighted.public SearchQuery highlight()
fragments
in each hit
.
Note that to be highlighted, the fields must be stored in the FTS index.public SearchQuery clearHighlight()
highlight(HighlightStyle, String...)
public SearchQuery fields(String... fields)
fields
in each hit
.
Note that to be highlighted, the fields must be stored in the FTS index.fields
- public SearchQuery sort(Object... sort)
sort
- the fields that should take part in the sorting.public SearchQuery addFacet(String facetName, SearchFacet facet)
SearchFacet
to the query.
This is an additive operation (the given facets are added to any facet previously requested),
but if an existing facet has the same name it will be replaced.
This drives the inclusion of the SearchQueryResult.facets()
facets} in the SearchQueryResult
.
Note that to be faceted, a field's value must be stored in the FTS index.facetName
- the name of the facet to add (or replace if one already exists with same name).facet
- the facet to add.public SearchQuery clearFacets()
SearchFacet
.addFacet(String, SearchFacet)
public SearchQuery serverSideTimeout(long timeout, TimeUnit unit)
searchTimeout
from the environment.timeout
- the server side timeout to apply.unit
- the unit for the timeout.public SearchQuery searchConsistency(SearchConsistency consistency)
consistency
- the simple consistency to use.public SearchQuery consistentWith(Document... docs)
docs
- one or mode Document
to get mutation state information from.public SearchQuery consistentWith(DocumentFragment... fragments)
fragments
- one or mode DocumentFragment
to get mutation state information from.public SearchQuery consistentWith(MutationState mutationState)
MutationState
directly to parameterize the consistency.
This replaces any consistency tuning previously set.mutationState
- the MutationState
information to work with.public Integer getLimit()
limit(int)
parameter, or null if it was not set.public Integer getSkip()
skip(int)
parameter, or null if it was not set.public HighlightStyle getHighlightStyle()
highlight style
parameter,
or null if it was not set.public String[] getHighlightFields()
highlight fields
parameter,
or an empty array if it was not set.public String[] getFields()
fields(String...)
parameter, or an empty array if it was not set.public Map<String,SearchFacet> getFacets()
facets (by name)
, or an empty Map if it was not set.public Long getServerSideTimeout()
serverSideTimeout(long, TimeUnit)
parameter, or null if it was not set.public static QueryStringQuery queryString(String query)
QueryStringQuery
body.public static MatchQuery match(String match)
MatchQuery
body.public static MatchPhraseQuery matchPhrase(String matchPhrase)
MatchPhraseQuery
body.public static PrefixQuery prefix(String prefix)
PrefixQuery
body.public static RegexpQuery regexp(String regexp)
RegexpQuery
body.public static TermRangeQuery termRange()
TermRangeQuery
body.public static NumericRangeQuery numericRange()
NumericRangeQuery
body.public static DateRangeQuery dateRange()
DateRangeQuery
body.public static DisjunctionQuery disjuncts(AbstractFtsQuery... queries)
DisjunctionQuery
body.public static ConjunctionQuery conjuncts(AbstractFtsQuery... queries)
ConjunctionQuery
body.public static BooleanQuery booleans()
BooleanQuery
body.public static WildcardQuery wildcard(String wildcard)
WildcardQuery
body.public static DocIdQuery docId(String... docIds)
DocIdQuery
body.public static BooleanFieldQuery booleanField(boolean value)
BooleanFieldQuery
body.public static PhraseQuery phrase(String... terms)
PhraseQuery
body.public static MatchAllQuery matchAll()
MatchAllQuery
body.public static MatchNoneQuery matchNone()
MatchNoneQuery
body.public static GeoBoundingBoxQuery geoBoundingBox(double topLeftLon, double topLeftLat, double bottomRightLon, double bottomRightLat)
GeoBoundingBoxQuery
body.public static GeoDistanceQuery geoDistance(double locationLon, double locationLat, String distance)
GeoDistanceQuery
body.Copyright © 2015 Couchbase, Inc.