Exactly what the question says - I'm using Search API with Database Search. I also have the Porter Stemmer module, but my understanding is that it only works with the Drupal built-in search.
Any help with this would be greatly appreciated.
Exactly what the question says - I'm using Search API with Database Search. I also have the Porter Stemmer module, but my understanding is that it only works with the Drupal built-in search.
Any help with this would be greatly appreciated.
It is possible to use the Porter Stemmer module with other modules besides the Drupal standard search. I have done it before (with Views exposed filters).
In your module, you could either invoke the porterstemmer_search_preprocess()
function or just copy its contents into your own function. And then pass your search terms to this function. E.g.:
function your_function_for_preprocessing_text($text) {
// Include porterstemmer (change accordingly).
module_load_include('module', 'porterstemmer');
// Convert text to lower case, and replace special apostrophes with regular
// apostrophes.
$text = drupal_strtolower(str_replace('’', "'", $text));
// Split into words
$words = preg_split('/(' . PORTERSTEMMER_BOUNDARY . '+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
if (!count( $words )) {
return $text;
}
$has_pecl_stem = _porterstemmer_pecl_loaded();
// Process each word, skipping delimiters.
$isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] );
foreach ($words as $k => $word) {
if ($isword) {
if ( $has_pecl_stem ) {
$words[$k] = stem_english($word);
}
else {
$words[$k] = porterstemmer_stem($word);
}
}
$isword = !$isword;
}
// Put it all back together (note that delimiters are in $words).
return implode('', $words);
}
As I said, I have used the Porter Stemmer to stem all the terms entered in a Views exposed search. However, you'll still need to find the right hook in the Search API module to pre-process the text before the search query is run against the database.