Skip to content

Instantly share code, notes, and snippets.

@jas8522
Created April 16, 2019 17:35
Show Gist options
  • Save jas8522/72aacf1e0a8c2b2f6d3a821bc8bf19b8 to your computer and use it in GitHub Desktop.
Save jas8522/72aacf1e0a8c2b2f6d3a821bc8bf19b8 to your computer and use it in GitHub Desktop.
woof by_text extention modification to support plurals and re-ordering of words
if (isset($WOOF->settings['by_text']['search_by_full_word'])) {
$search_by_full_word = (int) $WOOF->settings['by_text']['search_by_full_word'];
}
/*
if ($search_by_full_word) {
$woof_text = '[[:<:]]' . $woof_text . '[[:>:]]';
}
*/
/** ADDED APR 1, 2019 by websavers (+above comment out) **/
/* Handle Plurals */
if (!$search_by_full_word) { /* trimming "s" chars only works if search by full word is disabled */
$text_array = explode(' ', $woof_text); //make array
foreach($text_array as &$text ){
$text = rtrim($text, 's');
}
$woof_text = implode(' ', $text_array);
}
/* Handle order of words returning diff results */
$text_array = explode(" ", $woof_text);
$woof_t = str_replace(' ', '|', $woof_text);
$woof_text="";
foreach($text_array as $text ){
if ($search_by_full_word) {
$woof_text.= '([[:<:]]'.$woof_t . '[[:>:]])+(.*)';
}
else{
$woof_text.= '('.$woof_t . ')+(.*)';
}
}
/** END CHANGES APR 1, 2019 **/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment