/** * Get the search query string in the mysql full text format * * Built to produce the same search strings as the search.php file. * The natural language hack is from search.php * * @param vB_Legacy_Current_User $user user requesting the search * @param vB_Search_Criteria $criteria search criteria to process */ protected function get_search_text($user, $criteria) { // If the user doesn't have permission to search full text boolean mode, // use natural language mode. if ($user->hasPermission('genericpermissions', 'cansearchft_bool')) { $words = $criteria->get_keywords(); $search_text = ""; $word_count = 0; foreach ($words as $word_item) { $word_count++; //The value of the first term is ambiguous. If the second term is //an "or" both the the first and second terms should be treated as //ors. If the second term is an "and" or "not" then the first term //should be an and. if ($word_count == 2 and $word_item['joiner'] != 'OR') { $search_text = "+{$search_text}"; } $word = $word_item['word']; switch ($word_item['joiner']) { case 'OR': // OR is no operator $search_text .= " {$word}"; break; case 'NOT': $search_text .= " -{$word}"; break; case 'AND': // if we didn't have a joiner, default to and // if we didn't have a joiner, default to and default: if ($search_text) { $search_text .= " +{$word}"; } else { //if this is the first token added, then we don't want to assume any //join logic. We need to figure that out on the second term. $search_text = $word; } break; } } //not 100% sure about this, but it matches the results in search.php $search_text = str_replace('"', '\\"', trim($search_text)); } else { $search_text = $criteria->get_raw_keywords(); //if we are using the raw search text, use the whole string as the display text $criteria->set_keyword_display_string('<b><u>' . htmlspecialchars_uni($search_text) . '</u></b>'); $criteria->set_highlights(array($search_text)); } return $search_text; }
/** * Hack to get original (unparced) text from search request. * Because vBulletin transform it in very stupid way. * Then fill some dependent variables. * * The word build up is taken from the socialgroup/blog implementation * The natural language hack is from search.php * * @param vB_Legacy_Current_User $user user requesting the search * @param vB_Search_Criteria $criteria search criteria to process */ protected function _get_search_text($user, $criteria) { $search_text = $criteria->get_raw_keywords(); //if we are using the raw search text, use the whole string as the display text $criteria->set_keyword_display_string('<b><u>' . htmlspecialchars_uni($search_text) . '</u></b>'); $criteria->set_highlights(array($search_text)); return trim($search_text); }