If you open the searchpage (/search/node) an entry is added to the database in zeitgeist, with an empty search entry...

the quickest fix I can think of is modifying the store search function as follows:

function _zeitgeist_store_search($search, $category, $ts = NULL)
  {
  if (!isset($ts)) {
    $ts = time();
  }
  if (isset($search)) {
    $sq = 'INSERT INTO ' . ZGTABLE . ' (search, category, ts) '
        . "VALUES ('%s', '%s', %d) ";
    db_query($sq, $search, $category, $ts);
    }
  }

Comments

jadwigo’s picture

This would actually be better, it saves one function call

function zeitgeist_form_alter($form_id, &$form)
  {
  if ($form_id != 'search_form')
    return;

  $search   = $form['basic']['inline']['keys']['#default_value'];
  $category = $form['module']['#value'];
  if (!empty($search)) {
    _zeitgeist_store_search($search, $category);
    }
  }
fgm’s picture

Your second patch suggestion indeed removes such logging rather efficiently.

However, the problem is that it is important that ZG actually store empty searches, and I'm not sure how the module can know whether someone sent an empty search request, or just went to the search page without the intent to submit a search: both use the same mechanism currently, AFAIK.

Do you think you can imagine a way to get the difference between these two cases ? This is related to my battle plan for the next major Drupal version, and specifically the details outlined about logging for drupal (temporary URL, sorry).

jadwigo’s picture

In search module the following function is called and triggers an error when an empty search is submitted, I guess you could intercept the $form_values['processed_keys']; too in zeitgeist.

/**
 * Process a search form submission.
 */
function search_form_submit($form_id, $form_values) {
  $keys = $form_values['processed_keys'];
  if ($keys == '') {
    form_set_error('keys', t('Please enter some keywords.'));
    // Fall through to the drupal_goto() call.
  }

  $type = $form_values['module'] ? $form_values['module'] : 'node';
  return 'search/'. $type .'/'. $keys;
}
fgm’s picture

Title: zeitgeist also registers empty searches » zeitgeist also registers empty and invalid searches
Assigned: Unassigned » fgm
Priority: Normal » Minor
Status: Active » Needs review

This issue was actually covering two distinct cases:

  • valid empty searches : a user submitting an empty search
  • invalid empty searches : a user or bot following a /search link

Version 1.9.2.1 now in CVS adds a setting to allows ZG to keep valid empty searches or not, and should no longer store invalid empty searches.

jadwigo’s picture

Status: Needs review » Reviewed & tested by the community

Everything seems to work as advertised, code looks pretty .... it's all good.

fgm’s picture

Status: Reviewed & tested by the community » Fixed

OK, then...

Anonymous’s picture

Status: Fixed » Closed (fixed)