Blame Extras/phpBB/3.0.4/includes/search/fulltext_native.php

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