Make delicious recipes!

Solr Facet Example



Facets in Solr can be used to get count of groups (very similar to group-by clause in SQL).


Regular Solr Query Facet Solr Query
http://localhost:8983/solr/collection1/
select?q=*:*&
wt=json&
fl=id,cat,manu,price&
indent=true&
rows=5


{
  "response":{
    "numFound":1035,"start":0,
    "docs":[
      {
        "id":"GB18030TEST",
        "price":0.0},
      {
        "id":"SP2514N",
        "manu":"Samsung Electronics Co. Ltd.",
        "cat":["electronics", "hard drive"],
        "price":92.0},
      {
        "id":"6H500F0",
        "manu":"Maxtor Corp.",
        "cat":["electronics", "hard drive"],
        "price":350.0},
      {
        "id":"F8V7067-APL-KIT",
        "manu":"Belkin",
        "cat":["electronics", "connector"],
        "price":19.95},
      {
        "id":"IW-02",
        "manu":"Belkin",
        "cat":["electronics", "connector"],
        "price":11.5}]
  }}
http://localhost:8983/solr/collection1/
select?q=*:*&
wt=json&
fl=id,cat,manu,price&
indent=true&
rows=2&
facet=true&
facet.field=price&
facet.sort=index&
facet.limit=10
{
  "response":{
    "numFound":1035,"start":0,
    "docs":[
      {
        "id":"GB18030TEST",
        "price":0.0},
      {
        "id":"SP2514N",
        "manu":"Samsung Electronics Co. Ltd.",
        "cat":["electronics", "hard drive"],
        "price":92.0}]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "price":[
        "0.0",103,
        "1.0",100,
        "2.0",100,
        "3.0",100,
        "4.0",100,
        "5.0",100,
        "6.0",100,
        "7.0",100,
        "8.0",100,
        "9.0",100]},
    "facet_dates":{},
    "facet_ranges":{}}}

The official Solr Facet Parameters page provides a good description of all the options which can be used with facets.





Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal