Add: #452 全文検索で、ダブルクオートがない場合でも単語検索を標準とするオプション (#478)

This commit is contained in:
KMY(雪あすか) 2024-01-18 08:39:33 +09:00 committed by GitHub
parent 77843c0bdc
commit d5940f00d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 7 deletions

View file

@ -242,17 +242,20 @@ class SearchQueryTransformer < Parslet::Transform
class TermClause class TermClause
attr_reader :operator, :term attr_reader :operator, :term
def initialize(operator, term) def initialize(operator, term, current_account: nil)
@operator = Operator.symbol(operator) @operator = Operator.symbol(operator)
@term = term @term = term
@account = current_account
end end
def to_query def to_query
if @term.start_with?('#') if @term.start_with?('#')
{ match: { tags: { query: @term, operator: 'and' } } } { match: { tags: { query: @term, operator: 'and' } } }
else elsif @account&.user&.setting_reverse_search_quote
# Memo for checking when manually merge # Memo for checking when manually merge
# { multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } } # { 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' } } { multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } }
end end
end end
@ -261,17 +264,22 @@ class SearchQueryTransformer < Parslet::Transform
class PhraseClause class PhraseClause
attr_reader :operator, :phrase attr_reader :operator, :phrase
def initialize(operator, phrase) def initialize(operator, phrase, current_account: nil)
@operator = Operator.symbol(operator) @operator = Operator.symbol(operator)
@phrase = phrase @phrase = phrase
@account = current_account
end end
def to_query def to_query
# Memo for checking when manually merge # 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 } } } { match_phrase: { text: { query: @phrase } } }
end end
end end
end
class PrefixClause class PrefixClause
attr_reader :operator, :prefix, :term attr_reader :operator, :prefix, :term
@ -411,11 +419,11 @@ class SearchQueryTransformer < Parslet::Transform
if clause[:prefix] && SUPPORTED_PREFIXES.include?(prefix) if clause[:prefix] && SUPPORTED_PREFIXES.include?(prefix)
PrefixClause.new(prefix, operator, term, current_account: current_account) PrefixClause.new(prefix, operator, term, current_account: current_account)
elsif clause[:prefix] elsif clause[:prefix]
TermClause.new(operator, "#{prefix} #{term}") TermClause.new(operator, "#{prefix} #{term}", current_account: current_account)
elsif clause[:term] elsif clause[:term]
TermClause.new(operator, term) TermClause.new(operator, term, current_account: current_account)
elsif clause[:phrase] elsif clause[:phrase]
PhraseClause.new(operator, term) PhraseClause.new(operator, term, current_account: current_account)
else else
raise "Unexpected clause type: #{clause}" raise "Unexpected clause type: #{clause}"
end end

View file

@ -243,6 +243,10 @@ module User::HasSettings
settings['use_public_index'] settings['use_public_index']
end end
def setting_reverse_search_quote
settings['reverse_search_quote']
end
def setting_disallow_unlisted_public_searchability def setting_disallow_unlisted_public_searchability
settings['disallow_unlisted_public_searchability'] settings['disallow_unlisted_public_searchability']
end end

View file

@ -26,6 +26,7 @@ class UserSettings
setting :default_searchability, default: :direct, in: %w(public private direct limited public_unlisted) 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 :default_searchability_of_search, default: :public, in: %w(public private direct limited)
setting :use_public_index, default: true setting :use_public_index, default: true
setting :reverse_search_quote, default: false
setting :disallow_unlisted_public_searchability, default: false setting :disallow_unlisted_public_searchability, default: false
setting :public_post_to_unlisted, default: false setting :public_post_to_unlisted, default: false
setting :reject_public_unlisted_subscription, default: false setting :reject_public_unlisted_subscription, default: false

View file

@ -72,6 +72,8 @@
label_method: ->(searchability) { safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_search_long")], ' - ') }, label_method: ->(searchability) { safe_join([I18n.t("statuses.searchabilities.#{searchability}"), I18n.t("statuses.searchabilities.#{searchability}_search_long")], ' - ') },
required: false, required: false,
wrapper: :with_label 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 .fields-group
= ff.input :use_public_index, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_use_public_index') = ff.input :use_public_index, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_use_public_index')

View file

