@@ -11,63 +11,73 @@ module Searchable
1111
1212 settings sake_settings do
1313 mapping do
14+ indexes :id , type : "integer"
15+ indexes :alcohol , type : "float"
16+ indexes :aminosando , type : "float"
1417 indexes :aroma_impression , analyzer : "ja"
18+ indexes :aroma_value , type : "integer"
1519 indexes :awa , analyzer : "ja"
20+ indexes :bindume_date , type : "date"
21+ indexes :bottle_level , analyzer : "ja"
22+ indexes :brew_year , type : "date"
1623 indexes :color , analyzer : "ja"
1724 indexes :genryomai , analyzer : "ja"
25+ indexes :hiire , analyzer : "ja"
1826 indexes :kakemai , analyzer : "ja"
1927 indexes :kobo , analyzer : "ja"
2028 indexes :kura , analyzer : "ja"
29+ indexes :moto , analyzer : "ja"
2130 indexes :name , analyzer : "ja"
2231 indexes :nigori , analyzer : "ja"
32+ indexes :nihonshudo , type : "float"
2333 indexes :note , analyzer : "ja"
34+ indexes :price , type : "integer"
2435 indexes :roka , analyzer : "ja"
36+ indexes :sando , type : "float"
2537 indexes :season , analyzer : "ja"
38+ indexes :seimai_buai , type : "integer"
2639 indexes :shibori , analyzer : "ja"
40+ indexes :size , type : "integer"
2741 indexes :taste_impression , analyzer : "ja"
42+ indexes :taste_value , type : "integer"
2843 indexes :todofuken , analyzer : "ja"
44+ indexes :tokutei_meisho , analyzer : "ja"
45+ indexes :warimizu , analyzer : "ja"
46+ indexes :created_at , type : "date"
47+ indexes :updated_at , type : "date"
2948 end
3049 end
3150
32- # rubocop:disable Metrics/MethodLength
3351 def as_indexed_json ( _options = { } )
34- {
35- aroma_impression : aroma_impression ,
36- awa : awa ,
37- color : color ,
38- genryomai : genryomai ,
39- kakemai : kakemai ,
40- kobo : kobo ,
41- kura : kura ,
42- name : name ,
43- nigori : nigori ,
44- note : note ,
45- roka : roka ,
46- season : season ,
47- shibori : shibori ,
48- taste_impression : taste_impression ,
49- todofuken : todofuken ,
50- } . as_json
52+ hash = as_json
53+ hash [ "tokutei_meisho" ] = tokutei_meisho_i18n
54+ # enum値がunknownの時は検索したくないため空文字列にする
55+ hash [ "warimizu" ] = warimizu == "unknown" ? "" : warimizu_i18n
56+ hash [ "moto" ] = moto == "unknown" ? "" : moto_i18n
57+ hash [ "bottle_level" ] = bottle_level_i18n
58+ hash [ "hiire" ] = hiire == "unknown" ? "" : hiire_i18n
59+ hash
5160 end
52- # rubocop:enable Metrics/MethodLength
5361
5462 # rubocop:disable Metrics/MethodLength
5563 def self . simple_search ( keyword )
56- if keyword . blank?
57- __elasticsearch__ . search (
58- query : { match_all : { } } ,
59- )
60- else
61- __elasticsearch__ . search (
62- query : {
63- multi_match : {
64- query : keyword ,
65- fields : [ "*" ] ,
66- operator : "and" ,
67- } ,
64+ @search_definition = {
65+ query : { match_all : { } } ,
66+ post_filter : { bool : { must : [ match_all : { } ] } } ,
67+ sort : { updated_at : "desc" } ,
68+ }
69+
70+ if keyword . present?
71+ @search_definition [ :query ] = {
72+ multi_match : {
73+ query : keyword ,
74+ fields : %w[ name kura todofuken aroma_impression color taste_impression nigori awa
75+ tokutei_meisho genryomai kakemai kobo season warimizu moto roka shibori note bottle_level hiire ] ,
76+ operator : "and" ,
6877 } ,
69- )
78+ }
7079 end
80+ __elasticsearch__ . search ( @search_definition )
7181 end
7282 # rubocop:enable Metrics/MethodLength
7383 end
0 commit comments