From 7a9863cef75db6461fd9d1ddbb261391ac1fc977 Mon Sep 17 00:00:00 2001 From: Z Date: Sun, 19 Jul 2020 17:43:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E6=96=87=E6=90=9C=E7=B4=A2=E4=BD=BF?= =?UTF-8?q?=E7=94=A8ik=E5=88=86=E8=AF=8D=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chewy/statuses_index.rb | 1 + app/lib/search_query_transformer.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/chewy/statuses_index.rb b/app/chewy/statuses_index.rb index 47cb856ea..f364eb10f 100644 --- a/app/chewy/statuses_index.rb +++ b/app/chewy/statuses_index.rb @@ -58,6 +58,7 @@ class StatusesIndex < Chewy::Index field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].concat(status.media_attachments.map(&:description)).concat(status.preloadable_poll ? status.preloadable_poll.options : []).join("\n\n") } do field :stemmed, type: 'text', analyzer: 'content' + field :chn , type: 'text', analyzer: 'ik_max_word', search_analyzer: 'ik_smart' end field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb index e07ebfffe..42a8a0284 100644 --- a/app/lib/search_query_transformer.rb +++ b/app/lib/search_query_transformer.rb @@ -23,7 +23,7 @@ class SearchQueryTransformer < Parslet::Transform def clause_to_query(clause) case clause when TermClause - { multi_match: { type: 'most_fields', query: clause.term, fields: ['text', 'text.stemmed'] } } + { multi_match: { type: 'most_fields', query: clause.term, fields: clause.term.match?('^[a-zA-Z]*$') ? ['text', 'text.stemmed'] : ['text.chn']} } when PhraseClause { match_phrase: { text: { query: clause.phrase } } } else