How to use facets with PySolr - can't seem to get facet results to show

3k views Asked by At

(I have seen similar questions to this - but cannot seem to resolve why the below doesnt work!)

Hi, I have a running local instance of solr and make the following call (via the url box in my browser):

http://localhost:8983/solr/select?q=video&rows=0&facet=true&facet.field=q_date

And get the results below (see results 1). Then I try the equivalent with Python/PySolr:

solr = pysolr.Solr('http://localhost:8983/solr/', timeout=10)

params = {
  'facet': 'true',
  'facet.field': 'q_date',
  'rows': '0',
}

results = solr.search('video', **params)

And seem to get no results (if I make 'rows': 10 then I get 10 results) - but in either case I seem to get no facets.

Any ideas how to get around this? After I figure this out I also wish to use the StatsComponent feature (e.g. &stats=true&stats.field=q_visits)

Thanks in advance

RESULTS 1:

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">2</int>
<lst name="params">
<str name="facet">true</str>
<str name="q">video</str>
<str name="facet.field">q_date</str>
<str name="rows">0</str>
</lst>
</lst>
<result name="response" numFound="670" start="0"/>
<lst name="facet_counts">
<lst name="facet_queries"/>
<lst name="facet_fields">
<lst name="q_date">
<int name="2013-03-31T00:00:00Z">135</int>
<int name="2013-01-31T00:00:00Z">121</int>
<int name="2012-10-31T00:00:00Z">113</int>
<int name="2013-02-28T00:00:00Z">112</int>
<int name="2012-11-30T00:00:00Z">107</int>
<int name="2012-12-31T00:00:00Z">82</int>
</lst>
</lst>
<lst name="facet_dates"/>
<lst name="facet_ranges"/>
</lst>
</response>
1

There are 1 answers

1
Paige Cook On BEST ANSWER

According to the facet examples in the pysolr client tests, you need to set the value for facet parameter to 'on'. Like below:

solr = pysolr.Solr('http://localhost:8983/solr/', timeout=10)`

params = {
  'facet': 'on',
  'facet.field': 'q_date',
  'rows': '0',
}

results = solr.search('video', **params)