Skip to main content
Apache Solr

Apache Solr View Count module

While working with Apache solr in drupal, I had to sort the results based on relevancy, date, and popularity. The Apache solr sort module allowed me to sort based on relevancy and date, but sorting based on popularity wasn't available. What I mean by sorting based on popularity is that sorting based on the view count of each result.

Since sorting based on popularity wasn't available, I just started to build a module for it. The first thing that was needed to be done was to index the node count as a custom field, so that we can sort the results based on the node count value. For getting the node view count, I used the Statistics module that was available in the drupal core. 

I thought this would be something useful for others as well, so created it as a separate module. It is now available at The module requires Apache solr search module and also depends on either of the following modules to fetch the node view count:

The user needs to select one of the above choices to make the module start working. So one would be redirected to the Apachesolr Viewcount module configuration page after installing or enabling the module. There is another feature provided by the module: the node view count field can be used for sorting solr results. For this purpose, you need to install Apachesolr Sort module. 

Module configuration

For the first time, you need to initiate the module to record the node view count:

drush initiate-solr-count

 To update the solr index with view count values, use the following command in crontab and setup the timing accordingly.

drush update-solr-count