indvdum@0: word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']); indvdum@0: indvdum@0: /** indvdum@0: * Load the UTF tools indvdum@0: */ indvdum@0: if (!class_exists('utf_normalizer')) indvdum@0: { indvdum@0: include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); indvdum@0: } indvdum@0: indvdum@0: indvdum@0: $error = false; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * This function fills $this->search_query with the cleaned user search query. indvdum@0: * indvdum@0: * If $terms is 'any' then the words will be extracted from the search query indvdum@0: * and combined with | inside brackets. They will afterwards be treated like indvdum@0: * an standard search query. indvdum@0: * indvdum@0: * Then it analyses the query and fills the internal arrays $must_not_contain_ids, indvdum@0: * $must_contain_ids and $must_exclude_one_ids which are later used by keyword_search(). indvdum@0: * indvdum@0: * @param string $keywords contains the search query string as entered by the user indvdum@0: * @param string $terms is either 'all' (use search query as entered, default words to 'must be contained in post') indvdum@0: * or 'any' (find all posts containing at least one of the given words) indvdum@0: * @return boolean false if no valid keywords were found and otherwise true indvdum@0: * indvdum@0: * @access public indvdum@0: */ indvdum@0: function split_keywords($keywords, $terms) indvdum@0: { indvdum@0: global $db, $user, $config; indvdum@0: indvdum@0: $tokens = '+-|()*'; indvdum@0: indvdum@0: $keywords = trim($this->cleanup($keywords, $tokens)); indvdum@0: indvdum@0: // allow word|word|word without brackets indvdum@0: if ((strpos($keywords, ' ') === false) && (strpos($keywords, '|') !== false) && (strpos($keywords, '(') === false)) indvdum@0: { indvdum@0: $keywords = '(' . $keywords . ')'; indvdum@0: } indvdum@0: indvdum@0: $open_bracket = $space = false; indvdum@0: for ($i = 0, $n = strlen($keywords); $i < $n; $i++) indvdum@0: { indvdum@0: if ($open_bracket !== false) indvdum@0: { indvdum@0: switch ($keywords[$i]) indvdum@0: { indvdum@0: case ')': indvdum@0: if ($open_bracket + 1 == $i) indvdum@0: { indvdum@0: $keywords[$i - 1] = '|'; indvdum@0: $keywords[$i] = '|'; indvdum@0: } indvdum@0: $open_bracket = false; indvdum@0: break; indvdum@0: case '(': indvdum@0: $keywords[$i] = '|'; indvdum@0: break; indvdum@0: case '+': indvdum@0: case '-': indvdum@0: case ' ': indvdum@0: $keywords[$i] = '|'; indvdum@0: break; indvdum@0: case '*': indvdum@0: if ($i === 0 || ($keywords[$i - 1] !== '*' && strcspn($keywords[$i - 1], $tokens) === 0)) indvdum@0: { indvdum@0: if ($i === $n - 1 || ($keywords[$i + 1] !== '*' && strcspn($keywords[$i + 1], $tokens) === 0)) indvdum@0: { indvdum@0: $keywords = substr($keywords, 0, $i) . substr($keywords, $i + 1); indvdum@0: } indvdum@0: } indvdum@0: break; indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: switch ($keywords[$i]) indvdum@0: { indvdum@0: case ')': indvdum@0: $keywords[$i] = ' '; indvdum@0: break; indvdum@0: case '(': indvdum@0: $open_bracket = $i; indvdum@0: $space = false; indvdum@0: break; indvdum@0: case '|': indvdum@0: $keywords[$i] = ' '; indvdum@0: break; indvdum@0: case '-': indvdum@0: case '+': indvdum@0: $space = $keywords[$i]; indvdum@0: break; indvdum@0: case ' ': indvdum@0: if ($space !== false) indvdum@0: { indvdum@0: $keywords[$i] = $space; indvdum@0: } indvdum@0: break; indvdum@0: default: indvdum@0: $space = false; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if ($open_bracket) indvdum@0: { indvdum@0: $keywords .= ')'; indvdum@0: } indvdum@0: indvdum@0: $match = array( indvdum@0: '# +#', indvdum@0: '#\|\|+#', indvdum@0: '#(\+|\-)(?:\+|\-)+#', indvdum@0: '#\(\|#', indvdum@0: '#\|\)#', indvdum@0: ); indvdum@0: $replace = array( indvdum@0: ' ', indvdum@0: '|', indvdum@0: '$1', indvdum@0: '(', indvdum@0: ')', indvdum@0: ); indvdum@0: indvdum@0: $keywords = preg_replace($match, $replace, $keywords); indvdum@0: $num_keywords = sizeof(explode(' ', $keywords)); indvdum@0: indvdum@0: // We limit the number of allowed keywords to minimize load on the database indvdum@0: if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords']) indvdum@0: { indvdum@0: trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords)); indvdum@0: } indvdum@0: indvdum@0: // $keywords input format: each word separated by a space, words in a bracket are not separated indvdum@0: indvdum@0: // the user wants to search for any word, convert the search query indvdum@0: if ($terms == 'any') indvdum@0: { indvdum@0: $words = array(); indvdum@0: indvdum@0: preg_match_all('#([^\\s+\\-|()]+)(?:$|[\\s+\\-|()])#u', $keywords, $words); indvdum@0: if (sizeof($words[1])) indvdum@0: { indvdum@0: $keywords = '(' . implode('|', $words[1]) . ')'; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // set the search_query which is shown to the user indvdum@0: $this->search_query = $keywords; indvdum@0: indvdum@0: $exact_words = array(); indvdum@0: preg_match_all('#([^\\s+\\-|*()]+)(?:$|[\\s+\\-|()])#u', $keywords, $exact_words); indvdum@0: $exact_words = $exact_words[1]; indvdum@0: indvdum@0: $common_ids = $words = array(); indvdum@0: indvdum@0: if (sizeof($exact_words)) indvdum@0: { indvdum@0: $sql = 'SELECT word_id, word_text, word_common indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('word_text', $exact_words) . ' indvdum@0: ORDER BY word_count ASC'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: // store an array of words and ids, remove common words indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: if ($row['word_common']) indvdum@0: { indvdum@0: $this->common_words[] = $row['word_text']; indvdum@0: $common_ids[$row['word_text']] = (int) $row['word_id']; indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: $words[$row['word_text']] = (int) $row['word_id']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: unset($exact_words); indvdum@0: indvdum@0: // now analyse the search query, first split it using the spaces indvdum@0: $query = explode(' ', $keywords); indvdum@0: indvdum@0: $this->must_contain_ids = array(); indvdum@0: $this->must_not_contain_ids = array(); indvdum@0: $this->must_exclude_one_ids = array(); indvdum@0: indvdum@0: $mode = ''; indvdum@0: $ignore_no_id = true; indvdum@0: indvdum@0: foreach ($query as $word) indvdum@0: { indvdum@0: if (empty($word)) indvdum@0: { indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: // words which should not be included indvdum@0: if ($word[0] == '-') indvdum@0: { indvdum@0: $word = substr($word, 1); indvdum@0: indvdum@0: // a group of which at least one may not be in the resulting posts indvdum@0: if ($word[0] == '(') indvdum@0: { indvdum@0: $word = array_unique(explode('|', substr($word, 1, -1))); indvdum@0: $mode = 'must_exclude_one'; indvdum@0: } indvdum@0: // one word which should not be in the resulting posts indvdum@0: else indvdum@0: { indvdum@0: $mode = 'must_not_contain'; indvdum@0: } indvdum@0: $ignore_no_id = true; indvdum@0: } indvdum@0: // words which have to be included indvdum@0: else indvdum@0: { indvdum@0: // no prefix is the same as a +prefix indvdum@0: if ($word[0] == '+') indvdum@0: { indvdum@0: $word = substr($word, 1); indvdum@0: } indvdum@0: indvdum@0: // a group of words of which at least one word should be in every resulting post indvdum@0: if ($word[0] == '(') indvdum@0: { indvdum@0: $word = array_unique(explode('|', substr($word, 1, -1))); indvdum@0: } indvdum@0: $ignore_no_id = false; indvdum@0: $mode = 'must_contain'; indvdum@0: } indvdum@0: indvdum@0: if (empty($word)) indvdum@0: { indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: // if this is an array of words then retrieve an id for each indvdum@0: if (is_array($word)) indvdum@0: { indvdum@0: $non_common_words = array(); indvdum@0: $id_words = array(); indvdum@0: foreach ($word as $i => $word_part) indvdum@0: { indvdum@0: if (strpos($word_part, '*') !== false) indvdum@0: { indvdum@0: $id_words[] = '\'' . $db->sql_escape(str_replace('*', '%', $word_part)) . '\''; indvdum@0: $non_common_words[] = $word_part; indvdum@0: } indvdum@0: else if (isset($words[$word_part])) indvdum@0: { indvdum@0: $id_words[] = $words[$word_part]; indvdum@0: $non_common_words[] = $word_part; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $len = utf8_strlen($word_part); indvdum@0: if ($len < $this->word_length['min'] || $len > $this->word_length['max']) indvdum@0: { indvdum@0: $this->common_words[] = $word_part; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: if (sizeof($id_words)) indvdum@0: { indvdum@0: sort($id_words); indvdum@0: if (sizeof($id_words) > 1) indvdum@0: { indvdum@0: $this->{$mode . '_ids'}[] = $id_words; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $mode = ($mode == 'must_exclude_one') ? 'must_not_contain' : $mode; indvdum@0: $this->{$mode . '_ids'}[] = $id_words[0]; indvdum@0: } indvdum@0: } indvdum@0: // throw an error if we shall not ignore unexistant words indvdum@0: else if (!$ignore_no_id && sizeof($non_common_words)) indvdum@0: { indvdum@0: trigger_error(sprintf($user->lang['WORDS_IN_NO_POST'], implode(', ', $non_common_words))); indvdum@0: } indvdum@0: unset($non_common_words); indvdum@0: } indvdum@0: // else we only need one id indvdum@0: else if (($wildcard = strpos($word, '*') !== false) || isset($words[$word])) indvdum@0: { indvdum@0: if ($wildcard) indvdum@0: { indvdum@0: $len = utf8_strlen(str_replace('*', '', $word)); indvdum@0: if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) indvdum@0: { indvdum@0: $this->{$mode . '_ids'}[] = '\'' . $db->sql_escape(str_replace('*', '%', $word)) . '\''; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $this->common_words[] = $word; indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $this->{$mode . '_ids'}[] = $words[$word]; indvdum@0: } indvdum@0: } indvdum@0: // throw an error if we shall not ignore unexistant words indvdum@0: else if (!$ignore_no_id) indvdum@0: { indvdum@0: if (!isset($common_ids[$word])) indvdum@0: { indvdum@0: $len = utf8_strlen($word); indvdum@0: if ($len >= $this->word_length['min'] && $len <= $this->word_length['max']) indvdum@0: { indvdum@0: trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word)); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $this->common_words[] = $word; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $len = utf8_strlen($word); indvdum@0: if ($len < $this->word_length['min'] || $len > $this->word_length['max']) indvdum@0: { indvdum@0: $this->common_words[] = $word; indvdum@0: } indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // we can't search for negatives only indvdum@0: if (!sizeof($this->must_contain_ids)) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: if (!empty($this->search_query)) indvdum@0: { indvdum@0: return true; indvdum@0: } indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Performs a search on keywords depending on display specific params. You have to run split_keywords() first. indvdum@0: * indvdum@0: * @param string $type contains either posts or topics depending on what should be searched for indvdum@0: * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched) indvdum@0: * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words) indvdum@0: * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query indvdum@0: * @param string $sort_key is the key of $sort_by_sql for the selected sorting indvdum@0: * @param string $sort_dir is either a or d representing ASC and DESC indvdum@0: * @param string $sort_days specifies the maximum amount of days a post may be old indvdum@0: * @param array $ex_fid_ary specifies an array of forum ids which should not be searched indvdum@0: * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts indvdum@0: * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched indvdum@0: * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty indvdum@0: * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match indvdum@0: * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered indvdum@0: * @param int $start indicates the first index of the page indvdum@0: * @param int $per_page number of ids each page is supposed to contain indvdum@0: * @return boolean|int total number of results indvdum@0: * indvdum@0: * @access public indvdum@0: */ indvdum@0: function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) indvdum@0: { indvdum@0: global $config, $db; indvdum@0: indvdum@0: // No keywords? No posts. indvdum@0: if (empty($this->search_query)) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: $must_contain_ids = $this->must_contain_ids; indvdum@0: $must_not_contain_ids = $this->must_not_contain_ids; indvdum@0: $must_exclude_one_ids = $this->must_exclude_one_ids; indvdum@0: indvdum@0: sort($must_contain_ids); indvdum@0: sort($must_not_contain_ids); indvdum@0: sort($must_exclude_one_ids); indvdum@0: indvdum@0: // generate a search_key from all the options to identify the results indvdum@0: $search_key = md5(implode('#', array( indvdum@0: serialize($must_contain_ids), indvdum@0: serialize($must_not_contain_ids), indvdum@0: serialize($must_exclude_one_ids), indvdum@0: $type, indvdum@0: $fields, indvdum@0: $terms, indvdum@0: $sort_days, indvdum@0: $sort_key, indvdum@0: $topic_id, indvdum@0: implode(',', $ex_fid_ary), indvdum@0: implode(',', $m_approve_fid_ary), indvdum@0: implode(',', $author_ary), indvdum@0: $author_name, indvdum@0: ))); indvdum@0: indvdum@0: // try reading the results from cache indvdum@0: $total_results = 0; indvdum@0: if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) indvdum@0: { indvdum@0: return $total_results; indvdum@0: } indvdum@0: indvdum@0: $id_ary = array(); indvdum@0: indvdum@0: $sql_where = array(); indvdum@0: $group_by = false; indvdum@0: $m_num = 0; indvdum@0: $w_num = 0; indvdum@0: indvdum@0: $sql_array = array( indvdum@0: 'SELECT' => ($type == 'posts') ? 'p.post_id' : 'p.topic_id', indvdum@0: 'FROM' => array( indvdum@0: SEARCH_WORDMATCH_TABLE => array(), indvdum@0: SEARCH_WORDLIST_TABLE => array(), indvdum@0: ), indvdum@0: 'LEFT_JOIN' => array(array( indvdum@0: 'FROM' => array(POSTS_TABLE => 'p'), indvdum@0: 'ON' => 'm0.post_id = p.post_id', indvdum@0: )), indvdum@0: ); indvdum@0: indvdum@0: $title_match = ''; indvdum@0: $left_join_topics = false; indvdum@0: $group_by = true; indvdum@0: // Build some display specific sql strings indvdum@0: switch ($fields) indvdum@0: { indvdum@0: case 'titleonly': indvdum@0: $title_match = 'title_match = 1'; indvdum@0: $group_by = false; indvdum@0: // no break indvdum@0: case 'firstpost': indvdum@0: $left_join_topics = true; indvdum@0: $sql_where[] = 'p.post_id = t.topic_first_post_id'; indvdum@0: break; indvdum@0: indvdum@0: case 'msgonly': indvdum@0: $title_match = 'title_match = 0'; indvdum@0: $group_by = false; indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: if ($type == 'topics') indvdum@0: { indvdum@0: $left_join_topics = true; indvdum@0: $group_by = true; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * @todo Add a query optimizer (handle stuff like "+(4|3) +4") indvdum@0: */ indvdum@0: indvdum@0: foreach ($this->must_contain_ids as $subquery) indvdum@0: { indvdum@0: if (is_array($subquery)) indvdum@0: { indvdum@0: $group_by = true; indvdum@0: indvdum@0: $word_id_sql = array(); indvdum@0: $word_ids = array(); indvdum@0: foreach ($subquery as $id) indvdum@0: { indvdum@0: if (is_string($id)) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), indvdum@0: 'ON' => "w$w_num.word_text LIKE $id" indvdum@0: ); indvdum@0: $word_ids[] = "w$w_num.word_id"; indvdum@0: indvdum@0: $w_num++; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $word_ids[] = $id; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $sql_where[] = $db->sql_in_set("m$m_num.word_id", $word_ids); indvdum@0: indvdum@0: unset($word_id_sql); indvdum@0: unset($word_ids); indvdum@0: } indvdum@0: else if (is_string($subquery)) indvdum@0: { indvdum@0: $sql_array['FROM'][SEARCH_WORDLIST_TABLE][] = 'w' . $w_num; indvdum@0: indvdum@0: $sql_where[] = "w$w_num.word_text LIKE $subquery"; indvdum@0: $sql_where[] = "m$m_num.word_id = w$w_num.word_id"; indvdum@0: indvdum@0: $group_by = true; indvdum@0: $w_num++; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $sql_where[] = "m$m_num.word_id = $subquery"; indvdum@0: } indvdum@0: indvdum@0: $sql_array['FROM'][SEARCH_WORDMATCH_TABLE][] = 'm' . $m_num; indvdum@0: indvdum@0: if ($title_match) indvdum@0: { indvdum@0: $sql_where[] = "m$m_num.$title_match"; indvdum@0: } indvdum@0: indvdum@0: if ($m_num != 0) indvdum@0: { indvdum@0: $sql_where[] = "m$m_num.post_id = m0.post_id"; indvdum@0: } indvdum@0: $m_num++; indvdum@0: } indvdum@0: indvdum@0: foreach ($this->must_not_contain_ids as $key => $subquery) indvdum@0: { indvdum@0: if (is_string($subquery)) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), indvdum@0: 'ON' => "w$w_num.word_text LIKE $subquery" indvdum@0: ); indvdum@0: indvdum@0: $this->must_not_contain_ids[$key] = "w$w_num.word_id"; indvdum@0: indvdum@0: $group_by = true; indvdum@0: $w_num++; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (sizeof($this->must_not_contain_ids)) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), indvdum@0: 'ON' => $db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" indvdum@0: ); indvdum@0: indvdum@0: $sql_where[] = "m$m_num.word_id IS NULL"; indvdum@0: $m_num++; indvdum@0: } indvdum@0: indvdum@0: foreach ($this->must_exclude_one_ids as $ids) indvdum@0: { indvdum@0: $is_null_joins = array(); indvdum@0: foreach ($ids as $id) indvdum@0: { indvdum@0: if (is_string($id)) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), indvdum@0: 'ON' => "w$w_num.word_text LIKE $id" indvdum@0: ); indvdum@0: $id = "w$w_num.word_id"; indvdum@0: indvdum@0: $group_by = true; indvdum@0: $w_num++; indvdum@0: } indvdum@0: indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), indvdum@0: 'ON' => "m$m_num.word_id = $id AND m$m_num.post_id = m0.post_id" . (($title_match) ? " AND m$m_num.$title_match" : '') indvdum@0: ); indvdum@0: $is_null_joins[] = "m$m_num.word_id IS NULL"; indvdum@0: indvdum@0: $m_num++; indvdum@0: } indvdum@0: $sql_where[] = '(' . implode(' OR ', $is_null_joins) . ')'; indvdum@0: } indvdum@0: indvdum@0: if (!sizeof($m_approve_fid_ary)) indvdum@0: { indvdum@0: $sql_where[] = 'p.post_approved = 1'; indvdum@0: } indvdum@0: else if ($m_approve_fid_ary !== array(-1)) indvdum@0: { indvdum@0: $sql_where[] = '(p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; indvdum@0: } indvdum@0: indvdum@0: if ($topic_id) indvdum@0: { indvdum@0: $sql_where[] = 'p.topic_id = ' . $topic_id; indvdum@0: } indvdum@0: indvdum@0: if (sizeof($author_ary)) indvdum@0: { indvdum@0: if ($author_name) indvdum@0: { indvdum@0: // first one matches post of registered users, second one guests and deleted users indvdum@0: $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $sql_author = $db->sql_in_set('p.poster_id', $author_ary); indvdum@0: } indvdum@0: $sql_where[] = $sql_author; indvdum@0: } indvdum@0: indvdum@0: if (sizeof($ex_fid_ary)) indvdum@0: { indvdum@0: $sql_where[] = $db->sql_in_set('p.forum_id', $ex_fid_ary, true); indvdum@0: } indvdum@0: indvdum@0: if ($sort_days) indvdum@0: { indvdum@0: $sql_where[] = 'p.post_time >= ' . (time() - ($sort_days * 86400)); indvdum@0: } indvdum@0: indvdum@0: $sql_array['WHERE'] = implode(' AND ', $sql_where); indvdum@0: indvdum@0: $is_mysql = false; indvdum@0: // if the total result count is not cached yet, retrieve it from the db indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: $sql = ''; indvdum@0: $sql_array_count = $sql_array; indvdum@0: indvdum@0: if ($left_join_topics) indvdum@0: { indvdum@0: $sql_array_count['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(TOPICS_TABLE => 't'), indvdum@0: 'ON' => 'p.topic_id = t.topic_id' indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: switch ($db->sql_layer) indvdum@0: { indvdum@0: case 'mysql4': indvdum@0: case 'mysqli': indvdum@0: indvdum@0: // 3.x does not support SQL_CALC_FOUND_ROWS indvdum@0: // $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT']; indvdum@0: $is_mysql = true; indvdum@0: indvdum@0: break; indvdum@0: indvdum@0: case 'sqlite': indvdum@0: $sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id'; indvdum@0: $sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results indvdum@0: FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')'; indvdum@0: indvdum@0: // no break indvdum@0: indvdum@0: default: indvdum@0: $sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results'; indvdum@0: $sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql; indvdum@0: indvdum@0: $result = $db->sql_query($sql); indvdum@0: $total_results = (int) $db->sql_fetchfield('total_results'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: unset($sql_array_count, $sql); indvdum@0: } indvdum@0: indvdum@0: // Build sql strings for sorting indvdum@0: $sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); indvdum@0: indvdum@0: switch ($sql_sort[0]) indvdum@0: { indvdum@0: case 'u': indvdum@0: $sql_array['FROM'][USERS_TABLE] = 'u'; indvdum@0: $sql_where[] = 'u.user_id = p.poster_id '; indvdum@0: break; indvdum@0: indvdum@0: case 't': indvdum@0: $left_join_topics = true; indvdum@0: break; indvdum@0: indvdum@0: case 'f': indvdum@0: $sql_array['FROM'][FORUMS_TABLE] = 'f'; indvdum@0: $sql_where[] = 'f.forum_id = p.forum_id'; indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: if ($left_join_topics) indvdum@0: { indvdum@0: $sql_array['LEFT_JOIN'][] = array( indvdum@0: 'FROM' => array(TOPICS_TABLE => 't'), indvdum@0: 'ON' => 'p.topic_id = t.topic_id' indvdum@0: ); indvdum@0: } indvdum@0: indvdum@0: $sql_array['WHERE'] = implode(' AND ', $sql_where); indvdum@0: $sql_array['GROUP_BY'] = ($group_by) ? (($type == 'posts') ? 'p.post_id' : 'p.topic_id') . ', ' . $sort_by_sql[$sort_key] : ''; indvdum@0: $sql_array['ORDER_BY'] = $sql_sort; indvdum@0: indvdum@0: unset($sql_where, $sql_sort, $group_by); indvdum@0: indvdum@0: $sql = $db->sql_build_query('SELECT', $sql_array); indvdum@0: $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!sizeof($id_ary)) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: // if we use mysql and the total result count is not cached yet, retrieve it from the db indvdum@0: if (!$total_results && $is_mysql) indvdum@0: { indvdum@0: // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. indvdum@0: $sql_array_copy = $sql_array; indvdum@0: $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; indvdum@0: indvdum@0: $sql = $db->sql_build_query('SELECT', $sql_array_copy); indvdum@0: unset($sql_array_copy); indvdum@0: indvdum@0: $db->sql_query($sql); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $sql = 'SELECT FOUND_ROWS() as total_results'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $total_results = (int) $db->sql_fetchfield('total_results'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page indvdum@0: $this->save_ids($search_key, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir); indvdum@0: $id_ary = array_slice($id_ary, 0, (int) $per_page); indvdum@0: indvdum@0: return $total_results; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Performs a search on an author's posts without caring about message contents. Depends on display specific params indvdum@0: * indvdum@0: * @param string $type contains either posts or topics depending on what should be searched for indvdum@0: * @param boolean $firstpost_only if true, only topic starting posts will be considered indvdum@0: * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query indvdum@0: * @param string $sort_key is the key of $sort_by_sql for the selected sorting indvdum@0: * @param string $sort_dir is either a or d representing ASC and DESC indvdum@0: * @param string $sort_days specifies the maximum amount of days a post may be old indvdum@0: * @param array $ex_fid_ary specifies an array of forum ids which should not be searched indvdum@0: * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts indvdum@0: * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched indvdum@0: * @param array $author_ary an array of author ids indvdum@0: * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match indvdum@0: * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered indvdum@0: * @param int $start indicates the first index of the page indvdum@0: * @param int $per_page number of ids each page is supposed to contain indvdum@0: * @return boolean|int total number of results indvdum@0: * indvdum@0: * @access public indvdum@0: */ indvdum@0: function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) indvdum@0: { indvdum@0: global $config, $db; indvdum@0: indvdum@0: // No author? No posts. indvdum@0: if (!sizeof($author_ary)) indvdum@0: { indvdum@0: return 0; indvdum@0: } indvdum@0: indvdum@0: // generate a search_key from all the options to identify the results indvdum@0: $search_key = md5(implode('#', array( indvdum@0: '', indvdum@0: $type, indvdum@0: ($firstpost_only) ? 'firstpost' : '', indvdum@0: '', indvdum@0: '', indvdum@0: $sort_days, indvdum@0: $sort_key, indvdum@0: $topic_id, indvdum@0: implode(',', $ex_fid_ary), indvdum@0: implode(',', $m_approve_fid_ary), indvdum@0: implode(',', $author_ary), indvdum@0: $author_name, indvdum@0: ))); indvdum@0: indvdum@0: // try reading the results from cache indvdum@0: $total_results = 0; indvdum@0: if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) indvdum@0: { indvdum@0: return $total_results; indvdum@0: } indvdum@0: indvdum@0: $id_ary = array(); indvdum@0: indvdum@0: // Create some display specific sql strings indvdum@0: if ($author_name) indvdum@0: { indvdum@0: // first one matches post of registered users, second one guests and deleted users indvdum@0: $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $sql_author = $db->sql_in_set('p.poster_id', $author_ary); indvdum@0: } indvdum@0: $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; indvdum@0: $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; indvdum@0: $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; indvdum@0: $sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : ''; indvdum@0: indvdum@0: // Build sql strings for sorting indvdum@0: $sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); indvdum@0: $sql_sort_table = $sql_sort_join = ''; indvdum@0: switch ($sql_sort[0]) indvdum@0: { indvdum@0: case 'u': indvdum@0: $sql_sort_table = USERS_TABLE . ' u, '; indvdum@0: $sql_sort_join = ' AND u.user_id = p.poster_id '; indvdum@0: break; indvdum@0: indvdum@0: case 't': indvdum@0: $sql_sort_table = ($type == 'posts' && !$firstpost_only) ? TOPICS_TABLE . ' t, ' : ''; indvdum@0: $sql_sort_join = ($type == 'posts' && !$firstpost_only) ? ' AND t.topic_id = p.topic_id ' : ''; indvdum@0: break; indvdum@0: indvdum@0: case 'f': indvdum@0: $sql_sort_table = FORUMS_TABLE . ' f, '; indvdum@0: $sql_sort_join = ' AND f.forum_id = p.forum_id '; indvdum@0: break; indvdum@0: } indvdum@0: indvdum@0: if (!sizeof($m_approve_fid_ary)) indvdum@0: { indvdum@0: $m_approve_fid_sql = ' AND p.post_approved = 1'; indvdum@0: } indvdum@0: else if ($m_approve_fid_ary == array(-1)) indvdum@0: { indvdum@0: $m_approve_fid_sql = ''; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')'; indvdum@0: } indvdum@0: indvdum@0: $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; indvdum@0: $is_mysql = false; indvdum@0: indvdum@0: // If the cache was completely empty count the results indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: switch ($db->sql_layer) indvdum@0: { indvdum@0: case 'mysql4': indvdum@0: case 'mysqli': indvdum@0: // $select = 'SQL_CALC_FOUND_ROWS ' . $select; indvdum@0: $is_mysql = true; indvdum@0: break; indvdum@0: indvdum@0: default: indvdum@0: if ($type == 'posts') indvdum@0: { indvdum@0: $sql = 'SELECT COUNT(p.post_id) as total_results indvdum@0: FROM ' . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t ' : ' ') . " indvdum@0: WHERE $sql_author indvdum@0: $sql_topic_id indvdum@0: $sql_firstpost indvdum@0: $m_approve_fid_sql indvdum@0: $sql_fora indvdum@0: $sql_time"; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: if ($db->sql_layer == 'sqlite') indvdum@0: { indvdum@0: $sql = 'SELECT COUNT(topic_id) as total_results indvdum@0: FROM (SELECT DISTINCT t.topic_id'; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $sql = 'SELECT COUNT(DISTINCT t.topic_id) as total_results'; indvdum@0: } indvdum@0: indvdum@0: $sql .= ' FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p indvdum@0: WHERE $sql_author indvdum@0: $sql_topic_id indvdum@0: $sql_firstpost indvdum@0: $m_approve_fid_sql indvdum@0: $sql_fora indvdum@0: AND t.topic_id = p.topic_id indvdum@0: $sql_time" . (($db->sql_layer == 'sqlite') ? ')' : ''); indvdum@0: } indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: $total_results = (int) $db->sql_fetchfield('total_results'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: break; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: // Build the query for really selecting the post_ids indvdum@0: if ($type == 'posts') indvdum@0: { indvdum@0: $sql = "SELECT $select indvdum@0: FROM " . $sql_sort_table . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t' : '') . " indvdum@0: WHERE $sql_author indvdum@0: $sql_topic_id indvdum@0: $sql_firstpost indvdum@0: $m_approve_fid_sql indvdum@0: $sql_fora indvdum@0: $sql_sort_join indvdum@0: $sql_time indvdum@0: ORDER BY $sql_sort"; indvdum@0: $field = 'post_id'; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $sql = "SELECT $select indvdum@0: FROM " . $sql_sort_table . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p indvdum@0: WHERE $sql_author indvdum@0: $sql_topic_id indvdum@0: $sql_firstpost indvdum@0: $m_approve_fid_sql indvdum@0: $sql_fora indvdum@0: AND t.topic_id = p.topic_id indvdum@0: $sql_sort_join indvdum@0: $sql_time indvdum@0: GROUP BY t.topic_id, " . $sort_by_sql[$sort_key] . ' indvdum@0: ORDER BY ' . $sql_sort; indvdum@0: $field = 'topic_id'; indvdum@0: } indvdum@0: indvdum@0: // Only read one block of posts from the db and then cache it indvdum@0: $result = $db->sql_query_limit($sql, $config['search_block_size'], $start); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $id_ary[] = (int) $row[$field]; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$total_results && $is_mysql) indvdum@0: { indvdum@0: // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. indvdum@0: $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); indvdum@0: indvdum@0: $db->sql_query($sql); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $sql = 'SELECT FOUND_ROWS() as total_results'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $total_results = (int) $db->sql_fetchfield('total_results'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (!$total_results) indvdum@0: { indvdum@0: return false; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (sizeof($id_ary)) indvdum@0: { indvdum@0: $this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir); indvdum@0: $id_ary = array_slice($id_ary, 0, $per_page); indvdum@0: indvdum@0: return $total_results; indvdum@0: } indvdum@0: return false; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Split a text into words of a given length indvdum@0: * indvdum@0: * The text is converted to UTF-8, cleaned up, and split. Then, words that indvdum@0: * conform to the defined length range are returned in an array. indvdum@0: * indvdum@0: * NOTE: duplicates are NOT removed from the return array indvdum@0: * indvdum@0: * @param string $text Text to split, encoded in UTF-8 indvdum@0: * @return array Array of UTF-8 words indvdum@0: * indvdum@0: * @access private indvdum@0: */ indvdum@0: function split_message($text) indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx, $user; indvdum@0: indvdum@0: $match = $words = array(); indvdum@0: indvdum@0: /** indvdum@0: * Taken from the original code indvdum@0: */ indvdum@0: // Do not index code indvdum@0: $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is'; indvdum@0: // BBcode indvdum@0: $match[] = '#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?[0-9a-z]{5,})\]#'; indvdum@0: indvdum@0: $min = $this->word_length['min']; indvdum@0: $max = $this->word_length['max']; indvdum@0: indvdum@0: $isset_min = $min - 1; indvdum@0: indvdum@0: /** indvdum@0: * Clean up the string, remove HTML tags, remove BBCodes indvdum@0: */ indvdum@0: $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1), ' '); indvdum@0: indvdum@0: while (strlen($word)) indvdum@0: { indvdum@0: if (strlen($word) > 255 || strlen($word) <= $isset_min) indvdum@0: { indvdum@0: /** indvdum@0: * Words longer than 255 bytes are ignored. This will have to be indvdum@0: * changed whenever we change the length of search_wordlist.word_text indvdum@0: * indvdum@0: * Words shorter than $isset_min bytes are ignored, too indvdum@0: */ indvdum@0: $word = strtok(' '); indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: $len = utf8_strlen($word); indvdum@0: indvdum@0: /** indvdum@0: * Test whether the word is too short to be indexed. indvdum@0: * indvdum@0: * Note that this limit does NOT apply to CJK and Hangul indvdum@0: */ indvdum@0: if ($len < $min) indvdum@0: { indvdum@0: /** indvdum@0: * Note: this could be optimized. If the codepoint is lower than Hangul's range indvdum@0: * we know that it will also be lower than CJK ranges indvdum@0: */ indvdum@0: if ((strncmp($word, UTF8_HANGUL_FIRST, 3) < 0 || strncmp($word, UTF8_HANGUL_LAST, 3) > 0) indvdum@0: && (strncmp($word, UTF8_CJK_FIRST, 3) < 0 || strncmp($word, UTF8_CJK_LAST, 3) > 0) indvdum@0: && (strncmp($word, UTF8_CJK_B_FIRST, 4) < 0 || strncmp($word, UTF8_CJK_B_LAST, 4) > 0)) indvdum@0: { indvdum@0: $word = strtok(' '); indvdum@0: continue; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $words[] = $word; indvdum@0: $word = strtok(' '); indvdum@0: } indvdum@0: indvdum@0: return $words; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Updates wordlist and wordmatch tables when a message is posted or changed indvdum@0: * indvdum@0: * @param string $mode Contains the post mode: edit, post, reply, quote indvdum@0: * @param int $post_id The id of the post which is modified/created indvdum@0: * @param string &$message New or updated post content indvdum@0: * @param string &$subject New or updated post subject indvdum@0: * @param int $poster_id Post author's user id indvdum@0: * @param int $forum_id The id of the forum in which the post is located indvdum@0: * indvdum@0: * @access public indvdum@0: */ indvdum@0: function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) indvdum@0: { indvdum@0: global $config, $db, $user; indvdum@0: indvdum@0: if (!$config['fulltext_native_load_upd']) indvdum@0: { indvdum@0: /** indvdum@0: * The search indexer is disabled, return indvdum@0: */ indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: // Split old and new post/subject to obtain array of 'words' indvdum@0: $split_text = $this->split_message($message); indvdum@0: $split_title = $this->split_message($subject); indvdum@0: indvdum@0: $cur_words = array('post' => array(), 'title' => array()); indvdum@0: indvdum@0: $words = array(); indvdum@0: if ($mode == 'edit') indvdum@0: { indvdum@0: $words['add']['post'] = array(); indvdum@0: $words['add']['title'] = array(); indvdum@0: $words['del']['post'] = array(); indvdum@0: $words['del']['title'] = array(); indvdum@0: indvdum@0: $sql = 'SELECT w.word_id, w.word_text, m.title_match indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m indvdum@0: WHERE m.post_id = $post_id indvdum@0: AND w.word_id = m.word_id"; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $which = ($row['title_match']) ? 'title' : 'post'; indvdum@0: $cur_words[$which][$row['word_text']] = $row['word_id']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $words['add']['post'] = array_diff($split_text, array_keys($cur_words['post'])); indvdum@0: $words['add']['title'] = array_diff($split_title, array_keys($cur_words['title'])); indvdum@0: $words['del']['post'] = array_diff(array_keys($cur_words['post']), $split_text); indvdum@0: $words['del']['title'] = array_diff(array_keys($cur_words['title']), $split_title); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $words['add']['post'] = $split_text; indvdum@0: $words['add']['title'] = $split_title; indvdum@0: $words['del']['post'] = array(); indvdum@0: $words['del']['title'] = array(); indvdum@0: } indvdum@0: unset($split_text); indvdum@0: unset($split_title); indvdum@0: indvdum@0: // Get unique words from the above arrays indvdum@0: $unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title'])); indvdum@0: indvdum@0: // We now have unique arrays of all words to be added and removed and indvdum@0: // individual arrays of added and removed words for text and title. What indvdum@0: // we need to do now is add the new words (if they don't already exist) indvdum@0: // and then add (or remove) matches between the words and this post indvdum@0: if (sizeof($unique_add_words)) indvdum@0: { indvdum@0: $sql = 'SELECT word_id, word_text indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('word_text', $unique_add_words); indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: $word_ids = array(); indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $word_ids[$row['word_text']] = $row['word_id']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: $new_words = array_diff($unique_add_words, array_keys($word_ids)); indvdum@0: indvdum@0: $db->sql_transaction('begin'); indvdum@0: if (sizeof($new_words)) indvdum@0: { indvdum@0: $sql_ary = array(); indvdum@0: indvdum@0: foreach ($new_words as $word) indvdum@0: { indvdum@0: $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); indvdum@0: } indvdum@0: $db->sql_return_on_error(true); indvdum@0: $db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); indvdum@0: $db->sql_return_on_error(false); indvdum@0: } indvdum@0: unset($new_words, $sql_ary); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $db->sql_transaction('begin'); indvdum@0: } indvdum@0: indvdum@0: // now update the search match table, remove links to removed words and add links to new words indvdum@0: foreach ($words['del'] as $word_in => $word_ary) indvdum@0: { indvdum@0: $title_match = ($word_in == 'title') ? 1 : 0; indvdum@0: indvdum@0: if (sizeof($word_ary)) indvdum@0: { indvdum@0: $sql_in = array(); indvdum@0: foreach ($word_ary as $word) indvdum@0: { indvdum@0: $sql_in[] = $cur_words[$word_in][$word]; indvdum@0: } indvdum@0: indvdum@0: $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' indvdum@0: AND post_id = ' . intval($post_id) . " indvdum@0: AND title_match = $title_match"; indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: SET word_count = word_count - 1 indvdum@0: WHERE ' . $db->sql_in_set('word_id', $sql_in) . ' indvdum@0: AND word_count > 0'; indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: unset($sql_in); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: $db->sql_return_on_error(true); indvdum@0: foreach ($words['add'] as $word_in => $word_ary) indvdum@0: { indvdum@0: $title_match = ($word_in == 'title') ? 1 : 0; indvdum@0: indvdum@0: if (sizeof($word_ary)) indvdum@0: { indvdum@0: $sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) indvdum@0: SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('word_text', $word_ary); indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: SET word_count = word_count + 1 indvdum@0: WHERE ' . $db->sql_in_set('word_text', $word_ary); indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: } indvdum@0: $db->sql_return_on_error(false); indvdum@0: indvdum@0: $db->sql_transaction('commit'); indvdum@0: indvdum@0: // destroy cached search results containing any of the words removed or added indvdum@0: $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id)); indvdum@0: indvdum@0: unset($unique_add_words); indvdum@0: unset($words); indvdum@0: unset($cur_words); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Removes entries from the wordmatch table for the specified post_ids indvdum@0: */ indvdum@0: function index_remove($post_ids, $author_ids, $forum_ids) indvdum@0: { indvdum@0: global $db; indvdum@0: indvdum@0: if (sizeof($post_ids)) indvdum@0: { indvdum@0: $sql = 'SELECT w.word_id, w.word_text, m.title_match indvdum@0: FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w indvdum@0: WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . ' indvdum@0: AND w.word_id = m.word_id'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: $message_word_ids = $title_word_ids = $word_texts = array(); indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: if ($row['title_match']) indvdum@0: { indvdum@0: $title_word_ids[] = $row['word_id']; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: $message_word_ids[] = $row['word_id']; indvdum@0: } indvdum@0: $word_texts[] = $row['word_text']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (sizeof($title_word_ids)) indvdum@0: { indvdum@0: $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: SET word_count = word_count - 1 indvdum@0: WHERE ' . $db->sql_in_set('word_id', $title_word_ids) . ' indvdum@0: AND word_count > 0'; indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: indvdum@0: if (sizeof($message_word_ids)) indvdum@0: { indvdum@0: $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: SET word_count = word_count - 1 indvdum@0: WHERE ' . $db->sql_in_set('word_id', $message_word_ids) . ' indvdum@0: AND word_count > 0'; indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: indvdum@0: unset($title_word_ids); indvdum@0: unset($message_word_ids); indvdum@0: indvdum@0: $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('post_id', $post_ids); indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: indvdum@0: $this->destroy_cache(array_unique($word_texts), $author_ids); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Tidy up indexes: Tag 'common words' and remove indvdum@0: * words no longer referenced in the match table indvdum@0: */ indvdum@0: function tidy() indvdum@0: { indvdum@0: global $db, $config; indvdum@0: indvdum@0: // Is the fulltext indexer disabled? If yes then we need not indvdum@0: // carry on ... it's okay ... I know when I'm not wanted boo hoo indvdum@0: if (!$config['fulltext_native_load_upd']) indvdum@0: { indvdum@0: set_config('search_last_gc', time(), true); indvdum@0: return; indvdum@0: } indvdum@0: indvdum@0: $destroy_cache_words = array(); indvdum@0: indvdum@0: // Remove common words indvdum@0: if ($config['num_posts'] >= 100 && $config['fulltext_native_common_thres']) indvdum@0: { indvdum@0: $common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0; indvdum@0: // First, get the IDs of common words indvdum@0: $sql = 'SELECT word_id, word_text indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . ' indvdum@0: OR word_common = 1'; indvdum@0: $result = $db->sql_query($sql); indvdum@0: indvdum@0: $sql_in = array(); indvdum@0: while ($row = $db->sql_fetchrow($result)) indvdum@0: { indvdum@0: $sql_in[] = $row['word_id']; indvdum@0: $destroy_cache_words[] = $row['word_text']; indvdum@0: } indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: if (sizeof($sql_in)) indvdum@0: { indvdum@0: // Flag the words indvdum@0: $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' indvdum@0: SET word_common = 1 indvdum@0: WHERE ' . $db->sql_in_set('word_id', $sql_in); indvdum@0: $db->sql_query($sql); indvdum@0: indvdum@0: // by setting search_last_gc to the new time here we make sure that if a user reloads because the indvdum@0: // following query takes too long, he won't run into it again indvdum@0: set_config('search_last_gc', time(), true); indvdum@0: indvdum@0: // Delete the matches indvdum@0: $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' indvdum@0: WHERE ' . $db->sql_in_set('word_id', $sql_in); indvdum@0: $db->sql_query($sql); indvdum@0: } indvdum@0: unset($sql_in); indvdum@0: } indvdum@0: indvdum@0: if (sizeof($destroy_cache_words)) indvdum@0: { indvdum@0: // destroy cached search results containing any of the words that are now common or were removed indvdum@0: $this->destroy_cache(array_unique($destroy_cache_words)); indvdum@0: } indvdum@0: indvdum@0: set_config('search_last_gc', time(), true); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Deletes all words from the index indvdum@0: */ indvdum@0: function delete_index($acp_module, $u_action) indvdum@0: { indvdum@0: global $db; indvdum@0: indvdum@0: switch ($db->sql_layer) indvdum@0: { indvdum@0: case 'sqlite': indvdum@0: case 'firebird': indvdum@0: $db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE); indvdum@0: $db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE); indvdum@0: $db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE); indvdum@0: break; indvdum@0: indvdum@0: default: indvdum@0: $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE); indvdum@0: $db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE); indvdum@0: $db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); indvdum@0: break; indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Returns true if both FULLTEXT indexes exist indvdum@0: */ indvdum@0: function index_created() indvdum@0: { indvdum@0: if (!sizeof($this->stats)) indvdum@0: { indvdum@0: $this->get_stats(); indvdum@0: } indvdum@0: indvdum@0: return ($this->stats['total_words'] && $this->stats['total_matches']) ? true : false; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Returns an associative array containing information about the indexes indvdum@0: */ indvdum@0: function index_stats() indvdum@0: { indvdum@0: global $user; indvdum@0: indvdum@0: if (!sizeof($this->stats)) indvdum@0: { indvdum@0: $this->get_stats(); indvdum@0: } indvdum@0: indvdum@0: return array( indvdum@0: $user->lang['TOTAL_WORDS'] => $this->stats['total_words'], indvdum@0: $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); indvdum@0: } indvdum@0: indvdum@0: function get_stats() indvdum@0: { indvdum@0: global $db; indvdum@0: indvdum@0: $sql = 'SELECT COUNT(*) as total_words indvdum@0: FROM ' . SEARCH_WORDLIST_TABLE; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $this->stats['total_words'] = (int) $db->sql_fetchfield('total_words'); indvdum@0: $db->sql_freeresult($result); indvdum@0: indvdum@0: $sql = 'SELECT COUNT(*) as total_matches indvdum@0: FROM ' . SEARCH_WORDMATCH_TABLE; indvdum@0: $result = $db->sql_query($sql); indvdum@0: $this->stats['total_matches'] = (int) $db->sql_fetchfield('total_matches'); indvdum@0: $db->sql_freeresult($result); indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Clean up a text to remove non-alphanumeric characters indvdum@0: * indvdum@0: * This method receives a UTF-8 string, normalizes and validates it, replaces all indvdum@0: * non-alphanumeric characters with strings then returns the result. indvdum@0: * indvdum@0: * Any number of "allowed chars" can be passed as a UTF-8 string in NFC. indvdum@0: * indvdum@0: * @param string $text Text to split, in UTF-8 (not normalized or sanitized) indvdum@0: * @param string $allowed_chars String of special chars to allow indvdum@0: * @param string $encoding Text encoding indvdum@0: * @return string Cleaned up text, only alphanumeric chars are left indvdum@0: * indvdum@0: * @todo normalizer::cleanup being able to be used? indvdum@0: */ indvdum@0: function cleanup($text, $allowed_chars = null, $encoding = 'utf-8') indvdum@0: { indvdum@0: global $phpbb_root_path, $phpEx; indvdum@0: static $conv = array(), $conv_loaded = array(); indvdum@0: $words = $allow = array(); indvdum@0: indvdum@0: // Convert the text to UTF-8 indvdum@0: $encoding = strtolower($encoding); indvdum@0: if ($encoding != 'utf-8') indvdum@0: { indvdum@0: $text = utf8_recode($text, $encoding); indvdum@0: } indvdum@0: indvdum@0: $utf_len_mask = array( indvdum@0: "\xC0" => 2, indvdum@0: "\xD0" => 2, indvdum@0: "\xE0" => 3, indvdum@0: "\xF0" => 4 indvdum@0: ); indvdum@0: indvdum@0: /** indvdum@0: * Replace HTML entities and NCRs indvdum@0: */ indvdum@0: $text = htmlspecialchars_decode(utf8_decode_ncr($text), ENT_QUOTES); indvdum@0: indvdum@0: /** indvdum@0: * Load the UTF-8 normalizer indvdum@0: * indvdum@0: * If we use it more widely, an instance of that class should be held in a indvdum@0: * a global variable instead indvdum@0: */ indvdum@0: utf_normalizer::nfc($text); indvdum@0: indvdum@0: /** indvdum@0: * The first thing we do is: indvdum@0: * indvdum@0: * - convert ASCII-7 letters to lowercase indvdum@0: * - remove the ASCII-7 non-alpha characters indvdum@0: * - remove the bytes that should not appear in a valid UTF-8 string: 0xC0, indvdum@0: * 0xC1 and 0xF5-0xFF indvdum@0: * indvdum@0: * @todo in theory, the third one is already taken care of during normalization and those chars should have been replaced by Unicode replacement chars indvdum@0: */ indvdum@0: $sb_match = "ISTCPAMELRDOJBNHFGVWUQKYXZ\r\n\t!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\xC0\xC1\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"; indvdum@0: $sb_replace = 'istcpamelrdojbnhfgvwuqkyxz '; indvdum@0: indvdum@0: /** indvdum@0: * This is the list of legal ASCII chars, it is automatically extended indvdum@0: * with ASCII chars from $allowed_chars indvdum@0: */ indvdum@0: $legal_ascii = ' eaisntroludcpmghbfvq10xy2j9kw354867z'; indvdum@0: indvdum@0: /** indvdum@0: * Prepare an array containing the extra chars to allow indvdum@0: */ indvdum@0: if (isset($allowed_chars[0])) indvdum@0: { indvdum@0: $pos = 0; indvdum@0: $len = strlen($allowed_chars); indvdum@0: do indvdum@0: { indvdum@0: $c = $allowed_chars[$pos]; indvdum@0: indvdum@0: if ($c < "\x80") indvdum@0: { indvdum@0: /** indvdum@0: * ASCII char indvdum@0: */ indvdum@0: $sb_pos = strpos($sb_match, $c); indvdum@0: if (is_int($sb_pos)) indvdum@0: { indvdum@0: /** indvdum@0: * Remove the char from $sb_match and its corresponding indvdum@0: * replacement in $sb_replace indvdum@0: */ indvdum@0: $sb_match = substr($sb_match, 0, $sb_pos) . substr($sb_match, $sb_pos + 1); indvdum@0: $sb_replace = substr($sb_replace, 0, $sb_pos) . substr($sb_replace, $sb_pos + 1); indvdum@0: $legal_ascii .= $c; indvdum@0: } indvdum@0: indvdum@0: ++$pos; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: /** indvdum@0: * UTF-8 char indvdum@0: */ indvdum@0: $utf_len = $utf_len_mask[$c & "\xF0"]; indvdum@0: $allow[substr($allowed_chars, $pos, $utf_len)] = 1; indvdum@0: $pos += $utf_len; indvdum@0: } indvdum@0: } indvdum@0: while ($pos < $len); indvdum@0: } indvdum@0: indvdum@0: $text = strtr($text, $sb_match, $sb_replace); indvdum@0: $ret = ''; indvdum@0: indvdum@0: $pos = 0; indvdum@0: $len = strlen($text); indvdum@0: indvdum@0: do indvdum@0: { indvdum@0: /** indvdum@0: * Do all consecutive ASCII chars at once indvdum@0: */ indvdum@0: if ($spn = strspn($text, $legal_ascii, $pos)) indvdum@0: { indvdum@0: $ret .= substr($text, $pos, $spn); indvdum@0: $pos += $spn; indvdum@0: } indvdum@0: indvdum@0: if ($pos >= $len) indvdum@0: { indvdum@0: return $ret; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Capture the UTF char indvdum@0: */ indvdum@0: $utf_len = $utf_len_mask[$text[$pos] & "\xF0"]; indvdum@0: $utf_char = substr($text, $pos, $utf_len); indvdum@0: $pos += $utf_len; indvdum@0: indvdum@0: if (($utf_char >= UTF8_HANGUL_FIRST && $utf_char <= UTF8_HANGUL_LAST) indvdum@0: || ($utf_char >= UTF8_CJK_FIRST && $utf_char <= UTF8_CJK_LAST) indvdum@0: || ($utf_char >= UTF8_CJK_B_FIRST && $utf_char <= UTF8_CJK_B_LAST)) indvdum@0: { indvdum@0: /** indvdum@0: * All characters within these ranges are valid indvdum@0: * indvdum@0: * We separate them with a space in order to index each character indvdum@0: * individually indvdum@0: */ indvdum@0: $ret .= ' ' . $utf_char . ' '; indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: if (isset($allow[$utf_char])) indvdum@0: { indvdum@0: /** indvdum@0: * The char is explicitly allowed indvdum@0: */ indvdum@0: $ret .= $utf_char; indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: if (isset($conv[$utf_char])) indvdum@0: { indvdum@0: /** indvdum@0: * The char is mapped to something, maybe to itself actually indvdum@0: */ indvdum@0: $ret .= $conv[$utf_char]; indvdum@0: continue; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * The char isn't mapped, but did we load its conversion table? indvdum@0: * indvdum@0: * The search indexer table is split into blocks. The block number of indvdum@0: * each char is equal to its codepoint right-shifted for 11 bits. It indvdum@0: * means that out of the 11, 16 or 21 meaningful bits of a 2-, 3- or indvdum@0: * 4- byte sequence we only keep the leftmost 0, 5 or 10 bits. Thus, indvdum@0: * all UTF chars encoded in 2 bytes are in the same first block. indvdum@0: */ indvdum@0: if (isset($utf_char[2])) indvdum@0: { indvdum@0: if (isset($utf_char[3])) indvdum@0: { indvdum@0: /** indvdum@0: * 1111 0nnn 10nn nnnn 10nx xxxx 10xx xxxx indvdum@0: * 0000 0111 0011 1111 0010 0000 indvdum@0: */ indvdum@0: $idx = ((ord($utf_char[0]) & 0x07) << 7) | ((ord($utf_char[1]) & 0x3F) << 1) | ((ord($utf_char[2]) & 0x20) >> 5); indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: /** indvdum@0: * 1110 nnnn 10nx xxxx 10xx xxxx indvdum@0: * 0000 0111 0010 0000 indvdum@0: */ indvdum@0: $idx = ((ord($utf_char[0]) & 0x07) << 1) | ((ord($utf_char[1]) & 0x20) >> 5); indvdum@0: } indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: /** indvdum@0: * 110x xxxx 10xx xxxx indvdum@0: * 0000 0000 0000 0000 indvdum@0: */ indvdum@0: $idx = 0; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Check if the required conv table has been loaded already indvdum@0: */ indvdum@0: if (!isset($conv_loaded[$idx])) indvdum@0: { indvdum@0: $conv_loaded[$idx] = 1; indvdum@0: $file = $phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $phpEx; indvdum@0: indvdum@0: if (file_exists($file)) indvdum@0: { indvdum@0: $conv += include($file); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: if (isset($conv[$utf_char])) indvdum@0: { indvdum@0: $ret .= $conv[$utf_char]; indvdum@0: } indvdum@0: else indvdum@0: { indvdum@0: /** indvdum@0: * We add an entry to the conversion table so that we indvdum@0: * don't have to convert to codepoint and perform the checks indvdum@0: * that are above this block indvdum@0: */ indvdum@0: $conv[$utf_char] = ' '; indvdum@0: $ret .= ' '; indvdum@0: } indvdum@0: } indvdum@0: while (1); indvdum@0: indvdum@0: return $ret; indvdum@0: } indvdum@0: indvdum@0: /** indvdum@0: * Returns a list of options for the ACP to display indvdum@0: */ indvdum@0: function acp() indvdum@0: { indvdum@0: global $user, $config; indvdum@0: indvdum@0: indvdum@0: /** indvdum@0: * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed indvdum@0: */ indvdum@0: indvdum@0: $tpl = ' indvdum@0:
indvdum@0:

' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
indvdum@0:
indvdum@0:
indvdum@0:
indvdum@0:

' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
indvdum@0:
indvdum@0:
indvdum@0:
indvdum@0:

' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
indvdum@0:
indvdum@0:
indvdum@0:
indvdum@0:

' . $user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
indvdum@0:
%
indvdum@0:
indvdum@0: '; indvdum@0: indvdum@0: // These are fields required in the config table indvdum@0: return array( indvdum@0: 'tpl' => $tpl, indvdum@0: 'config' => array('fulltext_native_load_upd' => 'bool', 'fulltext_native_min_chars' => 'integer:0:255', 'fulltext_native_max_chars' => 'integer:0:255', 'fulltext_native_common_thres' => 'double:0:100') indvdum@0: ); indvdum@0: } indvdum@0: } indvdum@0: indvdum@0: ?>