protected function FuzzysearchSearch::split in Fuzzy Search 7
Split token fields into ngrams.
Parameters
array $field: Associative array of field information.
1 call to FuzzysearchSearch::split()
- FuzzysearchSearch::preprocessIndexItems in includes/
processor_search.inc - Calls processField() for all appropriate fields.
File
- includes/
processor_search.inc, line 110
Class
- FuzzysearchSearch
- Processor to set the index and search settings. Requires FuzzySearchService.
Code
protected function split(array &$field) {
if ($field['type'] == 'tokens') {
foreach ($field['value'] as $key => $value) {
$word = '';
$word = $value['value'];
$length = drupal_strlen($word);
if ($length < $this->options['ngram_length']) {
continue;
}
// Cleanse and remove spaces.
$ngrams = array(
'ngrams' => array(),
);
$word = str_replace(' ', '', fuzzysearch_cleanse($word));
$ngrams['completeness'] = $length - $this->options['ngram_length'] + 1 == 0 ? 100 : number_format(100 / ($length - $this->options['ngram_length'] + 1), 3);
$ngrams['comp_min'] = number_format(100 / ($length - $this->options['ngram_length'] + 1 + $this->options['missing_letters']), 3);
if ($length - $this->options['ngram_length'] + 1 - $this->options['extra_letters'] <= 0) {
$ngrams['comp_max'] = number_format(100, 3) + 0.001;
}
else {
$ngrams['comp_max'] = number_format(100 / ($length - $this->options['ngram_length'] + 1 - $this->options['extra_letters']), 3) + 0.001;
}
// Split word into ngrams.
for ($i = 0; $i < $length - $this->options['ngram_length'] + 1; $i++) {
$ngrams['ngrams'][] = drupal_substr($word, $i, $this->options['ngram_length']);
}
$field['value'][$key] += $ngrams;
$i = 9;
}
}
}