2008-11-25 02:37:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Hooks provided by the Search module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup hooks
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-27 10:54:12 +00:00
|
|
|
* Preprocess text for search.
|
2008-11-25 02:37:33 +00:00
|
|
|
*
|
2013-02-04 19:11:11 +00:00
|
|
|
* This hook is called to preprocess both the text added to the search index
|
|
|
|
* and the keywords users have submitted for searching.
|
2008-11-25 02:37:33 +00:00
|
|
|
*
|
2010-02-27 10:54:12 +00:00
|
|
|
* Possible uses:
|
|
|
|
* - Adding spaces between words of Chinese or Japanese text.
|
|
|
|
* - Stemming words down to their root words to allow matches between, for
|
|
|
|
* instance, walk, walked, walking, and walks in searching.
|
|
|
|
* - Expanding abbreviations and acronymns that occur in text.
|
2008-11-25 02:37:33 +00:00
|
|
|
*
|
|
|
|
* @param $text
|
2010-02-27 10:54:12 +00:00
|
|
|
* The text to preprocess. This is a single piece of plain text extracted
|
|
|
|
* from between two HTML tags or from the search query. It will not contain
|
|
|
|
* any HTML entities or HTML tags.
|
2012-08-26 18:05:58 +00:00
|
|
|
* @param $langcode
|
2012-11-10 14:55:08 +00:00
|
|
|
* The language code of the entity that has been found.
|
2012-08-26 18:05:58 +00:00
|
|
|
*
|
2008-11-25 02:37:33 +00:00
|
|
|
* @return
|
2013-02-04 19:11:11 +00:00
|
|
|
* The text after preprocessing. Note that if your module decides not to
|
|
|
|
* alter the text, it should return the original text. Also, after
|
|
|
|
* preprocessing, words in the text should be separated by a space.
|
2009-08-29 21:05:16 +00:00
|
|
|
*
|
|
|
|
* @ingroup search
|
2008-11-25 02:37:33 +00:00
|
|
|
*/
|
2012-08-26 18:05:58 +00:00
|
|
|
function hook_search_preprocess($text, $langcode = NULL) {
|
|
|
|
// If the langcode is set to 'en' then add variations of the word "testing"
|
|
|
|
// which can also be found during English language searches.
|
|
|
|
if (isset($langcode) && $langcode == 'en') {
|
|
|
|
// Add the alternate verb forms for the word "testing".
|
|
|
|
if ($text == 'we are testing') {
|
|
|
|
$text .= ' test tested';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 02:37:33 +00:00
|
|
|
return $text;
|
|
|
|
}
|