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