blog-banner

Apache Solr View Count Module

  • APACHE SOLR
  • Drupal 7
  • Drupal Module
  • Drupal Planet

Apache Solr Statistics

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 is 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 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 drupal.org. The module requires an 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 Apache solr 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 the Apache solr 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 set up the timing accordingly.

drush update-solr-count

 

Get awesome tech content in your inbox