parent
77843c0bdc
commit
d5940f00d3
7 changed files with 36 additions and 7 deletions
|
@ -242,17 +242,20 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
class TermClause
|
||||
attr_reader :operator, :term
|
||||
|
||||
def initialize(operator, term)
|
||||
def initialize(operator, term, current_account: nil)
|
||||
@operator = Operator.symbol(operator)
|
||||
@term = term
|
||||
@account = current_account
|
||||
end
|
||||
|
||||
def to_query
|
||||
if @term.start_with?('#')
|
||||
{ match: { tags: { query: @term, operator: 'and' } } }
|
||||
else
|
||||
elsif @account&.user&.setting_reverse_search_quote
|
||||
# Memo for checking when manually merge
|
||||
# { multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } }
|
||||
{ match_phrase: { text: { query: @term } } }
|
||||
else
|
||||
{ multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } }
|
||||
end
|
||||
end
|
||||
|
@ -261,15 +264,20 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
class PhraseClause
|
||||
attr_reader :operator, :phrase
|
||||
|
||||
def initialize(operator, phrase)
|
||||
def initialize(operator, phrase, current_account: nil)
|
||||
@operator = Operator.symbol(operator)
|
||||
@phrase = phrase
|
||||
@account = current_account
|
||||
end
|
||||
|
||||
def to_query
|
||||
# Memo for checking when manually merge
|
||||
# { match_phrase: { text: { query: @phrase } } }
|
||||
{ match_phrase: { text: { query: @phrase } } }
|
||||
if @account&.user&.setting_reverse_search_quote
|
||||
{ multi_match: { type: 'most_fields', query: @phrase, fields: ['text', 'text.stemmed'], operator: 'and' } }
|
||||
else
|
||||
{ match_phrase: { text: { query: @phrase } } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -411,11 +419,11 @@ class SearchQueryTransformer < Parslet::Transform
|
|||
if clause[:prefix] && SUPPORTED_PREFIXES.include?(prefix)
|
||||
PrefixClause.new(prefix, operator, term, current_account: current_account)
|
||||
elsif clause[:prefix]
|
||||
TermClause.new(operator, "#{prefix} #{term}")
|
||||
TermClause.new(operator, "#{prefix} #{term}", current_account: current_account)
|
||||
elsif clause[:term]
|
||||
TermClause.new(operator, term)
|
||||
TermClause.new(operator, term, current_account: current_account)
|
||||
elsif clause[:phrase]
|
||||
PhraseClause.new(operator, term)
|
||||
PhraseClause.new(operator, term, current_account: current_account)
|
||||
else
|
||||
raise "Unexpected clause type: #{clause}"
|
||||
end
|
||||
|
|
|
@ -243,6 +243,10 @@ module User::HasSettings
|
|||
settings['use_public_index']
|
||||
end
|
||||
|
||||
def setting_reverse_search_quote
|
||||
settings['reverse_search_quote']
|
||||
end
|
||||
|
||||
def setting_disallow_unlisted_public_searchability
|
||||
settings['disallow_unlisted_public_searchability']
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ class UserSettings
|
|||
setting :default_searchability, default: :direct, in: %w(public private direct limited public_unlisted)
|
||||
setting :default_searchability_of_search, default: :public, in: %w(public private direct limited)
|
||||
setting :use_public_index, default: true
|
||||
setting :reverse_search_quote, default: false
|
||||
setting :disallow_unlisted_public_searchability, default: false
|
||||
setting :public_post_to_unlisted, default: false
|
||||
setting :reject_public_unlisted_subscription, default: false
|
||||
|
|
|
@ -72,6 +72,8 @@
|
|||
label_method: ->(searchability) { safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_search_long")], ' - ') },
|
||||
required: false,
|
||||
wrapper: :with_label
|
||||
.fields-group
|
||||
= ff.input :reverse_search_quote, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_reverse_search_quote'), hint: I18n.t('simple_form.hints.defaults.setting_reverse_search_quote')
|
||||
|
||||
.fields-group
|
||||
= ff.input :use_public_index, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_use_public_index')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue