@InterfaceStability.Experimental @InterfaceAudience.Public public class SearchQuery extends Object
The FTS API entry point. Describes an FTS query entirely (index, query body and parameters) and can be used at the 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.
|
Map<String,SearchFacet> |
getFacets() |
String[] |
getFields() |
String[] |
getHighlightFields() |
HighlightStyle |
getHighlightStyle() |
Integer |
getLimit() |
Long |
getServerSideTimeout() |
Integer |
getSkip() |
SearchQuery |
highlight(HighlightStyle style,
String... fields)
Configures the highlighting of matches in the response.
|
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 RegexpQuery |
regexp(String regexp)
Prepare a
RegexpQuery body. |
SearchQuery |
scanConsistency(ScanConsistency 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.
|
static StringQuery |
string(String query)
Prepare a
StringQuery body. |
static TermQuery |
term(String term)
Prepare a
TermQuery body. |
static WildcardQuery |
wildcard(String wildcard)
Prepare a
WildcardQuery body. |
public SearchQuery(String indexName, AbstractFtsQuery queryPart)
Prepare an FTS 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()
Exports the whole query as a JsonObject.
public void injectParams(JsonObject queryJson)
Inject the top level parameters of a query into a prepared JsonObject that represents the root of the query.
queryJson - the prepared JsonObject for the whole query.public SearchQuery limit(int limit)
Add a limit to the query on the number of hits it can return.
limit - the maximum number of hits to return.public SearchQuery skip(int skip)
Set the number of hits to skip (eg. for pagination).
skip - the number of results to skip.public SearchQuery explain()
Activates the explanation of each result hit in the response.
public SearchQuery explain(boolean explain)
Activates or deactivates the explanation of each result hit in the response, according to the parameter.
explain - should the response include an explanation of each hit (true) or not (false)?public SearchQuery highlight(HighlightStyle style, String... fields)
Configures the highlighting of matches in the response.
This drives the inclusion of the 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 clearHighlight()
Clears any previously configured highlighting.
highlight(HighlightStyle, String...)public SearchQuery fields(String... fields)
Configures the list of fields for which the whole value should be included in the response. If empty, no field values are included.
This drives the inclusion of the fields in each hit.
Note that to be highlighted, the fields must be stored in the FTS index.
fields - public SearchQuery addFacet(String facetName, SearchFacet facet)
Adds one 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()
Clears all previously added SearchFacet.
addFacet(String, SearchFacet)public SearchQuery serverSideTimeout(long timeout, TimeUnit unit)
Sets the server side timeout. By default, the SDK will set this value to the configured searchTimeout from the environment.
timeout - the server side timeout to apply.unit - the unit for the timeout.public SearchQuery scanConsistency(ScanConsistency consistency)
Sets the unparameterized consistency to consider for this FTS query. This replaces any consistency tuning previously set.
consistency - the simple consistency to use.public 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. This replaces any consistency tuning previously set.
docs - one or mode Document to get mutation state information from.public 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. This replaces any consistency tuning previously set.
fragments - one or mode DocumentFragment to get mutation state information from.public 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. 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 StringQuery string(String query)
Prepare a StringQuery body.
public static MatchQuery match(String match)
Prepare a MatchQuery body.
public static MatchPhraseQuery matchPhrase(String matchPhrase)
Prepare a MatchPhraseQuery body.
public static PrefixQuery prefix(String prefix)
Prepare a PrefixQuery body.
public static RegexpQuery regexp(String regexp)
Prepare a RegexpQuery body.
public static NumericRangeQuery numericRange()
Prepare a NumericRangeQuery body.
public static DateRangeQuery dateRange()
Prepare a DateRangeQuery body.
public static DisjunctionQuery disjuncts(AbstractFtsQuery... queries)
Prepare a DisjunctionQuery body.
public static ConjunctionQuery conjuncts(AbstractFtsQuery... queries)
Prepare a ConjunctionQuery body.
public static BooleanQuery booleans()
Prepare a BooleanQuery body.
public static WildcardQuery wildcard(String wildcard)
Prepare a WildcardQuery body.
public static DocIdQuery docId(String... docIds)
Prepare a DocIdQuery body.
public static BooleanFieldQuery booleanField(boolean value)
Prepare a BooleanFieldQuery body.
public static PhraseQuery phrase(String... terms)
Prepare a PhraseQuery body.
public static MatchAllQuery matchAll()
Prepare a MatchAllQuery body.
public static MatchNoneQuery matchNone()
Prepare a MatchNoneQuery body.
Copyright © 2015 Couchbase, Inc.