motagirl2
motagirl2

Reputation: 608

Get results from Solr facets

I am pretty new to Solr, so I don't know if what I'd like to achieve is actually feasible or not. Currently, I am querying my Solr to retrieve the amount of results that match the conditions in several facet queries. For example:

localhost:8082/solr/dict/select?q=*:*&rows=0&wt=json&indent=true&facet=true&facet.query=dict1:"#tiger#"&facet.query=dict1:"#lion#"

With this kind of query, I am getting the count of Solr docs containing "tiger" and the count of those cointaining "lion", in field "dict1":

 {
  "responseHeader": {
    "status": 0,
    "QTime": 239,
    "params": {
      "facet.query": [
        "dict1:\"#tiger#\"",
        "dict1:\"#lion#\""
      ],
      "q": "*:*",
      "indent": "true",
      "rows": "0",
      "wt": "json",
      "facet": "true"
    }
  },
  "response": {
    "numFound": 37278987,
    "start": 0,
    "docs": [ ]
  },
  "facet_counts": {
    "facet_queries": {
      "dict1:\"#tiger#\"": 6,
      "dict1:\"#lion#\"": 10
    },
    [...]
  }
}

The thing is that now I need to get also some results for each facet, aside as the count (for example, three results for "tiger" and three more for "lion")

I have read some similar questions (Solr Facetting - Showing First 10 results and Other or SOLR - Querying Facets, return N results per Facet ) , but none of their answers seems to work for me, maybe because I am doing the facets on all docs (q=*:*).

Any help will be welcome :)

Upvotes: 2

Views: 852

Answers (1)

Alessandro Benedetti
Alessandro Benedetti

Reputation: 1114

As per mailing list, what about simply using grouping ?

solr/hotels/search?q=*%3A*&wt=json&indent=true&group=true&group.query=query1&group.query=query2&group.limit=3 [1]

Is this ok for you? This returns 2 groups (1 per query) with the related count and max number of documents.

[1] https://cwiki.apache.org/confluence/display/solr/Result+Grouping

Upvotes: 1

Related Questions