summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-09-08 16:30:32 +0200
committerClaire <claire.github-309c@sitedethib.com>2023-09-08 16:30:32 +0200
commit64c6adcc5817ff00f09ece2a296550319a6118c6 (patch)
treed5ee26929b48f0ccd22793e2b15ca920fd9a69ae
parente5caa462c1e95f3a499acc4f21b09dca3cbc76c9 (diff)
Move supported prefixes to a constantrefactor/search-query-parser
-rw-r--r--app/lib/search_query_parser.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/lib/search_query_parser.rb b/app/lib/search_query_parser.rb
index e32e299b4da..84e20b7b626 100644
--- a/app/lib/search_query_parser.rb
+++ b/app/lib/search_query_parser.rb
@@ -1,6 +1,17 @@
# frozen_string_literal: true
class SearchQueryParser < Parslet::Parser
+ SUPPORTED_PREFIXES = %w(
+ has
+ is
+ language
+ from
+ before
+ after
+ during
+ in
+ ).freeze
+
# Efficiently matches disjoint strings
class StrList < Parslet::Atoms::Base
attr_reader :strings
@@ -41,7 +52,7 @@ class SearchQueryParser < Parslet::Parser
rule(:colon) { str(':') }
rule(:space) { match('\s').repeat(1) }
rule(:operator) { (str('+') | str('-')).as(:operator) }
- rule(:prefix_operator) { StrList.new(%w(has is language from before after during in)) }
+ rule(:prefix_operator) { StrList.new(SUPPORTED_PREFIXES) }
rule(:prefix) { prefix_operator.as(:prefix_operator) >> colon }
rule(:phrase) do
(str('"') >> match('[^"]').repeat.as(:phrase) >> str('"')) |