Compare View
Commits (2)
Showing
10 changed files
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
... | ... | @@ -28,7 +28,13 @@ class ElasticsearchPluginController < ApplicationController |
28 | 28 | query = {} |
29 | 29 | unless text.blank? |
30 | 30 | |
31 | - fields = klass::SEARCHABLE_FIELDS.map {|k, v| "#{k}^#{v[:weight]}"} | |
31 | + fields = klass.indexable_fields.map do |key, value| | |
32 | + if value[:weight] | |
33 | + "#{k}^#{v[:weight]}" | |
34 | + else | |
35 | + "#{k}" | |
36 | + end | |
37 | + end | |
32 | 38 | |
33 | 39 | query = { |
34 | 40 | query: { | ... | ... |
plugins/elasticsearch/lib/elasticsearch_indexed_model.rb
... | ... | @@ -7,6 +7,7 @@ module ElasticsearchIndexedModel |
7 | 7 | mappings dynamic: 'false' do |
8 | 8 | base::SEARCHABLE_FIELDS.each do |field, value| |
9 | 9 | indexes field |
10 | + print '.' | |
10 | 11 | end |
11 | 12 | end |
12 | 13 | base.__elasticsearch__.client.indices.delete \ |
... | ... | @@ -19,7 +20,14 @@ module ElasticsearchIndexedModel |
19 | 20 | } |
20 | 21 | end |
21 | 22 | end |
23 | + base.extend ClassMethods | |
22 | 24 | base.send :import |
23 | 25 | end |
24 | 26 | |
27 | + module ClassMethods | |
28 | + def indexable_fields | |
29 | + self::SEARCHABLE_FIELDS.keys + self.control_fields | |
30 | + end | |
31 | + end | |
32 | + | |
25 | 33 | end | ... | ... |
plugins/elasticsearch/lib/ext/article.rb
plugins/elasticsearch/lib/ext/category.rb
plugins/elasticsearch/lib/ext/comment.rb
plugins/elasticsearch/lib/ext/license.rb
plugins/elasticsearch/lib/ext/national_region.rb
plugins/elasticsearch/lib/ext/profile.rb
... | ... | @@ -2,7 +2,12 @@ require_dependency 'profile' |
2 | 2 | require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class Profile |
5 | + include ElasticsearchIndexedModel | |
6 | + | |
5 | 7 | def self.control_fields |
6 | - %w( visible public_profile ) | |
8 | + [ | |
9 | + :visible, | |
10 | + :public_profile, | |
11 | + ] | |
7 | 12 | end |
8 | 13 | end | ... | ... |
plugins/elasticsearch/lib/ext/scrap.rb
... | ... | @@ -2,7 +2,12 @@ require_dependency 'scrap' |
2 | 2 | require_relative '../elasticsearch_indexed_model' |
3 | 3 | |
4 | 4 | class Scrap |
5 | + include ElasticsearchIndexedModel | |
6 | + | |
5 | 7 | def self.control_fields |
6 | - %w(advertise published) | |
8 | + [ | |
9 | + :advertise, | |
10 | + :published, | |
11 | + ] | |
7 | 12 | end |
8 | 13 | end | ... | ... |
plugins/elasticsearch/lib/ext/user.rb