Commit 62e8fbf0e598aa7e5d23c81c9398086682d4c164

Authored by conradverm
1 parent c2582289

KTS-2400

"Using double quotes in the new search system may be problematic"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8023 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/search/SearchCommandLexer.php
... ... @@ -95,6 +95,9 @@ class SearchCommandLexer
95 95 $append=false;
96 96 $clear=true;
97 97 break;
  98 + case '~':
  99 + $this->token=SearchCommandParser::TILDE;
  100 + break;
98 101 case '=':
99 102 $this->token=SearchCommandParser::IS;
100 103 break;
... ... @@ -136,8 +139,8 @@ class SearchCommandLexer
136 139 }
137 140 elseif ($this->lookahead == '=')
138 141 {
139   - $this->zap();
140 142 $this->token=($this->char == '<')?(SearchCommandParser::LE):(SearchCommandParser::GE);
  143 + $this->zap();
141 144 }
142 145 else
143 146 {
... ... @@ -223,6 +226,9 @@ class SearchCommandLexer
223 226 {
224 227 switch($this->char)
225 228 {
  229 + case '"':
  230 + $this->value .= '"';
  231 + break;
226 232 case 'r':
227 233 $this->value .= "\r";
228 234 break;
... ...
search2/search/expr.inc.php
... ... @@ -390,13 +390,14 @@ class FieldExpr extends Expr
390 390 $value = $right;
391 391 }
392 392  
393   - if (substr($value,0,1) != '\'' || substr($value,-1) != '\'')
  393 + if ((substr($value,0,1) == '\'' && substr($value,-1) == '\'') || (substr($value,0,1) == '"' && substr($value,-1) == '"'))
394 394 {
395   - OpExpr::rewriteString($left, $op, $right, $not);
  395 + $value = trim( substr($value,1,-1) );
  396 + $right = new ValueExpr($value);
396 397 }
397 398 else
398 399 {
399   - $right = new ValueExpr(trim(substr($value,1,-1)));
  400 + OpExpr::rewriteString($left, $op, $right, $not);
400 401 }
401 402 }
402 403 }
... ... @@ -541,19 +542,26 @@ class ValueExpr extends Expr
541 542 */
542 543 protected $value;
543 544  
  545 + protected $fuzzy;
  546 +
  547 + protected $proximity;
  548 +
544 549 /**
545 550 * Constructor for the value expression
546 551 *
547 552 * @param mixed $value
548 553 */
549   - public function __construct($value)
  554 + public function __construct($value, $fuzzy=null, $proximity=null)
550 555 {
551 556 parent::__construct();
552 557 $this->value=$value;
  558 + $this->fuzzy = $fuzzy;
  559 + $this->proximity = $proximity;
553 560 }
554 561  
555 562 public function getValue()
556 563 {
  564 +
557 565 return $this->value;
558 566 }
559 567  
... ... @@ -851,7 +859,14 @@ class TextQueryBuilder implements QueryBuilder
851 859  
852 860 $not = $expr->not()?' NOT ':'';
853 861  
854   - $query = "$not$fieldname: \"$value\"";
  862 + if (strpos($value, ' ') === false)
  863 + {
  864 + $query = "$not$fieldname: $value";
  865 + }
  866 + else
  867 + {
  868 + $query = "$not$fieldname: \"$value\"";
  869 + }
855 870 }
856 871  
857 872 return $query;
... ... @@ -875,7 +890,10 @@ class TextQueryBuilder implements QueryBuilder
875 890  
876 891 $not = $expr->not()?' NOT ':'';
877 892  
878   - $query .= "$not$fieldname: \"$value\"";
  893 + if (strpos($value, ' ') !== false)
  894 + $query .= "$not$fieldname: \"$value\"";
  895 + else
  896 + $query .= "$not$fieldname: $value";
879 897 }
880 898  
881 899 return $query;
... ... @@ -1931,7 +1949,8 @@ class OpExpr extends Expr
1931 1949  
1932 1950 $results = array();
1933 1951  
1934   - if ($this->debug) print "\n\n$sql\n\n";
  1952 + global $default;
  1953 + $default->log->debug("SEARCH SQL: $sql");
1935 1954 $rs = DBUtil::getResultArray($sql);
1936 1955  
1937 1956 if (PEAR::isError($rs))
... ... @@ -1969,7 +1988,9 @@ class OpExpr extends Expr
1969 1988 }
1970 1989  
1971 1990 $indexer = Indexer::get();
1972   - if ($this->debug) print "\n\n$query\n\n";
  1991 + global $default;
  1992 + $default->log->debug("SEARCH LUCENE: $query");
  1993 +
1973 1994 $results = $indexer->query($query);
1974 1995 foreach($results as $item)
1975 1996 {
... ...