about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/search_query_parser.rb19
-rw-r--r--app/lib/search_query_transformer.rb2
2 files changed, 12 insertions, 9 deletions
diff --git a/app/lib/search_query_parser.rb b/app/lib/search_query_parser.rb
index 405ad15b8..15956d4cf 100644
--- a/app/lib/search_query_parser.rb
+++ b/app/lib/search_query_parser.rb
@@ -1,14 +1,15 @@
 # frozen_string_literal: true
 
 class SearchQueryParser < Parslet::Parser
-  rule(:term)     { match('[^\s":]').repeat(1).as(:term) }
-  rule(:quote)    { str('"') }
-  rule(:colon)    { str(':') }
-  rule(:space)    { match('\s').repeat(1) }
-  rule(:operator) { (str('+') | str('-')).as(:operator) }
-  rule(:prefix)   { (term >> colon).as(:prefix) }
-  rule(:phrase)   { (quote >> (term >> space.maybe).repeat >> quote).as(:phrase) }
-  rule(:clause)   { (prefix.maybe >> operator.maybe >> (phrase | term)).as(:clause) }
-  rule(:query)    { (clause >> space.maybe).repeat.as(:query) }
+  rule(:term)      { match('[^\s":]').repeat(1).as(:term) }
+  rule(:quote)     { str('"') }
+  rule(:colon)     { str(':') }
+  rule(:space)     { match('\s').repeat(1) }
+  rule(:operator)  { (str('+') | str('-')).as(:operator) }
+  rule(:prefix)    { (term >> colon).as(:prefix) }
+  rule(:shortcode) { (colon >> term >> colon.maybe).as(:shortcode) }
+  rule(:phrase)    { (quote >> (term >> space.maybe).repeat >> quote).as(:phrase) }
+  rule(:clause)    { (prefix.maybe >> operator.maybe >> (phrase | term | shortcode)).as(:clause) }
+  rule(:query)     { (clause >> space.maybe).repeat.as(:query) }
   root(:query)
 end
diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb
index 2c4144790..6a299f59d 100644
--- a/app/lib/search_query_transformer.rb
+++ b/app/lib/search_query_transformer.rb
@@ -75,6 +75,8 @@ class SearchQueryTransformer < Parslet::Transform
 
     if clause[:term]
       TermClause.new(prefix, operator, clause[:term].to_s)
+    elsif clause[:shortcode]
+      TermClause.new(prefix, operator, ":#{clause[:term]}:")
     elsif clause[:phrase]
       PhraseClause.new(prefix, operator, clause[:phrase].map { |p| p[:term].to_s }.join(' '))
     else