You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Furkan KAMACI <fu...@gmail.com> on 2016/11/04 16:22:00 UTC
Solrj facet.date
Hi,
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 facet.date definition at source code (5.5.3):
public static final String FACET_DATE = FACET + ".date";
However it is not used at Solrj. How can I make such a query with Solrj? If
I'm not missing anything I can create a patch for such functionality at
Solrj.
Kind Regards,
Furkan KAMACI
Re: Solrj facet.date
Posted by Furkan KAMACI <fu...@gmail.com>.
Hi Shawn,
You are right, ClientUtils.escapeQueryChars() breaks the functionality. My
expectation was that: Solrj has
addDateRangeFacet
However there is not a direct method for facet.date query.
Kind Regards,
Furkan KAMACI
On Fri, Nov 4, 2016 at 7:04 PM, Shawn Heisey <ap...@elyograg.org> wrote:
> 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
>
>
Re: Solrj facet.date
Posted by Shawn Heisey <ap...@elyograg.org>.
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