From b835cf7a41f0fdef472ef4e88c4f450b036b9818 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Thu, 22 Feb 2007 17:35:44 +0000 Subject: [PATCH] Properly handle search operators "+" and "-", thanks cedric.villemain@gmail.com Fixes bug #8958 --- includes/SearchPostgres.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/SearchPostgres.php b/includes/SearchPostgres.php index d4fae150c4..fd1be48214 100644 --- a/includes/SearchPostgres.php +++ b/includes/SearchPostgres.php @@ -1,5 +1,5 @@ +# Copyright (C) 2006-2007 Greg Sabino Mullane # http://www.mediawiki.org/ # # This program is free software; you can redistribute it and/or modify @@ -55,6 +55,7 @@ class SearchPostgres extends SearchEngine { global $wgContLang; $lc = SearchEngine::legalSearchChars(); $searchon = ''; + $searchonst = ''; $this->searchTerms = array(); # FIXME: This doesn't handle parenthetical expressions. @@ -62,11 +63,16 @@ class SearchPostgres extends SearchEngine { if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER ) ) { foreach( $m as $terms ) { - if( $searchon !== '' ) $searchon .= ' '; - if($terms[1] == '') { - $terms[1] = '+'; - } - $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] ); + switch ($terms[1]) { + case '~': // negate but do not exclude like "-" for now, simply negate + case '-': $searchconst.= '&!' . $wgContLang->stripForSearch( $terms[2] ); + break; + case '+': $searchconst.= '&' . $wgContLang->stripForSearch( $terms[2] ); + break; + case '<': // decrease priority of word - not implemented + case '>': // increase priority of word - not implemented + default : $searchon.= '|' . $wgContLang->stripForSearch( $terms[2] ); + } if( !empty( $terms[3] ) ) { $regexp = preg_quote( $terms[3], '/' ); if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+"; @@ -81,7 +87,10 @@ class SearchPostgres extends SearchEngine { wfDebug( "Can't understand search query '{$this->filteredText}'\n" ); } - $searchon = preg_replace('/!/','\\!',$searchon); + if (substr_count($searchon,'|')==1) { + $searchon = str_replace ('|','&',$searchon); + } + $searchon = substr($searchconst . $searchon, 1) ; $searchon = preg_replace('/(\s+)/','&',$searchon); $searchon = $this->db->strencode( $searchon ); return $searchon; -- 2.20.1