diff --git a/.gitignore b/.gitignore index f95b1a4b7e..631bd2629f 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,7 @@ behat.yml # Exclude crossdomain.xml file it's generated /www/crossdomain.xml + +# Exclude jison files +grammar/query.js +grammar/jison-* diff --git a/build_query_parser.sh b/build_query_parser.sh old mode 100644 new mode 100755 index 8d6a673873..406954df55 --- a/build_query_parser.sh +++ b/build_query_parser.sh @@ -1,4 +1,19 @@ #!/bin/sh + +jison_version="master"; +jison_php="jison-$jison_version/ports/php/php.js" + cd grammar -node jison/ports/php/php.js query.jison -mv QueryParser.php ../lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php \ No newline at end of file + +if [ -f $jison_php ]; +then + echo "Skip jison download" +else + echo "Download jison lib" + wget https://github.com/zaach/jison/archive/$jison_version.zip + unzip $jison_version.zip + rm $jison_version.zip +fi + +node jison-$jison_version/ports/php/php.js query.jison +mv QueryParser.php ../lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/KeywordNode.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/KeywordNode.php index 3b42f719d2..a11a117754 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/KeywordNode.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/AST/KeywordNode.php @@ -18,7 +18,7 @@ class KeywordNode extends Node public function getQuery() { - throw new LogicException("A keyword can't be converted to a query."); + throw new \LogicException("A keyword can't be converted to a query."); } public function __toString() diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index a06ffbf235..6edcded230 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -276,6 +276,8 @@ class ElasticSearchEngine implements SearchEngineInterface { $parser = new QueryParser(); $ast = $parser->parse($string); + + $userQuery = $ast->getQuery(); $params = $this->createQueryParams($userQuery, $options ?: new SearchEngineOptions()); diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php index c48e977ef5..aabea5763d 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/QueryParser.php @@ -446,12 +446,14 @@ class QueryParser switch ($yystate) { case 1: + return $thisS; break; case 2: + // $thisS = sprintf('(%s DEF_OP %s)', $s[$o-1]->text, $s[$o]->text); $thisS = new AST\AndExpression($s[$o-1]->text, $s[$o]->text); @@ -459,40 +461,48 @@ case 2: break; case 4: + $thisS = new AST\AndExpression($s[$o-2]->text, $s[$o]->text); break; case 5: + $thisS = new AST\OrExpression($s[$o-2]->text, $s[$o]->text); break; case 6: + $thisS = new AST\InExpression($s[$o]->text, $s[$o-2]->text); break; case 7: + $thisS = $s[$o-1]; break; case 10: + $thisS = new AST\KeywordNode($s[$o]->text); break; case 11: + $thisS = new AST\PrefixNode($s[$o-1]->text); break; case 12: + $thisS = new AST\TextNode($s[$o]->text); break; case 13: + $thisS = new AST\QuotedTextNode($s[$o]->text); break; @@ -811,7 +821,7 @@ break; } } } - if ( isset($match) && $match ) { + if ( $match ) { $matchCount = strlen($match[0]); $lineCount = preg_match("/(?:\r\n?|\n).*/", $match[0], $lines); $line = ($lines ? $lines[$lineCount - 1] : false); @@ -897,7 +907,6 @@ break; function LexerPerformAction($avoidingNameCollisions, $YY_START = null) { - ; switch($avoidingNameCollisions) { case 0:/* skip whitespace */ @@ -1120,4 +1129,4 @@ class ParserRange $this->x = $x; $this->y = $y; } -} +} \ No newline at end of file