$this->db = $db;
}
- /** @todo document */
+ /**
+ * Parse the user's query and transform it into an SQL fragment which will
+ * become part of a WHERE clause
+ */
function parseQuery( $filteredText, $fulltext ) {
global $wgContLang;
$lc = SearchEngine::legalSearchChars(); // Minus format chars
if( $this->strictMatching && ($terms[1] == '') ) {
$terms[1] = '+';
}
- $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
+ // Search terms in all variant forms, only
+ // apply on wiki with LanguageConverter
+ $temp_terms = $wgContLang->autoConvertToAllVariants( $terms[2] );
+ if( is_array( $temp_terms )) {
+ $temp_terms = array_unique( array_values( $temp_terms ));
+ foreach( $temp_terms as $t )
+ $searchon .= $terms[1] . $wgContLang->stripForSearch( $t ) . ' ';
+ }
+ else
+ $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
if( !empty( $terms[3] ) ) {
// Match individual terms in result highlighting...
$regexp = preg_quote( $terms[3], '/' );
- if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
+ if( $terms[4] ) {
+ $regexp = "\b$regexp"; // foo*
+ } else {
+ $regexp = "\b$regexp\b";
+ }
} else {
// Match the quoted term in result highlighting...
$regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
/**
* Perform a full text search query and return a result set.
*
- * @param string $term - Raw search term
+ * @param $term String: raw search term
* @return MySQLSearchResultSet
- * @access public
*/
function searchText( $term ) {
$resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
/**
* Perform a title-only search query and return a result set.
*
- * @param string $term - Raw search term
+ * @param $term String: raw search term
* @return MySQLSearchResultSet
- * @access public
*/
function searchTitle( $term ) {
$resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
/**
* Return a partial WHERE clause to exclude redirects, if so set
- * @return string
- * @private
+ * @return String
*/
function queryRedirect() {
if( $this->showRedirects ) {
/**
* Return a partial WHERE clause to limit the search to the given namespaces
- * @return string
- * @private
+ * @return String
*/
function queryNamespaces() {
if( is_null($this->namespaces) )
return ''; # search all
- $namespaces = implode( ',', $this->namespaces );
- if ($namespaces == '') {
+ if ( !count( $this->namespaces ) ) {
$namespaces = '0';
+ } else {
+ $namespaces = $this->db->makeList( $this->namespaces );
}
return 'AND page_namespace IN (' . $namespaces . ')';
}
/**
* Return a LIMIT clause to limit results on the query.
- * @return string
- * @private
+ * @return String
*/
function queryLimit() {
return $this->db->limitResult( '', $this->limit, $this->offset );
/**
* Does not do anything for generic search engine
* subclasses may define this though
- * @return string
- * @private
+ * @return String
*/
function queryRanking( $filteredTerm, $fulltext ) {
return '';
/**
* Construct the full SQL query to do the search.
* The guts shoulds be constructed in queryMain()
- * @param string $filteredTerm
- * @param bool $fulltext
- * @private
+ * @param $filteredTerm String
+ * @param $fulltext Boolean
*/
function getQuery( $filteredTerm, $fulltext ) {
return $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
/**
* Picks which field to index on, depending on what type of query.
- * @param bool $fulltext
- * @return string
+ * @param $fulltext Boolean
+ * @return String
*/
function getIndexField( $fulltext ) {
return $fulltext ? 'si_text' : 'si_title';
* version; MySQL 3 and MySQL 4 have different capabilities
* in their fulltext search indexes.
*
- * @param string $filteredTerm
- * @param bool $fulltext
- * @return string
- * @private
+ * @param $filteredTerm String
+ * @param $fulltext Boolean
+ * @return String
*/
function queryMain( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
* Create or update the search index record for the given page.
* Title and text should be pre-processed.
*
- * @param int $id
- * @param string $title
- * @param string $text
+ * @param $id Integer
+ * @param $title String
+ * @param $text String
*/
function update( $id, $title, $text ) {
$dbw = wfGetDB( DB_MASTER );
* Update a search index record's title only.
* Title should be pre-processed.
*
- * @param int $id
- * @param string $title
+ * @param $id Integer
+ * @param $title String
*/
function updateTitle( $id, $title ) {
$dbw = wfGetDB( DB_MASTER );
function free() {
$this->mResultSet->free();
}
-}
+}
\ No newline at end of file