diff options
| author | Mohamed Bassem <me@mbassem.com> | 2026-01-26 00:50:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-26 00:50:55 +0000 |
| commit | 5656e394d3d879d9cd48c18400cd7ce4c12f416e (patch) | |
| tree | a3744e6cd640c09151b3bb1f32d23cbc50e6d084 /packages/shared/searchQueryParser.ts | |
| parent | af3a587acaf641007c410e61579eeefe4836e8d7 (diff) | |
| download | karakeep-5656e394d3d879d9cd48c18400cd7ce4c12f416e.tar.zst | |
feat(search): add tag: alias for # and ! alias for negation (#2425)
Add `tag:` as an alternative syntax to `#` for tag search queries,
and `!` as an alternative to `-` for negating qualifiers. This provides
more intuitive syntax options for users who prefer text-based qualifiers
over special characters.
Co-authored-by: Claude <noreply@anthropic.com>
Diffstat (limited to '')
| -rw-r--r-- | packages/shared/searchQueryParser.ts | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/packages/shared/searchQueryParser.ts b/packages/shared/searchQueryParser.ts index 7447593a..027a662f 100644 --- a/packages/shared/searchQueryParser.ts +++ b/packages/shared/searchQueryParser.ts @@ -33,6 +33,7 @@ enum TokenType { Space = "SPACE", Hash = "HASH", Minus = "MINUS", + Exclamation = "EXCLAMATION", } // Rules are in order of priority @@ -41,7 +42,7 @@ const lexerRules: [RegExp, TokenType][] = [ [/^\s+or/i, TokenType.Or], [/^#/, TokenType.Hash], - [/^(is|url|list|after|before|age|feed|title):/, TokenType.Qualifier], + [/^(is|url|list|after|before|age|feed|title|tag):/, TokenType.Qualifier], [/^"([^"]+)"/, TokenType.StringLiteral], @@ -49,6 +50,7 @@ const lexerRules: [RegExp, TokenType][] = [ [/^\)/, TokenType.RParen], [/^\s+/, TokenType.Space], [/^-/, TokenType.Minus], + [/^!/, TokenType.Exclamation], // This needs to be last as it matches a lot of stuff [/^[^ )(]+/, TokenType.Ident], @@ -116,7 +118,10 @@ const EXP = rule<TokenType, TextAndMatcher>(); MATCHER.setPattern( alt_sc( apply( - seq(opt(str("-")), kright(str("is:"), tok(TokenType.Ident))), + seq( + opt(alt(str("-"), str("!"))), + kright(str("is:"), tok(TokenType.Ident)), + ), ([minus, ident]) => { switch (ident.text) { case "fav": @@ -182,7 +187,7 @@ MATCHER.setPattern( ), apply( seq( - opt(str("-")), + opt(alt(str("-"), str("!"))), alt(tok(TokenType.Qualifier), tok(TokenType.Hash)), alt( apply(tok(TokenType.Ident), (tok) => { @@ -206,6 +211,7 @@ MATCHER.setPattern( matcher: { type: "title", title: ident, inverse: !!minus }, }; case "#": + case "tag:": return { text: "", matcher: { type: "tagName", tagName: ident, inverse: !!minus }, |
