word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']); $error = false; } /** * Splits keywords entered by a user into an array of words stored in $this->split_words * * @param string $keywords Contains the keyword as entered by the user * @param string $terms is either 'all' or 'any' * @return false if no valid keywords were found and otherwise true */ function split_keywords(&$keywords, $terms) { global $db, $config; /** * these functions are in /includes/search/search.php */ //$this->get_ignore_words(); //$this->get_synonyms(); $this->split_words = explode(' ', preg_replace('#\s+#', ' ', $keywords)); if (sizeof($this->ignore_words)) { $this->common_words = array_intersect($this->split_words, $this->ignore_words); $this->split_words = array_diff($this->split_words, $this->ignore_words); } if (sizeof($this->match_synonym)) { $this->split_words = str_replace($this->match_synonym, $this->replace_synonym, $this->split_words); } /** * remove words which are too long/short */ /** * identify common words and ignore them (add to $this->common_words) */ if (sizeof($this->split_words)) { $this->split_words = array_values($this->split_words); sort($this->split_words); return true; } return false; } /** * Returns any array of string lengths for the given array of strings * It counts multibyte entities as single characters and ignores "*" * * @param array $words an array of strings * * @return Array of string lengths */ function get_word_lengths($words) { return array_map('strlen', str_replace('*', '', preg_replace('#&\#[0-9]+;#', 'x', $words))); } /** * Turns text into an array of words that can be stored in the word list table */ function split_message($text) { global $config; /** * these functions are in /includes/search/search.php */ //$this->get_ignore_words(); //$this->get_synonyms(); $match = array(); // Comments for hardcoded bbcode elements (urls, smilies) $match[] = '#(.*?)#is'; // NCRs like etc. $match[] = '#(&|&)[a-z0-9]+;#i'; // Do not index code $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is'; // BBcode $match[] = '#\[\/?[a-z\*\+\-]+(?:=.*?)?(\:?[0-9a-z]{5,})\]#'; $text = preg_replace($match, ' ', $text); // Split words $text = explode(' ', preg_replace('#\s+#', ' ', $text)); if (sizeof($this->ignore_words)) { $text = array_diff($text, $this->ignore_words); } if (sizeof($this->match_synonym)) { $text = str_replace($this->match_synonym, $this->replace_synonym, $text); } /** * remove words which are too long/short */ return $text; } /** * Performs a search on keywords depending on display specific params. * * @param string $type contains either posts or topics depending on what should be searched for * @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) * @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) * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query * @param string $sort_key is the key of $sort_by_sql for the selected sorting * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @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 * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty * @param array $id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ 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, &$id_ary, $start, $per_page) { global $config, $db; // No keywords? No posts. if (!sizeof($this->split_words)) { return false; } if (!sizeof($id_ary)) { return false; } //$id_ary = $per_page ids return $total_results; } /** * Performs a search on an author's posts without caring about message contents. Depends on display specific params * * @param string $type contains either posts or topics depending on what should be searched for * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query * @param string $sort_key is the key of $sort_by_sql for the selected sorting * @param string $sort_dir is either a or d representing ASC and DESC * @param string $sort_days specifies the maximum amount of days a post may be old * @param array $ex_fid_ary specifies an array of forum ids which should not be searched * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts * @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 * @param array $author_ary an array of author ids * @param array $id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered * @param int $start indicates the first index of the page * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ function author_search($type, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; // No author? No posts. if (!sizeof($author_ary)) { return 0; } //$id_ary = $per_page ids return $total_results; } /** * Updates the index when a new post was added or a post is edited * * @param string $mode contains the post mode: edit, post, reply, quote ... */ function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { global $config, $db; // Is the fulltext indexer disabled? If yes then we need not // carry on ... it's okay ... I know when I'm not wanted boo hoo if (!$config['fulltext_native_load_upd']) { return; } // Split old and new post/subject to obtain array of 'words' $split_text = $this->split_message($message); $split_title = ($subject) ? $this->split_message($subject) : array(); /** * Create new forum word table if we don't have forum_id yet (we don't have a search engine function triggered on forum creation) */ /** * Update the index */ } /** * Removes entries from the index, forum_ids[x] and post_ids[x] belong together */ function index_remove($post_ids, $author_ids, $forum_ids) { global $db; } /** * Tidy up, remove common words */ function tidy() { global $db, $config; set_config('search_last_gc', time(), true); } /** * Deletes all words from the index */ function delete_index($acp_module, $u_action) { global $db; /** * drop all index tables */ } /** * Returns true if both FULLTEXT indexes exist */ function index_created() { /** * check whether all index tables exist */ } /** * Returns an associative array containing information about the indexes */ function index_stats() { global $user; if (!is_array($this->stats)) { $this->get_stats(); } return array( $user->lang['TOTAL_WORDS'] => $this->stats['total_words'], $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); } function get_stats() { global $db; /** * retrieve some stats */ $this->stats['total_words'] = (int) $db->sql_fetchfield('total_words'); $this->stats['total_matches'] = (int) $db->sql_fetchfield('total_matches'); } /** * Returns a list of options for the ACP to display */ function acp() { global $user, $config; /** * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed */ $tpl = '