Class JsonQueryRequest

    • Method Detail

      • setQuery

        public 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.
        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 - if query is null
      • setQuery

        public JsonQueryRequest setQuery​(Map<String,​Object> queryJson)
        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 - if queryJson is null.
      • setQuery

        public JsonQueryRequest setQuery​(MapWriter queryWriter)
        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 - if queryWriter is null.
      • withFacet

        public JsonQueryRequest withFacet​(String facetName,
                                          Map<String,​Object> facetJson)
        Specify a facet sent as a part of this JSON request. This method may be called multiple times. Each call made with a different 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);
         
        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

        public JsonQueryRequest withFacet​(String facetName,
                                          MapWriter facetWriter)
        Specify a facet sent as a part of this JSON request. This method may be called multiple times. Each call made with a different 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");
                 }
             };
         
        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

        public JsonQueryRequest withStatFacet​(String facetName,
                                              String facetValue)
        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 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)");
         
        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

        public JsonQueryRequest setOffset​(int offset)
        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 - if offset is negative
      • setLimit

        public JsonQueryRequest setLimit​(int limit)
        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 - if limit is negative
      • setSort

        public JsonQueryRequest setSort​(String sort)
        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 - if sort is null
      • withFilter

        public 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
        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 - if filterQuery is null
      • withFilter

        public 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

        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 - if filterQuery is null
      • returnFields

        public JsonQueryRequest returnFields​(String... fieldNames)
        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

        public JsonQueryRequest returnFields​(Iterable<String> fieldNames)
        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 - if fieldNames is null
      • withParam

        public 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.). 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 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.

        Parameters:
        name - the name of the parameter to add
        value - the value of the parameter to add. Usually a String, Number (Integer, Long, Double), or Boolean.
        Throws:
        IllegalArgumentException - if either name or value are null