Ticket #13704 (new Bug)

Opened 3 years ago

custom event when search result is available

Reported by: schrei5 Owned by:
Priority: minor Milestone: 4.x
Component: Unknown Version: 4.3
Keywords: Cc:

Description

I use piwik which allows you to monitor what users search for on your site. I found a way to report the search queries to piwik

  var last_query = '';
  
  $(document).ready(function(){
    $.fn.orig_pullSearchResults = $.fn.pullSearchResults;
    $.fn.pullSearchResults = function(query){
      var res = this.orig_pullSearchResults(query);
      var cur_query = RegExp('SearchableText=(.+?)(&|$)').exec(query)[1];
      if(cur_query !== last_query){
        last_query = cur_query;
        _paq.push(['trackSiteSearch',
          RegExp('SearchableText=(.+?)(&|$)').exec(query)[1]
        ]);
      }
      return res;
    };
  });

but I'd also like to report the number of results to piwik. The problem is the results are not available when my code runs. I think the only way to make this possible is if plone.app.search/search.js would fire a custom event when the results have been updated.

$("form.searchPage").trigger('resultsUpdated')

This would be a single line of code in search.js with AFAIK no side effects and would help my (and maybe others) a lot.

Note: See TracTickets for help on using tickets.