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,19 +92,20 @@ module ElasticsearchHelper | ||
| 92 | query = { | 92 | query = { |
| 93 | query: query_method(text, fields), | 93 | query: query_method(text, fields), |
| 94 | sort: [ | 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 | query | 107 | query |
| 108 | end | 108 | end |
| 109 | 109 | ||
| 110 | + | ||
| 110 | end | 111 | end |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
| @@ -7,12 +7,17 @@ module ElasticsearchIndexedModel | @@ -7,12 +7,17 @@ module ElasticsearchIndexedModel | ||
| 7 | base.class_eval do | 7 | base.class_eval do |
| 8 | settings index: { number_of_shards: 1 } do | 8 | settings index: { number_of_shards: 1 } do |
| 9 | mappings dynamic: 'false' do | 9 | mappings dynamic: 'false' do |
| 10 | + puts "="*10 | ||
| 11 | + puts base.inspect | ||
| 12 | + puts base.indexable_fields | ||
| 10 | base.indexable_fields.each do |field, value| | 13 | base.indexable_fields.each do |field, value| |
| 11 | value = {} if value.nil? | 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 | print '.' | 21 | print '.' |
| 17 | end | 22 | end |
| 18 | end | 23 | end |
plugins/elasticsearch/lib/ext/community.rb
| @@ -3,7 +3,12 @@ require_relative '../elasticsearch_indexed_model' | @@ -3,7 +3,12 @@ require_relative '../elasticsearch_indexed_model' | ||
| 3 | 3 | ||
| 4 | class Community | 4 | class Community |
| 5 | def self.control_fields | 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 | end | 12 | end |
| 8 | include ElasticsearchIndexedModel | 13 | include ElasticsearchIndexedModel |
| 9 | end | 14 | end |
plugins/elasticsearch/lib/ext/event.rb
| @@ -6,6 +6,12 @@ class Event | @@ -6,6 +6,12 @@ class Event | ||
| 6 | { | 6 | { |
| 7 | :advertise => {}, | 7 | :advertise => {}, |
| 8 | :published => {}, | 8 | :published => {}, |
| 9 | + :name => {type: "string", analyzer: "english", fields: { | ||
| 10 | + raw:{ | ||
| 11 | + type: "string", | ||
| 12 | + index: "not_analyzed" | ||
| 13 | + } | ||
| 14 | + }} | ||
| 9 | } | 15 | } |
| 10 | end | 16 | end |
| 11 | include ElasticsearchIndexedModel | 17 | include ElasticsearchIndexedModel |
plugins/elasticsearch/lib/ext/person.rb
| @@ -6,7 +6,12 @@ class Person | @@ -6,7 +6,12 @@ class Person | ||
| 6 | { | 6 | { |
| 7 | :visible => {type: 'boolean'}, | 7 | :visible => {type: 'boolean'}, |
| 8 | :public_profile => {type: 'boolean'}, | 8 | :public_profile => {type: 'boolean'}, |
| 9 | - } | 9 | + :name => {type: "string", fields: { |
| 10 | + raw:{ | ||
| 11 | + type: "string", | ||
| 12 | + index: "not_analyzed" | ||
| 13 | + } | ||
| 14 | + }}} | ||
| 10 | end | 15 | end |
| 11 | include ElasticsearchIndexedModel | 16 | include ElasticsearchIndexedModel |
| 12 | end | 17 | end |
plugins/elasticsearch/lib/ext/text_article.rb
| @@ -5,7 +5,7 @@ class TextArticle | @@ -5,7 +5,7 @@ class TextArticle | ||
| 5 | def self.control_fields | 5 | def self.control_fields |
| 6 | { | 6 | { |
| 7 | :advertise => {}, | 7 | :advertise => {}, |
| 8 | - :published => {}, | 8 | + :published => {} |
| 9 | } | 9 | } |
| 10 | end | 10 | end |
| 11 | include ElasticsearchIndexedModel | 11 | include ElasticsearchIndexedModel |