diff options
| author | wn_ <invalid@email.com> | 2024-10-20 16:07:50 +0000 |
|---|---|---|
| committer | wn_ <invalid@email.com> | 2024-10-20 16:08:20 +0000 |
| commit | 142ca20cb034b0b197b44cf1094aac10e2c7996a (patch) | |
| tree | 800112795be9904ab45d95ac117426b1b072cfca /classes/Feeds.php | |
| parent | 5ea96397c08bb7e960a0eb2c2687073dc92c0ad3 (diff) | |
Fix keyword searches with a quoted string value.
Before this change curly braces wrapped the keyword and its value, making the pair get treated as leftover words.
Also make the search query modification and CSV parsing a bit clearer with some comments and minor refactoring.
Diffstat (limited to 'classes/Feeds.php')
| -rw-r--r-- | classes/Feeds.php | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/classes/Feeds.php b/classes/Feeds.php index 5239c9f8a..2a3715211 100644 --- a/classes/Feeds.php +++ b/classes/Feeds.php @@ -2212,7 +2212,13 @@ class Feeds extends Handler_Protected { * @return array{0: string, 1: array<int, string>} [$search_query_part, $search_words] */ private static function _search_to_sql(string $search, string $search_language, int $owner_uid): array { - $keywords = str_getcsv(preg_replace('/(-?\w+)\:"(\w+)/', '"{$1}:{$2}', trim($search)), ' ', '"', ''); + // Modify the search string so that 'keyword:"foo bar"' becomes '"keyword:foo bar"'. + // This is needed so potential command pairs are grouped correctly. + $search_csv_str = preg_replace('/(-?\w+)\:"(\w+)/', '"$1:$2', trim($search)); + + // $keywords will be an array like ['"title:hello world"', 'some', 'words'] + $keywords = str_getcsv($search_csv_str, ' ', '"', ''); + $query_keywords = array(); $search_words = array(); $search_query_leftover = array(); @@ -2271,7 +2277,6 @@ class Feeds extends Handler_Protected { } break; case "star": - if ($commandpair[1]) { if ($commandpair[1] == "true") array_push($query_keywords, "($not (marked = true))"); |