You are here

function suggestion_surfer_submit in Autocomplete Search Suggestions 7

Same name and namespace in other branches
  1. 8.2 suggestion.module \suggestion_surfer_submit()
  2. 8 suggestion.module \suggestion_surfer_submit()
  3. 3.0.x suggestion.module \suggestion_surfer_submit()

Custom submit function to add surfer suggestions.

1 string reference to 'suggestion_surfer_submit'
SuggestionHelper::alterElement in src/SuggestionHelper.php
Search the form recursivley for the field and add the autocomplete route.

File

./suggestion.module, line 179
Autocomplete suggestions.

Code

function suggestion_surfer_submit($form, &$state) {
  $field_name = variable_get('suggestion_field_name', '');
  if (empty($state['values'][$field_name])) {
    return;
  }
  $txt = SuggestionHelper::tokenize($state['values'][$field_name], variable_get('suggestion_min', 4));
  if (!$txt) {
    return;
  }
  $atoms = SuggestionHelper::atomize($txt);
  $count = count($atoms);
  if ($count < variable_get('suggestion_atoms_min', 3) || $count > variable_get('suggestion_atoms_max', 6)) {
    return;
  }
  $ngram = implode(' ', $atoms);
  $qty = SuggestionStorage::getNgramQty($ngram);
  if ($qty) {
    $src = SuggestionStorage::getBitmap($ngram, SuggestionStorage::SURFER_BIT);
    $key = array(
      'ngram' => $ngram,
    );
    $fields = array(
      'atoms' => $count,
      'density' => SuggestionHelper::calculateDensity($src, $count, $qty + 1),
      'qty' => $qty + 1,
      'src' => $src,
    );
    SuggestionStorage::mergeSuggestion($key, $fields);
    return;
  }
  $score = SuggestionStorage::getScore($atoms);
  if ($score >= SuggestionHelper::MIN_SCORE) {
    SuggestionHelper::insert($ngram, SuggestionStorage::SURFER_BIT, $score);
  }
}