Merge pull request #9598 from Sobuno/NewQueryParserV3

New Query Parser for Search Engine and Rules
This commit is contained in:
James Cole
2025-01-05 07:32:55 +01:00
committed by GitHub
21 changed files with 843 additions and 126 deletions

View File

@@ -89,16 +89,28 @@ class CreateController extends Controller
// build triggers from query, if present.
$query = (string) $request->get('from_query');
if ('' !== $query) {
$search = app(SearchInterface::class);
$search = app(SearchInterface::class);
$search->parseQuery($query);
$words = $search->getWordsAsString();
$operators = $search->getOperators()->toArray();
if ('' !== $words) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words]));
$operators[] = [
'type' => 'description_contains',
'value' => $words,
];
$words = $search->getWords();
$excludedWords = $search->getExcludedWords();
$operators = $search->getOperators()->toArray();
if (count($words) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
foreach($words as $word) {
$operators[] = [
'type' => 'description_contains',
'value' => $word,
];
}
}
if (count($excludedWords) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
foreach($excludedWords as $excludedWord) {
$operators[] = [
'type' => '-description_contains',
'value' => $excludedWord,
];
}
}
$oldTriggers = $this->parseFromOperators($operators);
}

View File

@@ -87,11 +87,26 @@ class EditController extends Controller
if ('' !== $query) {
$search = app(SearchInterface::class);
$search->parseQuery($query);
$words = $search->getWordsAsString();
$words = $search->getWords();
$excludedWords = $search->getExcludedWords();
$operators = $search->getOperators()->toArray();
if ('' !== $words) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words]));
$operators[] = ['type' => 'description_contains', 'value' => $words];
if (count($words) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $words)]));
foreach($words as $word) {
$operators[] = [
'type' => 'description_contains',
'value' => $word,
];
}
}
if (count($excludedWords) > 0) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => implode('', $excludedWords)]));
foreach($excludedWords as $excludedWord) {
$operators[] = [
'type' => '-description_contains',
'value' => $excludedWord,
];
}
}
$oldTriggers = $this->parseFromOperators($operators);
}

View File

@@ -83,12 +83,13 @@ class SearchController extends Controller
$searcher->parseQuery($fullQuery);
// words from query and operators:
$query = $searcher->getWordsAsString();
$words = $searcher->getWords();
$excludedWords = $searcher->getExcludedWords();
$operators = $searcher->getOperators();
$invalidOperators = $searcher->getInvalidOperators();
$subTitle = (string) trans('breadcrumbs.search_result', ['query' => $fullQuery]);
return view('search.index', compact('query', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged', 'invalidOperators'));
return view('search.index', compact('words', 'excludedWords', 'operators', 'page', 'rule', 'fullQuery', 'subTitle', 'ruleId', 'ruleChanged', 'invalidOperators'));
}
/**