/** * Function searchFull() * * This function performs a search to the search table for a given string. The query string * is first transformed into greeklish. The results are returned as an array, whose each element * is another array holding results data: * - 'foreign_ID' : The id of the entry that includes the search string, in the original table. * - 'table_name' : The original table name, where the search term came from * - 'position' : The posirion of the text, 'title' or 'data' * - 'score' : The relevance score * * @param string $text The text to search for * @param bool $tableName The database table to search into * @param string $position The position of the text, could be 'title' or 'data' * @param int $number The number of results to display * @since 3.5.0 * @access public */ public static function searchFull($text, $tableName = false, $position = false, $number = 20) { global $debugMessages; $debugMessages .= "Got into search"; $eachword = explode(" ", $text); $maxres = 10000; $score_ids = array(); for ($i = 0; $i < count($eachword); $i++) { if (mb_strlen($eachword[$i]) > 3) { $results[$i] = EfrontSearch::searchForOneWord($eachword[$i], $maxres, $tableName, $position); $score_ids[$i] = array_combine($results[$i]['foreign_ID'], $results[$i]['score']); $maxres = $maxres / 2; } } //These lines are used for removing empty subarrays because of words with mb_strlen < 3 foreach ($results as $key => $value) { if (!empty($value)) { $resultsTemp[] = $results[$key]; $score_idsTemp[] = $score_ids[$key]; } } $results = $resultsTemp; $score_ids = $score_idsTemp; $common_keys = $score_ids[0]; for ($i = 1; $i < sizeof($score_ids); $i++) { $common_keys = array_intersect_key($common_keys, $score_ids[$i]); foreach ($common_keys as $key => $value) { $common_keys[$key] += $score_ids[$i][$key] - 1; } } $field_data = array(); $max_score = max($common_keys); for ($i = 0; $i < sizeof($results[0]['foreign_ID']); $i++) { if (in_array($results[0]['foreign_ID'][$i], array_keys($common_keys))) { $field_data[] = array('foreign_ID' => $results[0]['foreign_ID'][$i], 'table_name' => array_search($results[0]['table_name'][$i], EfrontSearch::$tableAssoc), 'position' => $results[0]['position'][$i], 'score' => $common_keys[$results[0]['foreign_ID'][$i]] / $max_score); } } return $field_data; }