2
votes
Get results from Solr facets - Stack Overflow
Asked
Viewed 643 times
2

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 :)

2
  • I'm not sure how your case differs from the grouping strategy described in the last link you included?
    – MatsLindh
    Aug 26 2016 at 13:19
  • Because my search is *:*, I mean, I am performing the facet to match "tiger" or "lion" over all the entries, and the strategy stated in the last link is asuming that the query is "doing something". For example, if I query with "dict1:tiger", and then add the group filtering as in the second link, it kind of works, but it's not the desired approach...
    – motagirl2
    Aug 26 2016 at 14:06
1

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

1
  • Thank you! I manage to get the results as I wanted: /select?q=*:*&wt=json&indent=true&facet=true&group=true&group.query=dict1:tiger&group.query=dict1:lion&group.limit=2 The only thing is that this query is super slow :/ (From 0,2secs to 2secs)
    – motagirl2
    Aug 26 2016 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.

 
1
I'm not sure how your case differs from the grouping strategy described in the last link you included?MatsLindh
Because my search is *:*, I mean, I am performing the facet to match "tiger" or "lion" over all the entries, and the strategy stated in the last link is asuming that the query is "doing something". For example, if I query with "dict1:tiger", and then add the group filtering as in the second link, it kind of works, but it's not the desired approach...motagirl2

1 Answers

1
votes

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