Commit 06b3ae3a02686a5cba88a6c769220fc571ffe011
1 parent
dc186a75
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
Showing
2 changed files
with
36 additions
and
9 deletions
search2/search/SearchCommandLexer.php
| @@ -95,6 +95,9 @@ class SearchCommandLexer | @@ -95,6 +95,9 @@ class SearchCommandLexer | ||
| 95 | $append=false; | 95 | $append=false; |
| 96 | $clear=true; | 96 | $clear=true; |
| 97 | break; | 97 | break; |
| 98 | + case '~': | ||
| 99 | + $this->token=SearchCommandParser::TILDE; | ||
| 100 | + break; | ||
| 98 | case '=': | 101 | case '=': |
| 99 | $this->token=SearchCommandParser::IS; | 102 | $this->token=SearchCommandParser::IS; |
| 100 | break; | 103 | break; |
| @@ -136,8 +139,8 @@ class SearchCommandLexer | @@ -136,8 +139,8 @@ class SearchCommandLexer | ||
| 136 | } | 139 | } |
| 137 | elseif ($this->lookahead == '=') | 140 | elseif ($this->lookahead == '=') |
| 138 | { | 141 | { |
| 139 | - $this->zap(); | ||
| 140 | $this->token=($this->char == '<')?(SearchCommandParser::LE):(SearchCommandParser::GE); | 142 | $this->token=($this->char == '<')?(SearchCommandParser::LE):(SearchCommandParser::GE); |
| 143 | + $this->zap(); | ||
| 141 | } | 144 | } |
| 142 | else | 145 | else |
| 143 | { | 146 | { |
| @@ -223,6 +226,9 @@ class SearchCommandLexer | @@ -223,6 +226,9 @@ class SearchCommandLexer | ||
| 223 | { | 226 | { |
| 224 | switch($this->char) | 227 | switch($this->char) |
| 225 | { | 228 | { |
| 229 | + case '"': | ||
| 230 | + $this->value .= '"'; | ||
| 231 | + break; | ||
| 226 | case 'r': | 232 | case 'r': |
| 227 | $this->value .= "\r"; | 233 | $this->value .= "\r"; |
| 228 | break; | 234 | break; |
search2/search/expr.inc.php
| @@ -390,13 +390,14 @@ class FieldExpr extends Expr | @@ -390,13 +390,14 @@ class FieldExpr extends Expr | ||
| 390 | $value = $right; | 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 | else | 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,19 +542,26 @@ class ValueExpr extends Expr | ||
| 541 | */ | 542 | */ |
| 542 | protected $value; | 543 | protected $value; |
| 543 | 544 | ||
| 545 | + protected $fuzzy; | ||
| 546 | + | ||
| 547 | + protected $proximity; | ||
| 548 | + | ||
| 544 | /** | 549 | /** |
| 545 | * Constructor for the value expression | 550 | * Constructor for the value expression |
| 546 | * | 551 | * |
| 547 | * @param mixed $value | 552 | * @param mixed $value |
| 548 | */ | 553 | */ |
| 549 | - public function __construct($value) | 554 | + public function __construct($value, $fuzzy=null, $proximity=null) |
| 550 | { | 555 | { |
| 551 | parent::__construct(); | 556 | parent::__construct(); |
| 552 | $this->value=$value; | 557 | $this->value=$value; |
| 558 | + $this->fuzzy = $fuzzy; | ||
| 559 | + $this->proximity = $proximity; | ||
| 553 | } | 560 | } |
| 554 | 561 | ||
| 555 | public function getValue() | 562 | public function getValue() |
| 556 | { | 563 | { |
| 564 | + | ||
| 557 | return $this->value; | 565 | return $this->value; |
| 558 | } | 566 | } |
| 559 | 567 | ||
| @@ -851,7 +859,14 @@ class TextQueryBuilder implements QueryBuilder | @@ -851,7 +859,14 @@ class TextQueryBuilder implements QueryBuilder | ||
| 851 | 859 | ||
| 852 | $not = $expr->not()?' NOT ':''; | 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 | return $query; | 872 | return $query; |
| @@ -875,7 +890,10 @@ class TextQueryBuilder implements QueryBuilder | @@ -875,7 +890,10 @@ class TextQueryBuilder implements QueryBuilder | ||
| 875 | 890 | ||
| 876 | $not = $expr->not()?' NOT ':''; | 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 | return $query; | 899 | return $query; |
| @@ -1931,7 +1949,8 @@ class OpExpr extends Expr | @@ -1931,7 +1949,8 @@ class OpExpr extends Expr | ||
| 1931 | 1949 | ||
| 1932 | $results = array(); | 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 | $rs = DBUtil::getResultArray($sql); | 1954 | $rs = DBUtil::getResultArray($sql); |
| 1936 | 1955 | ||
| 1937 | if (PEAR::isError($rs)) | 1956 | if (PEAR::isError($rs)) |
| @@ -1969,7 +1988,9 @@ class OpExpr extends Expr | @@ -1969,7 +1988,9 @@ class OpExpr extends Expr | ||
| 1969 | } | 1988 | } |
| 1970 | 1989 | ||
| 1971 | $indexer = Indexer::get(); | 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 | $results = $indexer->query($query); | 1994 | $results = $indexer->query($query); |
| 1974 | foreach($results as $item) | 1995 | foreach($results as $item) |
| 1975 | { | 1996 | { |