public class JsonQueryRequest extends QueryRequest
DirectJsonQueryRequest
SolrRequest.METHOD
SUPPORTED_METHODS, useBinaryV2, usev2
Constructor and Description |
---|
JsonQueryRequest()
Creates a
JsonQueryRequest with an empty SolrParams object |
JsonQueryRequest(SolrParams params)
Creates a
JsonQueryRequest using the provided SolrParams |
Modifier and Type | Method and Description |
---|---|
RequestWriter.ContentWriter |
getContentWriter(String expectedType)
If a request object wants to do a push write, implement this method.
|
JsonQueryRequest |
returnFields(Iterable<String> fieldNames)
Specify fields which should be returned by the JSON request.
|
JsonQueryRequest |
returnFields(String... fieldNames)
Specify fields which should be returned by the JSON request.
|
JsonQueryRequest |
setLimit(int limit)
Specify how many results should be returned from the JSON request
|
void |
setMethod(SolrRequest.METHOD m) |
JsonQueryRequest |
setOffset(int offset)
Specify whether results should be fetched starting from a particular offset (or 'start').
|
JsonQueryRequest |
setQuery(Map<String,Object> queryJson)
Specify the query sent as a part of this JSON request.
|
JsonQueryRequest |
setQuery(MapWriter queryWriter)
Specify the query sent as a part of this JSON request.
|
JsonQueryRequest |
setQuery(String query)
Specify the query sent as a part of this JSON request
This method may be called multiple times, but each call overwrites the value specified by previous calls.
|
JsonQueryRequest |
setSort(String sort)
Specify how results to the JSON request should be sorted before being returned by Solr
|
JsonQueryRequest |
withFacet(String facetName,
Map<String,Object> facetJson)
Specify a facet sent as a part of this JSON request.
|
JsonQueryRequest |
withFacet(String facetName,
MapWriter facetWriter)
Specify a facet sent as a part of this JSON request.
|
JsonQueryRequest |
withFilter(Map<String,Object> filterQuery)
Add a filter query to run as a part of the JSON request
This method may be called multiple times; each call will add a new filter to the request
|
JsonQueryRequest |
withFilter(String filterQuery)
Add a filter query to run as a part of the JSON request
This method may be called multiple times; each call will add a new filter to the request
|
JsonQueryRequest |
withParam(String name,
Object value)
Add a property to the "params" block supported by the JSON query DSL
The JSON query DSL has special support for a few query parameters (limit/rows, offset/start, filter/fq, etc.).
|
JsonQueryRequest |
withStatFacet(String facetName,
String facetValue)
Specify a simple stat or aggregation facet to be sent as a part of this JSON request.
|
createResponse, getParams, getPath
addHeader, getBasePath, getBasicAuthPassword, getBasicAuthUser, getCollection, getContentStreams, getHeaders, getMethod, getQueryParams, getResponseParser, getStreamingResponseCallback, getUserPrincipal, process, process, setBasePath, setBasicAuthCredentials, setPath, setQueryParams, setResponseParser, setStreamingResponseCallback, setUseBinaryV2, setUserPrincipal, setUseV2
public JsonQueryRequest()
JsonQueryRequest
with an empty SolrParams
objectpublic JsonQueryRequest(SolrParams params)
JsonQueryRequest
using the provided SolrParams
public JsonQueryRequest setQuery(String query)
query
- a String in either of two formats: a query string for the default deftype (e.g. "title:solr"), or a
localparams query (e.g. "{!lucene df=text v='solr'}" )IllegalArgumentException
- if query
is nullpublic JsonQueryRequest setQuery(Map<String,Object> queryJson)
Example: You wish to send the JSON request: "{'limit': 5, 'query': {'lucene': {'df':'genre_s', 'query': 'scifi'}}}". The query subtree of this request is: "{'lucene': {'df': 'genre_s', 'query': 'scifi'}}". You would represent this query JSON as follows:
final Map<String, Object> queryMap = new HashMap<>();
final Map<String, Object> luceneQueryParamMap = new HashMap<>();
queryMap.put("lucene", luceneQueryParamMap);
luceneQueryParamMap.put("df", "genre_s");
luceneQueryParamMap.put("query", "scifi");
queryJson
- a Map of values representing the query subtree of the JSON request you wish to send.IllegalArgumentException
- if queryJson
is null.public JsonQueryRequest setQuery(MapWriter queryWriter)
Example: You wish to send the JSON request: "{'limit': 5, 'query': {'lucene': {'df':'genre_s', 'query': 'scifi'}}}". The query subtree of this request is: "{'lucene': {'df': 'genre_s', 'query': 'scifi'}}". You would represent this query JSON as follows:
final MapWriter queryWriter = new MapWriter() { @Override public void writeMap(EntryWriter ew) throws IOException { ew.put("lucene", (MapWriter) queryParamWriter -> { queryParamWriter.put("df", "genre_s"); queryParamWriter.put("query", "scifi"); }); } };
queryWriter
- a MapWriter capable of writing out the query subtree of the JSON request you wish to send.IllegalArgumentException
- if queryWriter
is null.public JsonQueryRequest withFacet(String facetName, Map<String,Object> facetJson)
facetName
value will add a new
top-level facet. Repeating facetName
values will cause previous facets with that facetName
to be
overwritten.
Example: You wish to send the JSON request: {"query": "*:*", "facet": { "top_cats":{"type": "terms", "field":"cat"}}}. You would represent (and attach) the facet in this request as follows:
final Map<String, Object> catFacetMap = new HashMap<>();
catFacetMap.put("type", "terms");
catFacetMap.put("field", "cat");
jsonQueryRequest.withStatFacet("top_cats", catFacetMap);
facetName
- the name of the top-level facet you'd like to add. Avoid choosing facet names which overload
properties already present in the JSON response schema (e.g. "count", "val", "minX", etc.)facetJson
- a Map of values representing the facet you wish to add to the requestpublic JsonQueryRequest withFacet(String facetName, MapWriter facetWriter)
facetName
value will add a new
top-level facet. Repeating facetName
values will cause previous facets with that facetName
to be
overwritten.
Example: You wish to send the JSON request: {"query": "*:*", "facet": { "top_cats":{"type": "terms", "field":"cat"}}}. You would represent the facet in this request as follows:
final MapWriter facetWriter = new MapWriter() { @Override public void writeMap(EntryWriter ew) throws IOException { ew.put("type", "terms"); ew.put("field", "cat"); } };
facetName
- the name of the top-level facet you'd like to add. Avoid choosing facet names which overload
properties already present in the JSON response schema (e.g. "count", "val", "minX", etc.)facetWriter
- a MapWriter representing the facet you wish to add to the requestpublic JsonQueryRequest withStatFacet(String facetName, String facetValue)
facetName
value will add a new
top-level facet. Repeating facetName
values will cause previous facets with that facetName
to be
overwritten.
Example: You wish to send the JSON request: {"query": "*:*", "facet": {"avg_price": "avg(price)"}}. You would represent the facet in this request as follows:
jsonQueryRequest.withStatFacet("avg_price", "avg(price)");
facetName
- the name of the top-level stat/agg facet you'd like to add. Avoid choosing facet names which overload
properties already present in the JSON response schema (e.g. "count", "val", "minX", etc.)facetValue
- a String representing the stat/agg facet computation to perform.public JsonQueryRequest setOffset(int offset)
offset
- a non-negative integer representing the offset (or 'start') to use when returning resultsIllegalArgumentException
- if offset
is negativepublic JsonQueryRequest setLimit(int limit)
limit
- a non-negative integer representing the maximum results to return from a searchIllegalArgumentException
- if limit
is negativepublic JsonQueryRequest setSort(String sort)
sort
- a string representing the desired result sort order (e.g. "price asc")IllegalArgumentException
- if sort
is nullpublic JsonQueryRequest withFilter(String filterQuery)
filterQuery
- a String in either of two formats: a query string for the default deftype (e.g. "title:solr"), or a
localparams query (e.g. "{!lucene df=text v='solr'}" )IllegalArgumentException
- if filterQuery
is nullpublic JsonQueryRequest withFilter(Map<String,Object> filterQuery)
Example: You wish to send the JSON request: "{'query':'*:*', 'filter': [{'lucene': {'df':'genre_s', 'query': 'scifi'}}]}". The filter you want to add is: "{'lucene': {'df': 'genre_s', 'query': 'scifi'}}". You would represent this filter query as follows:
final Map<String, Object> filterMap = new HashMap<>();
final Map<String, Object> luceneQueryParamMap = new HashMap<>();
filterMap.put("lucene", luceneQueryParamMap);
luceneQueryParamMap.put("df", "genre_s");
luceneQueryParamMap.put("query", "scifi");
filterQuery
- a Map of values representing the filter request you wish to send.IllegalArgumentException
- if filterQuery
is nullpublic JsonQueryRequest returnFields(String... fieldNames)
fieldNames
- the field names that should be returned by the requestpublic JsonQueryRequest returnFields(Iterable<String> fieldNames)
fieldNames
- the field names that should be returned by the requestIllegalArgumentException
- if fieldNames
is nullpublic JsonQueryRequest withParam(String name, Object value)
This method may be called multiple times; each call with a different name
will add a new param name/value
to the params subtree. Invocations that repeat a name
will overwrite the previously specified parameter
values associated with that name.
name
- the name of the parameter to addvalue
- the value of the parameter to add. Usually a String, Number (Integer, Long, Double), or Boolean.IllegalArgumentException
- if either name
or value
are nullpublic RequestWriter.ContentWriter getContentWriter(String expectedType)
SolrRequest
getContentWriter
in class SolrRequest<QueryResponse>
expectedType
- This is the type that the RequestWriter would like to get. But, it is OK to send any formatpublic void setMethod(SolrRequest.METHOD m)
setMethod
in class SolrRequest<QueryResponse>
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.