Hi lovely Solr masters!

I am using Facet API to get histograms for two keywords.

For each keyword, the histogram calculates the number of documents with the
keyword every hour.


An example of list of documents :

{ q_s : "keyword1", when_dt : "2015-05-27T15:13:00.000Z" }

{ q_s : "keyword2", when_dt : "2015-05-27T16:17:00.000Z" }

{ q_s : "keyword2", when_dt : "2015-05-27T16:18:00.000Z" }

{ q_s : "keyword1", when_dt : "2015-05-27T16:20:00.000Z" }


An example of output historgram using facet:

"keyword1" : {

    "2015-05-27T15:00:00.000Z" : "1",

    "2015-05-27T16:00:00.000Z" : "1"

}

"keyword2" : {

    "2015-05-27T15:00:00.000Z" : "0",

    "2015-05-27T16:00:00.000Z" : "2"

}


My question is what is best practice to run the query once for N keywords
using Facet JSON API ?


The following command using the query using Json request API successfully
responds with the above expected results, but the facet.date part of the
Json request is hard to read for programmers.

curl -d @- http://localhost:8983/solr/queries/select
{
 "params": {
   "wt": "json",
   "indent": true,
   "_": 1436772757584,
   "q": "*:*",
   "rows": 0,
   "fq": [
     "{!tag=fq0}q_s:keyword1",
     "{!tag=fq1}q_s:keyword2",
     "when_dt:[2015-05-27T15:00:00.000Z TO 2015-05-28T10:19:04.000Z]"
   ],
   "facet": true,
   "facet.date": [
     "{!ex=fq1 key=keyword1 facet.date.start=2015-05-27T15:00:00.000Z
facet.date.end=2015-05-28T10:19:04.000Z facet.date.gap=+1HOURS
facet.date.sort=when_dt}when_dt",
     "{!ex=fq0 key=keyword2 facet.date.start=2015-05-27T15:00:00.000Z
facet.date.end=2015-05-28T10:19:04.000Z facet.date.gap=+1HOURS
facet.date.sort=when_dt}when_dt"
   ]
 }
}

 To make the complicated part simpler, I decided to use Facet API as shown
below, but it does not return any facet results.

            curl -d @- http://localhost:8983/solr/queries/select

{
 "params": {
   "wt": "json",
   "indent": true,
   "_": 1436772757584,
   "q": "*:*",
   "rows": 0,
   "fq": [
     "{!tag=fq0}q_s:keyword1",
     "{!tag=fq1}q_s:keyword2",
     "when_dt:[2015-05-27T15:00:00.000Z TO 2015-05-28T10:19:04.000Z]"
   ]
 },
 "facet": {
   "keyword1": {
     "range": {
       "excludeTags": ["fq1"],
       "field": "when_dt",
       "start": "2015-05-27T15:00:00.000Z",
       "end": "2015-05-28T10:19:04.000Z",
       "gap": "+1HOURS",
       "sort": "when_dt"
     }
   },
   "keyword2": {
     "range": {
       "excludeTags": ["fq0"],
       "field": "when_dt",
       "start": "2015-05-27T15:00:00.000Z",
       "end": "2015-05-28T10:19:04.000Z",
       "gap": "+1HOURS",
       "sort": "when_dt"
     }
   }
 }
}

 Response :

> {
>  "responseHeader":{
>    "status":0,
>    "QTime":2,
>    "params":{
>      "json":"{  \"params\": {    \"wt\": \"json\",    \"indent\": true,
> \"_\": 1436772757584,    \"q\": \"*:*\",    \"rows\": 0,    \"fq\": [
> \"{!tag=fq0}q_s:keyworkd1\",       \"{!tag=fq1}q_s:keyword2\",
> \"when_dt:[2015-05-27T15:00:00.000Z TO 2015-05-28T10:19:04.000Z]\"     ]
> },  \"facet\": {    \"keyword1\": {       \"range\": {
> \"excludeTags\": [\"fq1\"],        \"field\": \"when_dt\",
> \"start\": \"2015-05-27T15:00:00.000Z\",         \"end\":
> \"2015-05-28T10:19:04.000Z\",         \"gap\": \"+1HOURS\",
> \"sort\": \"when_dt\"      }     },    \"keyword2\": {       \"range\": {
>       \"excludeTags\": [\"fq0\"],        \"field\": \"when_dt\",
> \"start\": \"2015-05-27T15:00:00.000Z\",         \"end\":
> \"2015-05-28T10:19:04.000Z\",         \"gap\": \"+1HOURS\",
> \"sort\": \"when_dt\"      }     }  }}"}},
>  "response":{"numFound":0,"start":0,"docs":[]
>  },
>  "facets":{
>    "count":0}}


Any idea about this?

Thanks in advance. Solr rocks!

- Kangmo

Reply via email to