mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Fix a few test cases.
This commit is contained in:
@@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use Gdbots\QueryParser\QueryParser as BaseQueryParser;
|
||||
use Gdbots\QueryParser\Node as GdbotsNode;
|
||||
use Gdbots\QueryParser\Enum\BoolOperator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GdbotsQueryParser implements QueryParserInterface
|
||||
{
|
||||
@@ -63,9 +64,10 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
|
||||
private function convertNode(GdbotsNode\Node $node): Node
|
||||
{
|
||||
|
||||
switch (true) {
|
||||
case $node instanceof GdbotsNode\Word:
|
||||
return new StringNode($node->getValue());
|
||||
return new StringNode($node->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
|
||||
case $node instanceof GdbotsNode\Field:
|
||||
return new FieldNode(
|
||||
@@ -75,6 +77,7 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
);
|
||||
|
||||
case $node instanceof GdbotsNode\Subquery:
|
||||
Log::debug('Subquery');
|
||||
return new NodeGroup(
|
||||
array_map(
|
||||
fn(GdbotsNode\Node $subNode) => $this->convertNode($subNode),
|
||||
@@ -90,7 +93,7 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
case $node instanceof GdbotsNode\Mention:
|
||||
case $node instanceof GdbotsNode\Emoticon:
|
||||
case $node instanceof GdbotsNode\Emoji:
|
||||
return new StringNode((string) $node->getValue());
|
||||
return new StringNode((string) $node->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
|
||||
default:
|
||||
throw new FireflyException(
|
||||
|
@@ -25,6 +25,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Base class for all nodes
|
||||
*/
|
||||
@@ -45,8 +47,10 @@ abstract class Node
|
||||
public function isProhibited(bool $flipFlag): bool
|
||||
{
|
||||
if ($flipFlag) {
|
||||
//Log::debug(sprintf('This %s is (flipped) now prohibited: %s',get_class($this), var_export(!$this->prohibited, true)));
|
||||
return !$this->prohibited;
|
||||
}
|
||||
//Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
|
||||
return $this->prohibited;
|
||||
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Represents a result from parsing a query node
|
||||
*
|
||||
@@ -36,8 +38,7 @@ class NodeResult
|
||||
public function __construct(
|
||||
public readonly ?Node $node,
|
||||
public readonly bool $isSubqueryEnd
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +55,7 @@ class QueryParser implements QueryParserInterface
|
||||
/** @return NodeGroup */
|
||||
public function parse(string $query): NodeGroup
|
||||
{
|
||||
Log::debug(sprintf('Parsing query in QueryParser: "%s"', $query));
|
||||
$this->query = $query;
|
||||
$this->position = 0;
|
||||
return $this->buildNodeGroup(false);
|
||||
@@ -93,6 +95,7 @@ class QueryParser implements QueryParserInterface
|
||||
$this->position++;
|
||||
continue;
|
||||
}
|
||||
// char is "
|
||||
$this->position++;
|
||||
return new NodeResult(
|
||||
$this->createNode($tokenUnderConstruction, $fieldName, $prohibited),
|
||||
@@ -104,6 +107,7 @@ class QueryParser implements QueryParserInterface
|
||||
case '-':
|
||||
if ($tokenUnderConstruction === '') {
|
||||
// A minus sign at the beginning of a token indicates prohibition
|
||||
Log::debug('Indicate prohibition');
|
||||
$prohibited = true;
|
||||
}
|
||||
if ($tokenUnderConstruction !== '') {
|
||||
@@ -192,8 +196,10 @@ class QueryParser implements QueryParserInterface
|
||||
private function createNode(string $token, string $fieldName, bool $prohibited): Node
|
||||
{
|
||||
if (strlen($fieldName) > 0) {
|
||||
Log::debug(sprintf('Create FieldNode %s:%s (%s)', $fieldName, $token, var_export($prohibited, true)));
|
||||
return new FieldNode(trim($fieldName), trim($token), $prohibited);
|
||||
}
|
||||
Log::debug(sprintf('Create StringNode "%s" (%s)', $token, var_export($prohibited, true)));
|
||||
return new StringNode(trim($token), $prohibited);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user