Browse Source

中文搜索使用ik分词器

pull/4/head
欧醚 4 years ago
parent
commit
7a9863cef7
2 changed files with 2 additions and 1 deletions
  1. +1
    -0
      app/chewy/statuses_index.rb
  2. +1
    -1
      app/lib/search_query_transformer.rb

+ 1
- 0
app/chewy/statuses_index.rb View File

@ -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) }

+ 1
- 1
app/lib/search_query_transformer.rb View File

@ -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

Loading…
Cancel
Save