Search filtering and sorting

In the previous section, we saw how we can use the facet feature to group data together and seethe number of results in each genre. We can use the fq parameter to further limit the search. Let's now see how we can use the fq parameter to return only those songs whose genre is Pop:

http://localhost:8983/solr/musicStore/select?q=*%3A*&wt=json&indent=true&fq=genre:Pop&fl=id,songName,genre

This URL will result in the following output:

{
   "responseHeader":{
      "status":0,
      "QTime":2
   },
   "response":{
      "numFound":3,
      "start":0,
      "docs":[
         {
            "id":"1001",
            "songName":"Don't Stop the Party",
            "genre":"Pop"
         },
         {
            "id":"1002",
            "songName":"All I Want For Christmas Is You",
            "genre":"Pop"
         },
         {
            "id":"1003",
            "songName":"A Thousand Years",
            "genre":"Pop"
         }
      ]
   }
}

As we can see from the preceding output, the results are limited to those songs whose genre is Pop. This example shows us how we can apply filters to results.

We can also sort the data using the sort parameter, which we can specify. Let's see how we can sort the songName in ascending order:

http://localhost:8983/solr/musicStore/select?q=*%3A*&wt=json&indent=true&fq=genre:Pop&fl=id,songName,genre&sort=songName%20asc

The preceding URL gives the following result:

{
   "responseHeader":{
      "status":0,
      "QTime":0
   },
   "response":{
      "numFound":3,
      "start":0,
      "docs":[
         {
            "id":"1003",
            "songName":"A Thousand Years",
            "genre":"Pop"
         },
         {
            "id":"1002",
            "songName":"All I Want For Christmas Is You",
            "genre":"Pop"
         },
         {
            "id":"1001",
            "songName":"Don't Stop the Party",
            "genre":"Pop"
         }
      ]
   }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.25.193