On 11/4/2016 10:22 AM, Furkan KAMACI wrote:
> I send a query to Solr to get information about each day of current week
> via this way:
>
> &q=*:*
> &fq=type:dps
> &rows=0
> &facet=true
> &facet.date=date
> &facet.date.start=NOW/DAY-6DAYS
> &facet.date.end=NOW/DAY%2B1DAY
> &facet.date.gap=%2B1DAY
>
> I want to make that query over Solrj.

This code would do it:

  /*
   * The client creation would probably be elsewhere, just putting it here
   * for a complete example.
   */
  SolrClient client = new HttpSolrClient("http://server:8983/solr";);
  SolrQuery query = new SolrQuery();
  query.setQuery("*:*");
  query.addFilterQuery("type:dps");
  query.setRows(0);
  query.add("facet", "true");
  query.add("facet.date", "date");
  query.add("facet.date.start", "NOW/DAY-6DAYS");
  query.add("facet.date.end", "NOW/DAY+1DAY");
  query.add("facet.date.gap", "+1DAY");
  String collection = "gettingstarted";
  client.query(collection, query);

One possible problem in the attempts you've made:  In the parameters
you've provided, %2B is a URL-encoded plus sign.  It is shown in the
documentation that way because a plus sign in a URL is a URL-encoded
space.  If your SolrJ code tries to use "%2B" like you would need when
doing the query in a browser, then Solr will not receive a plus sign. 
It would receive the literal string "%2B" which it won't understand. 
SolrJ performs URL encoding on all parameters, so you don't want to do
the URL encoding yourself.

Thanks,
Shawn

Reply via email to