<commit_before><?php

require_once 'Site/SiteFulltextSearchEngine.php';
require_once 'Site/SiteNateGoFulltextSearchResult.php';
require_once 'NateGoSearch/NateGoSearchQuery.php';
require_once 'NateGoSearch/NateGoSearchPSpellSpellChecker.php';

/**
 * A fulltext search engine that uses NateGoSearch
 *
 * @package   Site
 * @copyright 2007 silverorange
 */
class SiteNateGoFulltextSearchEngine extends SwatObject
	implements SiteFulltextSearchEngine
{
	// {{{ protected properties

	/**
	 * The database
	 *
	 * @var MDB2_Driver_Common
	 */
	protected $db;

	/**
	 * The locale to use for spell checking
	 *
	 * @var string
	 */
	protected $locale;

	/**
	 * The document types to search
	 *
	 * @var array
	 */
	protected $types = array();

	// }}}
	// {{{ public function __construct()

	/**
	 * Creates a new nate-go fulltext search engine
	 *
	 * @param MDB2_Driver_Common $db
	 * @param string $locale optional.
	 */
	public function __construct($db, $locale = null)
	{
		$this->db = $db;
		if ($locale === null) {
			$this->locale = setlocale(LC_ALL, '0');
		} else {
			$this->locale = $locale;
		}
	}

	// }}}
	// {{{ public function setTypes()

	/**
	 * Sets the document types to search
	 *
	 * @param array $types
	 */
	public function setTypes($types)
	{
		// TODO: if $types is not array throw an exception
		$this->types = $types;
	}

	// }}}
	// {{{ public function search()

	/**
	 * Perform a fulltext search and return the result
	 *
	 * @param string $keywords the keywords to search with.
	 *
	 * @return SiteFulltextSearchResult
	 */
	public function search($keywords)
	{
		$spell_checker = new NateGoSearchPSpellSpellChecker($this->locale);
		$spell_checker->setCustomWordList($this->getCustomWordList());
		$spell_checker->loadCustomContent();

		$query = new NateGoSearchQuery($this->db);
		$query->addBlockedWords(NateGoSearchQuery::getDefaultBlockedWords());
		$query->setSpellChecker($spell_checker);

		foreach ($this->types as $type)
			$query->addDocumentType($type);

		$result = $query->query($keywords);

		return new SiteNateGoFulltextSearchResult($this->db, $result);
	}

	// }}}
	// {{{ protected function getCustomWordList()

	/**
	 * Get the custom word list
	 *
	 * Get the custom word list that is used by this fulltext search engine.
	 *
	 * @return string the path to the custom word list
	 */
	protected function getCustomWordList()
	{
		return './../system/search/custom-wordlist.pws';
	}

	// }}}
}

?>
<commit_msg>Preemptively prevent client relations disaster.<commit_after><?php

require_once 'Site/SiteFulltextSearchEngine.php';
require_once 'Site/SiteNateGoFulltextSearchResult.php';
require_once 'NateGoSearch/NateGoSearchQuery.php';
require_once 'NateGoSearch/NateGoSearchPSpellSpellChecker.php';

/**
 * A fulltext search engine that uses NateGoSearch
 *
 * @package   Site
 * @copyright 2007 silverorange
 */
class SiteNateGoFulltextSearchEngine extends SwatObject
	implements SiteFulltextSearchEngine
{
	// {{{ protected properties

	/**
	 * The database
	 *
	 * @var MDB2_Driver_Common
	 */
	protected $db;

	/**
	 * The locale to use for spell checking
	 *
	 * @var string
	 */
	protected $locale;

	/**
	 * The document types to search
	 *
	 * @var array
	 */
	protected $types = array();

	// }}}
	// {{{ public function __construct()

	/**
	 * Creates a new nate-go fulltext search engine
	 *
	 * @param MDB2_Driver_Common $db
	 * @param string $locale optional.
	 */
	public function __construct($db, $locale = null)
	{
		$this->db = $db;
		if ($locale === null) {
			$this->locale = setlocale(LC_ALL, '0');
		} else {
			$this->locale = $locale;
		}
	}

	// }}}
	// {{{ public function setTypes()

	/**
	 * Sets the document types to search
	 *
	 * @param array $types
	 */
	public function setTypes($types)
	{
		// TODO: if $types is not array throw an exception
		$this->types = $types;
	}

	// }}}
	// {{{ public function search()

	/**
	 * Perform a fulltext search and return the result
	 *
	 * @param string $keywords the keywords to search with.
	 *
	 * @return SiteFulltextSearchResult
	 */
	public function search($keywords)
	{
		$spell_checker = new NateGoSearchPSpellSpellChecker($this->locale);
		$spell_checker->setCustomWordList($this->getCustomWordList());
		$spell_checker->loadCustomContent();

		$query = new NateGoSearchQuery($this->db);
		$query->addBlockedWords(NateGoSearchQuery::getDefaultBlockedWords());
// TODO: add this back when we filter out bad words. Mike 2008-12-15.
// Ticket #3949.
//		$query->setSpellChecker($spell_checker);

		foreach ($this->types as $type)
			$query->addDocumentType($type);

		$result = $query->query($keywords);

		return new SiteNateGoFulltextSearchResult($this->db, $result);
	}

	// }}}
	// {{{ protected function getCustomWordList()

	/**
	 * Get the custom word list
	 *
	 * Get the custom word list that is used by this fulltext search engine.
	 *
	 * @return string the path to the custom word list
	 */
	protected function getCustomWordList()
	{
		return './../system/search/custom-wordlist.pws';
	}

	// }}}
}

?>

{'fraction_non_alphanumeric': 0.13801308744794766, 'fraction_numerical': 0.005155661312710688, 'mean_word_length': 3.640294388224471, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3091125', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1601, 'n_words': 408}