Class JsonQueryRequest
- All Implemented Interfaces:
Serializable
This class constructs the request using setters for individual properties. For a more
monolithic approach to constructing the JSON request, see DirectJsonQueryRequest
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.solr.client.solrj.SolrRequest
SolrRequest.ApiVersion, SolrRequest.METHOD, SolrRequest.SolrClientContext, SolrRequest.SolrRequestType -
Field Summary
Fields inherited from class org.apache.solr.client.solrj.SolrRequest
SUPPORTED_METHODS -
Constructor Summary
ConstructorsConstructorDescriptionCreates aJsonQueryRequestwith an emptySolrParamsobjectJsonQueryRequest(SolrParams params) Creates aJsonQueryRequestusing the providedSolrParams -
Method Summary
Modifier and TypeMethodDescriptiongetContentWriter(String expectedType) If a request object wants to do a push write, implement this method.returnFields(Iterable<String> fieldNames) Specify fields which should be returned by the JSON request.returnFields(String... fieldNames) Specify fields which should be returned by the JSON request.setLimit(int limit) Specify how many results should be returned from the JSON requestvoidsetOffset(int offset) Specify whether results should be fetched starting from a particular offset (or 'start').Specify the query sent as a part of this JSON requestSpecify the query sent as a part of this JSON request.Specify the query sent as a part of this JSON request.Specify how results to the JSON request should be sorted before being returned by SolrSpecify a facet sent as a part of this JSON request.Specify a facet sent as a part of this JSON request.withFilter(String filterQuery) Add a filter query to run as a part of the JSON requestwithFilter(Map<String, Object> filterQuery) Add a filter query to run as a part of the JSON requestAdd a property to the "params" block supported by the JSON query DSLwithStatFacet(String facetName, String facetValue) Specify a simple stat or aggregation facet to be sent as a part of this JSON request.Methods inherited from class org.apache.solr.client.solrj.request.QueryRequest
createResponse, getParams, getPathMethods inherited from class org.apache.solr.client.solrj.request.CollectionRequiringSolrRequest
requiresCollectionMethods inherited from class org.apache.solr.client.solrj.SolrRequest
addHeader, addHeaders, getApiVersion, getBasicAuthPassword, getBasicAuthUser, getCollection, getContentStreams, getHeaders, getMethod, getPreferredNodes, getQueryParams, getRequestType, getResponseParser, getStreamingResponseCallback, getUserPrincipal, process, process, processWithBaseUrl, setBasicAuthCredentials, setPath, setPreferredNodes, setQueryParams, setRequestType, setResponseParser, setStreamingResponseCallback, setUserPrincipal
-
Constructor Details
-
JsonQueryRequest
public JsonQueryRequest()Creates aJsonQueryRequestwith an emptySolrParamsobject -
JsonQueryRequest
Creates aJsonQueryRequestusing the providedSolrParams
-
-
Method Details
-
setQuery
Specify the query sent as a part of this JSON requestThis method may be called multiple times, but each call overwrites the value specified by previous calls.
- Parameters:
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'}" )- Throws:
IllegalArgumentException- ifqueryis null
-
setQuery
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.
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");- Parameters:
queryJson- a Map of values representing the query subtree of the JSON request you wish to send.- Throws:
IllegalArgumentException- ifqueryJsonis null.
-
setQuery
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.
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"); }); } };- Parameters:
queryWriter- a MapWriter capable of writing out the query subtree of the JSON request you wish to send.- Throws:
IllegalArgumentException- ifqueryWriteris null.
-
withFacet
Specify a facet sent as a part of this JSON request.This method may be called multiple times. Each call made with a different
facetNamevalue will add a new top-level facet. RepeatingfacetNamevalues will cause previous facets with thatfacetNameto 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);- Parameters:
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 request
-
withFacet
Specify a facet sent as a part of this JSON request.This method may be called multiple times. Each call made with a different
facetNamevalue will add a new top-level facet. RepeatingfacetNamevalues will cause previous facets with thatfacetNameto 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"); } };- Parameters:
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 request
-
withStatFacet
Specify a simple stat or aggregation facet to be sent as a part of this JSON request.This method may be called multiple times. Each call made with a different
facetNamevalue will add a new top-level facet. RepeatingfacetNamevalues will cause previous facets with thatfacetNameto 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)");- Parameters:
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.
-
setOffset
Specify whether results should be fetched starting from a particular offset (or 'start').Defaults to 0 if not set.
- Parameters:
offset- a non-negative integer representing the offset (or 'start') to use when returning results- Throws:
IllegalArgumentException- ifoffsetis negative
-
setLimit
Specify how many results should be returned from the JSON request- Parameters:
limit- a non-negative integer representing the maximum results to return from a search- Throws:
IllegalArgumentException- iflimitis negative
-
setSort
Specify how results to the JSON request should be sorted before being returned by Solr- Parameters:
sort- a string representing the desired result sort order (e.g. "price asc")- Throws:
IllegalArgumentException- ifsortis null
-
withFilter
Add a filter query to run as a part of the JSON requestThis method may be called multiple times; each call will add a new filter to the request
- Parameters:
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'}" )- Throws:
IllegalArgumentException- iffilterQueryis null
-
withFilter
Add a filter query to run as a part of the JSON requestThis method may be called multiple times; each call will add a new filter to the request
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");- Parameters:
filterQuery- a Map of values representing the filter request you wish to send.- Throws:
IllegalArgumentException- iffilterQueryis null
-
returnFields
Specify fields which should be returned by the JSON request.This method may be called multiple times; each call will add a new field to the list of those to be returned.
- Parameters:
fieldNames- the field names that should be returned by the request
-
returnFields
Specify fields which should be returned by the JSON request.This method may be called multiple times; each call will add a new field to the list of those to be returned.
- Parameters:
fieldNames- the field names that should be returned by the request- Throws:
IllegalArgumentException- iffieldNamesis null
-
withParam
Add a property to the "params" block supported by the JSON query DSLThe JSON query DSL has special support for a few query parameters (limit/rows, offset/start, filter/fq, etc.). But many other query parameters are not explicitly covered by the query DSL. This method can be used to add any of these other parameters to the JSON request.
This method may be called multiple times; each call with a different
namewill add a new param name/value to the params subtree. Invocations that repeat anamewill overwrite the previously specified parameter values associated with that name.- Parameters:
name- the name of the parameter to addvalue- the value of the parameter to add. Usually a String, Number (Integer, Long, Double), or Boolean.- Throws:
IllegalArgumentException- if eithernameorvalueare null
-
getContentWriter
Description copied from class:SolrRequestIf a request object wants to do a push write, implement this method.- Overrides:
getContentWriterin classSolrRequest<QueryResponse>- Parameters:
expectedType- This is the type that the RequestWriter would like to get. But, it is OK to send any format
-
setMethod
- Overrides:
setMethodin classSolrRequest<QueryResponse>
-