Commit d88262317147ab21fafd3f34e5ba2d569b450b86
Committed by
Macartur Sousa
1 parent
e6b4ec6f
Exists in
elasticsearch_sort
Fixes tests and alphabetical ordering
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Arthur Jahn <stutrzbecher@gmail.com> Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
7 changed files
with
37 additions
and
50 deletions
Show diff stats
plugins/elasticsearch/Rakefile
@@ -30,7 +30,7 @@ task :start do | @@ -30,7 +30,7 @@ task :start do | ||
30 | if elasticsearch_development | 30 | if elasticsearch_development |
31 | sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' | 31 | sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1' |
32 | sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' | 32 | sh 'sudo systemctl enable elasticsearch >> /dev/null 2>&1' |
33 | - sleep 2 | 33 | + sleep 10 |
34 | end | 34 | end |
35 | end | 35 | end |
36 | 36 |
plugins/elasticsearch/helpers/elasticsearch_helper.rb
@@ -65,7 +65,7 @@ module ElasticsearchHelper | @@ -65,7 +65,7 @@ module ElasticsearchHelper | ||
65 | private | 65 | private |
66 | 66 | ||
67 | def searchable_models | 67 | def searchable_models |
68 | - SEARCHABLE_TYPES.except(:all).keys.map { | model | model.to_s.classify.constantize } | 68 | + ElasticsearchHelper::searchable_types.except(:all).keys.map { | model | model.to_s.classify.constantize } |
69 | end | 69 | end |
70 | 70 | ||
71 | def query_method expression, fields | 71 | def query_method expression, fields |
@@ -77,7 +77,7 @@ module ElasticsearchHelper | @@ -77,7 +77,7 @@ module ElasticsearchHelper | ||
77 | else | 77 | else |
78 | query_exp = { | 78 | query_exp = { |
79 | multi_match: { | 79 | multi_match: { |
80 | - query: expression, | 80 | + query: expression.downcase, |
81 | fields: fields, | 81 | fields: fields, |
82 | tie_breaker: 0.4, | 82 | tie_breaker: 0.4, |
83 | minimum_should_match: "40%" | 83 | minimum_should_match: "40%" |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
@@ -7,20 +7,13 @@ module ElasticsearchIndexedModel | @@ -7,20 +7,13 @@ 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 | ||
13 | - base.indexable_fields.each do |field, value| | 10 | + base.indexed_fields.each do |field, value| |
14 | value = {} if value.nil? | 11 | value = {} if value.nil? |
15 | - if field.to_s == "name" | ||
16 | - indexes "name", type: "string", fields: { | ||
17 | - raw: { | ||
18 | - type: "string", | ||
19 | - index: "not_analyzed" | ||
20 | - } | ||
21 | - } | 12 | + type = value[:type].presence |
13 | + if type.nil? | ||
14 | + indexes(field, fields: base.raw_field(field)) | ||
22 | else | 15 | else |
23 | - indexes field, type: value[:type].presence | 16 | + indexes field, type: type |
24 | end | 17 | end |
25 | print '.' | 18 | print '.' |
26 | end | 19 | end |
@@ -40,9 +33,19 @@ module ElasticsearchIndexedModel | @@ -40,9 +33,19 @@ module ElasticsearchIndexedModel | ||
40 | end | 33 | end |
41 | 34 | ||
42 | module ClassMethods | 35 | module ClassMethods |
43 | - def indexable_fields | 36 | + def raw_field name |
37 | + { | ||
38 | + raw: { | ||
39 | + type: "string", | ||
40 | + index: "not_analyzed" | ||
41 | + } | ||
42 | + } | ||
43 | + end | ||
44 | + | ||
45 | + def indexed_fields | ||
44 | self::SEARCHABLE_FIELDS.merge self.control_fields | 46 | self::SEARCHABLE_FIELDS.merge self.control_fields |
45 | end | 47 | end |
48 | + | ||
46 | end | 49 | end |
47 | 50 | ||
48 | end | 51 | end |
plugins/elasticsearch/lib/ext/community.rb
@@ -3,12 +3,7 @@ require_relative '../elasticsearch_indexed_model' | @@ -3,12 +3,7 @@ require_relative '../elasticsearch_indexed_model' | ||
3 | 3 | ||
4 | class Community | 4 | class Community |
5 | def self.control_fields | 5 | def self.control_fields |
6 | - {:name => {type: "string", analyzer: "english", fields: { | ||
7 | - raw:{ | ||
8 | - type: "string", | ||
9 | - index: "not_analyzed" | ||
10 | - } | ||
11 | - }}} | 6 | + {} |
12 | end | 7 | end |
13 | include ElasticsearchIndexedModel | 8 | include ElasticsearchIndexedModel |
14 | end | 9 | end |
plugins/elasticsearch/lib/ext/event.rb
@@ -6,12 +6,6 @@ class Event | @@ -6,12 +6,6 @@ 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 | - }} | ||
15 | } | 9 | } |
16 | end | 10 | end |
17 | include ElasticsearchIndexedModel | 11 | include ElasticsearchIndexedModel |
plugins/elasticsearch/lib/ext/person.rb
@@ -6,12 +6,7 @@ class Person | @@ -6,12 +6,7 @@ class Person | ||
6 | { | 6 | { |
7 | :visible => {type: 'boolean'}, | 7 | :visible => {type: 'boolean'}, |
8 | :public_profile => {type: 'boolean'}, | 8 | :public_profile => {type: 'boolean'}, |
9 | - :name => {type: "string", fields: { | ||
10 | - raw:{ | ||
11 | - type: "string", | ||
12 | - index: "not_analyzed" | ||
13 | - } | ||
14 | - }}} | 9 | + } |
15 | end | 10 | end |
16 | include ElasticsearchIndexedModel | 11 | include ElasticsearchIndexedModel |
17 | end | 12 | end |
plugins/elasticsearch/test/unit/controllers/elasticsearch_plugin_controller_test.rb
@@ -15,13 +15,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -15,13 +15,13 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
15 | 15 | ||
16 | def create_people | 16 | def create_people |
17 | 5.times do | index | | 17 | 5.times do | index | |
18 | - create_user "person_#{index}" | 18 | + create_user "person #{index}" |
19 | end | 19 | end |
20 | end | 20 | end |
21 | 21 | ||
22 | def create_communities | 22 | def create_communities |
23 | 6.times do | index | | 23 | 6.times do | index | |
24 | - fast_create Community, name: "community_#{index}", created_at: Date.new | 24 | + fast_create Community, name: "community #{index}", created_at: Date.new |
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 | ||
@@ -54,31 +54,31 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -54,31 +54,31 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
54 | end | 54 | end |
55 | 55 | ||
56 | should 'return results filtered by query' do | 56 | should 'return results filtered by query' do |
57 | - get :index, { 'query' => "person_"} | 57 | + get :index, { 'query' => "person"} |
58 | assert_response :success | 58 | assert_response :success |
59 | assert_select ".search-item", 5 | 59 | assert_select ".search-item", 5 |
60 | assert_template partial: '_person_display' | 60 | assert_template partial: '_person_display' |
61 | end | 61 | end |
62 | 62 | ||
63 | - should 'return results filtered by query with uppercase' do | ||
64 | - get :index, {'query' => "PERSON_1"} | ||
65 | - assert_response :success | ||
66 | - assert_select ".search-item", 1 | ||
67 | - assert_template partial: '_person_display' | ||
68 | - end | 63 | + should 'return results filtered by query with uppercase' do |
64 | + get :index, {'query' => "PERSON 1"} | ||
65 | + assert_response :success | ||
66 | + assert_template partial: '_person_display' | ||
67 | + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
68 | + end | ||
69 | 69 | ||
70 | - should 'return results filtered by query with downcase' do | ||
71 | - get :index, {'query' => "person_1"} | ||
72 | - assert_response :success | ||
73 | - assert_select ".search-item", 1 | ||
74 | - end | 70 | + should 'return results filtered by query with downcase' do |
71 | + get :index, {'query' => "person 1"} | ||
72 | + assert_response :success | ||
73 | + assert_tag(tag: "div", attributes: { class: "person-item" } , descendant: { tag: "a", child: "person 1"} ) | ||
74 | + end | ||
75 | 75 | ||
76 | should 'return new person indexed' do | 76 | should 'return new person indexed' do |
77 | get :index, { "selected_type" => :community} | 77 | get :index, { "selected_type" => :community} |
78 | assert_response :success | 78 | assert_response :success |
79 | assert_select ".search-item", 6 | 79 | assert_select ".search-item", 6 |
80 | 80 | ||
81 | - fast_create Community, name: "community_#{7}", created_at: Date.new | 81 | + fast_create Community, name: "community #{7}", created_at: Date.new |
82 | Community.import | 82 | Community.import |
83 | sleep 2 | 83 | sleep 2 |
84 | 84 | ||
@@ -108,7 +108,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | @@ -108,7 +108,7 @@ class ElasticsearchPluginControllerTest < ActionController::TestCase | ||
108 | end | 108 | end |
109 | 109 | ||
110 | should 'pass params to elastic search controller' do | 110 | should 'pass params to elastic search controller' do |
111 | - get 'index', { query: 'community_' } | 111 | + get 'index', { query: 'community' } |
112 | assert_not_nil assigns(:results) | 112 | assert_not_nil assigns(:results) |
113 | assert_template partial: '_community_display' | 113 | assert_template partial: '_community_display' |
114 | end | 114 | end |