Commit 7b4a2ff477b68f957dc40d19404e7526a007ad71
Committed by
Macartur Sousa
1 parent
8913303c
Exists in
elasticsearch_sort
WIP: Sort by name.raw instead of name
Showing
6 changed files
with
39 additions
and
17 deletions
Show diff stats
plugins/elasticsearch/helpers/elasticsearch_helper.rb
... | ... | @@ -92,19 +92,20 @@ module ElasticsearchHelper |
92 | 92 | query = { |
93 | 93 | query: query_method(text, fields), |
94 | 94 | sort: [ |
95 | - {"name.raw" => {"order" => "asc"}} | |
96 | - ], | |
97 | - suggest: { | |
98 | - autocomplete: { | |
99 | - text: text, | |
100 | - term: { | |
101 | - field: "name", | |
102 | - suggest_mode: "always" | |
103 | - } | |
95 | + {"name.raw" => {"order" => "desc"}}, "_score" | |
96 | + ], | |
97 | + suggest: { | |
98 | + autocomplete: { | |
99 | + text: text, | |
100 | + term: { | |
101 | + field: "name", | |
102 | + suggest_mode: "always" | |
103 | + } | |
104 | + } | |
104 | 105 | } |
105 | 106 | } |
106 | - } | |
107 | 107 | query |
108 | 108 | end |
109 | 109 | |
110 | + | |
110 | 111 | end | ... | ... |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
... | ... | @@ -7,12 +7,17 @@ module ElasticsearchIndexedModel |
7 | 7 | base.class_eval do |
8 | 8 | settings index: { number_of_shards: 1 } do |
9 | 9 | mappings dynamic: 'false' do |
10 | + puts "="*10 | |
11 | + puts base.inspect | |
12 | + puts base.indexable_fields | |
10 | 13 | base.indexable_fields.each do |field, value| |
11 | 14 | value = {} if value.nil? |
12 | - indexes field, type: value[:type].presence, fields: {"raw" => | |
13 | - {"index" => "not_analyzed", | |
14 | - "type" => "String" | |
15 | - } } | |
15 | + if field.to_s == "name" | |
16 | + indexes "name.raw", type: "string", index: "not_analyzed" | |
17 | + indexes "name", type: "string" | |
18 | + else | |
19 | + indexes field, type: value[:type].presence | |
20 | + end | |
16 | 21 | print '.' |
17 | 22 | end |
18 | 23 | end | ... | ... |
plugins/elasticsearch/lib/ext/community.rb
... | ... | @@ -3,7 +3,12 @@ require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class Community |
5 | 5 | def self.control_fields |
6 | - {} | |
6 | + {:name => {type: "string", analyzer: "english", fields: { | |
7 | + raw:{ | |
8 | + type: "string", | |
9 | + index: "not_analyzed" | |
10 | + } | |
11 | + }}} | |
7 | 12 | end |
8 | 13 | include ElasticsearchIndexedModel |
9 | 14 | end | ... | ... |
plugins/elasticsearch/lib/ext/event.rb
plugins/elasticsearch/lib/ext/person.rb
... | ... | @@ -6,7 +6,12 @@ class Person |
6 | 6 | { |
7 | 7 | :visible => {type: 'boolean'}, |
8 | 8 | :public_profile => {type: 'boolean'}, |
9 | - } | |
9 | + :name => {type: "string", fields: { | |
10 | + raw:{ | |
11 | + type: "string", | |
12 | + index: "not_analyzed" | |
13 | + } | |
14 | + }}} | |
10 | 15 | end |
11 | 16 | include ElasticsearchIndexedModel |
12 | 17 | end | ... | ... |