mjordan / islandora_repository_reports

A Drupal 8 module that provides a collection of graphical reports on various aspects of an Islandora repository.
GNU General Public License v2.0
2 stars 5 forks source link

Add a report of keywords searched for #64

Open mjordan opened 3 years ago

mjordan commented 3 years ago

The following simple module captures the current search via the current request URL and the number of results:

<?php

/**
 * @file
 * Testing search API stuff.
 */

use Drupal\search_api\Query\ResultSetInterface;

/**
 * Implements hook_search_api_results_alter().
 */
function mjtest_search_api_results_alter(ResultSetInterface &$results) {
  $current_uri = \Drupal::request()->getRequestUri();
  devel_debug($current_uri);

  devel_debug($results->getResultCount());
}
mjordan commented 3 years ago

Using parse_str(), we can get arrays like this from the search query string:

Array
(
    [/solr-search/content?search_api_fulltext] => thesis
    [f] => Array
        (
            [0] => sfu_department_program:Applied Science: School of Engineering Science
        )

)
Array
(
    [/solr-search/content?search_api_fulltext] => analysis defect seeing
)
Array
(
    [/solr-search/content?search_api_fulltext] => thesis
    [page] => 2
)

So reports on the search terms, facets used, and pagination could be created. Another useful report is searches that resulted in 0 hits.