@ -72,6 +72,7 @@ en:
setting_dtl_menu: Show DTL menu on web setting_dtl_menu: Show DTL menu on web
setting_emoji_reaction_policy: Even with this setting, users on other servers are free to put their stamp on the post and share it within the same server. If you simply want to remove the stamp from your own screen, you can disable it from the appearance settings setting_emoji_reaction_policy: Even with this setting, users on other servers are free to put their stamp on the post and share it within the same server. If you simply want to remove the stamp from your own screen, you can disable it from the appearance settings
setting_enable_emoji_reaction: If turn off, other users still can react your posts setting_enable_emoji_reaction: If turn off, other users still can react your posts
setting_reverse_search_quote: Double-quotes will result in a search with a wider range of notation, which is the opposite of Mastodon's default behavior.
setting_single_ref_to_quote: If this server does not have target post, target server maybe cannot read your quote setting_single_ref_to_quote: If this server does not have target post, target server maybe cannot read your quote
setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details setting_use_blurhash: Gradients are based on the colors of the hidden visuals but obfuscate any details
setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed setting_use_pending_items: Hide timeline updates behind a click instead of automatically scrolling the feed
@ -283,6 +284,7 @@ en:
setting_reduce_motion: Reduce motion in animations setting_reduce_motion: Reduce motion in animations
setting_reject_public_unlisted_subscription: Reject sending public unlisted visibility/non-public searchability posts to Misskey, Calckey setting_reject_public_unlisted_subscription: Reject sending public unlisted visibility/non-public searchability posts to Misskey, Calckey
setting_reject_unlisted_subscription: Reject sending unlisted visibility/non-public searchability posts to Misskey, Calckey setting_reject_unlisted_subscription: Reject sending unlisted visibility/non-public searchability posts to Misskey, Calckey
setting_reverse_search_quote: Perform word-by-word search when search keywords are not enclosed in double quotes
setting_send_without_domain_blocks: Send your post to all server with administrator set as rejecting-post-server for protect you [DEPRECATED] setting_send_without_domain_blocks: Send your post to all server with administrator set as rejecting-post-server for protect you [DEPRECATED]
setting_show_application: Disclose application used to send posts setting_show_application: Disclose application used to send posts
setting_show_emoji_reaction_on_timeline: Show all stamps on timeline setting_show_emoji_reaction_on_timeline: Show all stamps on timeline

View file

@ -81,6 +81,7 @@ ja:
setting_hide_network: フォローとフォロワーの情報がプロフィールページで見られないようにします setting_hide_network: フォローとフォロワーの情報がプロフィールページで見られないようにします
setting_public_post_to_unlisted: 未対応のサードパーティアプリからもローカル公開で投稿できますが、公開投稿はWeb以外できなくなります setting_public_post_to_unlisted: 未対応のサードパーティアプリからもローカル公開で投稿できますが、公開投稿はWeb以外できなくなります
setting_reject_unlisted_subscription: Misskeyやそのフォークは、フォローしていないアカウントの「非収載」投稿を **購読・検索** することができます。これはkmyblueの挙動と異なります。そのようなサーバーに、指定した公開範囲の投稿を「フォロワーのみ」として配送します。ただし構造上、完璧な対応は困難でたまに非収載として配信されること、ご理解ください setting_reject_unlisted_subscription: Misskeyやそのフォークは、フォローしていないアカウントの「非収載」投稿を **購読・検索** することができます。これはkmyblueの挙動と異なります。そのようなサーバーに、指定した公開範囲の投稿を「フォロワーのみ」として配送します。ただし構造上、完璧な対応は困難でたまに非収載として配信されること、ご理解ください
setting_reverse_search_quote: 検索ワードをダブルクオートで囲って検索した場合、表記ゆれ多めの検索結果になります。Mastodon標準とは逆の挙動となります。
setting_show_application: 投稿するのに使用したアプリが投稿の詳細ビューに表示されるようになります setting_show_application: 投稿するのに使用したアプリが投稿の詳細ビューに表示されるようになります
setting_single_ref_to_quote: 当サーバーがまだ対象投稿を取り込んでいない場合、引用が相手に正常に認識されない場合があります setting_single_ref_to_quote: 当サーバーがまだ対象投稿を取り込んでいない場合、引用が相手に正常に認識されない場合があります
setting_stop_emoji_reaction_streaming: 通信容量の節約に役立ちます setting_stop_emoji_reaction_streaming: 通信容量の節約に役立ちます
@ -294,6 +295,7 @@ ja:
setting_reduce_motion: アニメーションの動きを減らす setting_reduce_motion: アニメーションの動きを減らす
setting_reject_public_unlisted_subscription: Misskey系サーバーに「ローカル公開」かつ検索許可「誰でも以外」の投稿を「フォロワーのみ」に変換して配送する setting_reject_public_unlisted_subscription: Misskey系サーバーに「ローカル公開」かつ検索許可「誰でも以外」の投稿を「フォロワーのみ」に変換して配送する
setting_reject_unlisted_subscription: Misskey系サーバーに「非収載」かつ検索許可「誰でも以外」の投稿を「フォロワーのみ」に変換して配送する setting_reject_unlisted_subscription: Misskey系サーバーに「非収載」かつ検索許可「誰でも以外」の投稿を「フォロワーのみ」に変換して配送する
setting_reverse_search_quote: ダブルクオートで囲まず検索した時、単語単位で検索する
setting_send_without_domain_blocks: 管理人の設定した配送停止設定を拒否する (非推奨) setting_send_without_domain_blocks: 管理人の設定した配送停止設定を拒否する (非推奨)
setting_show_application: 送信したアプリを開示する setting_show_application: 送信したアプリを開示する
setting_show_emoji_reaction_on_timeline: タイムライン上に他の人のつけたスタンプを表示する setting_show_emoji_reaction_on_timeline: タイムライン上に他の人のつけたスタンプを表示する

View file

@ -289,5 +289,15 @@ describe StatusesSearchService do
it_behaves_like 'does not hit status', 'when search with following', 'in:following りんご' it_behaves_like 'does not hit status', 'when search with following', 'in:following りんご'
end end
end end
context 'when reverse_search_quote is enabled' do
before do
alice.user.update!(settings: { reverse_search_quote: true })
end
it_behaves_like 'does not hit status', 'when search with letter in word', 'ご'
it_behaves_like 'hit status', 'when double quote search with letter in word', '"ご"'
it_behaves_like 'hit status', 'when search with word', 'りんご'
end
end end
end end