elasticsearch-rails 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/elasticsearch-rails.gemspec +1 -1
- data/lib/elasticsearch/rails/version.rb +1 -1
- data/lib/rails/templates/02-pretty.rb +4 -1
- data/lib/rails/templates/03-expert.rb +25 -2
- data/lib/rails/templates/04-dsl.rb +6 -3
- data/lib/rails/templates/05-settings-files.rb +3 -1
- data/lib/rails/templates/index.html.dsl.erb +3 -3
- data/lib/rails/templates/index.html.erb +14 -14
- data/lib/rails/templates/search_controller_test.dsl.rb +1 -1
- data/lib/rails/templates/search_controller_test.rb +18 -17
- data/lib/rails/templates/searchable.rb +16 -22
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0787291aba03d312879a2ce76404dcf85842a2bc
|
4
|
+
data.tar.gz: 271098b78bda71302678b132ab85d0a3efd8ef4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39225728dce276bf9b5e2d7613912fd75fcbf208d3b9dd3c92ad8886e69eaa1355da24f2684a15590affcb9f54b246c6c23d4bd88274efe3156e4862cad88d8e
|
7
|
+
data.tar.gz: 05d38f3aa061b4c5dbe260c53eaeb3e79b3b73fc3e62b61304bfc76e5b596241e42dc366db6639e0cc3a66e36b9af8a000350c5f21bc9552f156338624dad3e6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.1.9
|
2
|
+
|
3
|
+
* Added checks for proper launch order and other updates to the example application templates
|
4
|
+
* Updated the example application to work with Elasticsearch 2.x
|
5
|
+
* Used the `suggest` method instead of `response['suggest']` in the application template
|
6
|
+
|
1
7
|
## 0.1.8
|
2
8
|
|
3
9
|
* Added an example application template that loads settings from a file
|
data/elasticsearch-rails.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.required_ruby_version = ">= 1.9.3"
|
25
25
|
|
26
26
|
s.add_development_dependency "bundler", "~> 1.3"
|
27
|
-
s.add_development_dependency "rake"
|
27
|
+
s.add_development_dependency "rake", "< 11.0"
|
28
28
|
|
29
29
|
s.add_development_dependency "elasticsearch-extensions"
|
30
30
|
s.add_development_dependency "elasticsearch-model"
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/02-pretty.rb
|
2
2
|
|
3
|
-
|
3
|
+
unless File.read('README.rdoc').include? '== [1] Basic'
|
4
|
+
say_status "ERROR", "You have to run the 01-basic.rb template first.", :red
|
5
|
+
exit(1)
|
6
|
+
end
|
4
7
|
|
5
8
|
puts
|
6
9
|
say_status "README", "Updating Readme...\n", :yellow
|
@@ -1,6 +1,25 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb
|
2
2
|
|
3
|
-
|
3
|
+
unless File.read('README.rdoc').include? '== [2] Pretty'
|
4
|
+
say_status "ERROR", "You have to run the 01-basic.rb and 02-pretty.rb templates first.", :red
|
5
|
+
exit(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'redis'
|
10
|
+
rescue LoadError
|
11
|
+
say_status "ERROR", "Please install the 'redis' gem before running this template", :red
|
12
|
+
exit(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
Redis.new.info
|
17
|
+
rescue Redis::CannotConnectError
|
18
|
+
puts
|
19
|
+
say_status "ERROR", "Redis not available", :red
|
20
|
+
say_status "", "This template uses an asynchronous indexer via Sidekiq, and requires a running Redis server."
|
21
|
+
exit(1)
|
22
|
+
end
|
4
23
|
|
5
24
|
append_to_file 'README.rdoc', <<-README
|
6
25
|
|
@@ -189,7 +208,11 @@ run "bundle install"
|
|
189
208
|
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/indexer.rb',
|
190
209
|
'app/workers/indexer.rb'
|
191
210
|
|
192
|
-
|
211
|
+
insert_into_file "test/test_helper.rb",
|
212
|
+
"require 'sidekiq/testing'\n\n",
|
213
|
+
before: "class ActiveSupport::TestCase\n"
|
214
|
+
|
215
|
+
git add: "Gemfile* app/workers/ test/test_helper.rb"
|
193
216
|
git commit: "-m 'Added a Sidekiq indexer\n\nRun:\n\n $ bundle exec sidekiq --queue elasticsearch --verbose\n\nSee http://sidekiq.org'"
|
194
217
|
|
195
218
|
# ----- Add SearchController -----------------------------------------------------------------------
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# $ rails new searchapp --skip --skip-bundle --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/04-dsl.rb
|
2
2
|
|
3
|
-
|
3
|
+
unless File.read('README.rdoc').include? '== [3] Expert'
|
4
|
+
say_status "ERROR", "You have to run the 01-basic.rb, 02-pretty.rb and 03-expert.rb templates first.", :red
|
5
|
+
exit(1)
|
6
|
+
end
|
4
7
|
|
5
8
|
append_to_file 'README.rdoc', <<-README
|
6
9
|
|
@@ -37,11 +40,11 @@ run "bundle install"
|
|
37
40
|
|
38
41
|
# copy_file File.expand_path('../searchable.dsl.rb', __FILE__), 'app/models/concerns/searchable.rb', force: true
|
39
42
|
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/searchable.dsl.rb',
|
40
|
-
'app/models/concerns/searchable.rb'
|
43
|
+
'app/models/concerns/searchable.rb', force: true
|
41
44
|
|
42
45
|
# copy_file File.expand_path('../index.html.dsl.erb', __FILE__), 'app/views/search/index.html.erb', force: true
|
43
46
|
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/index.html.dsl.erb',
|
44
|
-
'app/views/search/index.html.erb'
|
47
|
+
'app/views/search/index.html.erb', force: true
|
45
48
|
|
46
49
|
gsub_file "test/controllers/search_controller_test.rb", %r{test "should return facets" do.*?end}m, <<-CODE
|
47
50
|
test "should return aggregations" do
|
@@ -25,7 +25,9 @@ git commit: "-m 'Setup the Searchable module to load settings from file'"
|
|
25
25
|
|
26
26
|
# ----- Copy the articles_settings.json file -------------------------------------------------------
|
27
27
|
|
28
|
-
copy_file File.expand_path('../articles_settings.json', __FILE__), 'config/elasticsearch/articles_settings.json'
|
28
|
+
# copy_file File.expand_path('../articles_settings.json', __FILE__), 'config/elasticsearch/articles_settings.json'
|
29
|
+
get 'https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/articles_settings.json',
|
30
|
+
'config/elasticsearch/articles_settings.json', force: true
|
29
31
|
|
30
32
|
git add: "config/elasticsearch/articles_settings.json"
|
31
33
|
git commit: "-m 'Create the articles settings file'"
|
@@ -47,13 +47,13 @@
|
|
47
47
|
<hr>
|
48
48
|
</div>
|
49
49
|
|
50
|
-
<% if @articles.size < 1 &&
|
50
|
+
<% if @articles.size < 1 && @articles.response.suggestions.present? %>
|
51
51
|
<div class="col-md-12">
|
52
52
|
<p class="alert alert-warning">
|
53
53
|
No documents have been found.
|
54
|
-
<% if
|
54
|
+
<% if @articles.response.suggestions.terms.present? %>
|
55
55
|
Maybe you mean
|
56
|
-
<%=
|
56
|
+
<%= @articles.response.suggestions.terms.map do |term|
|
57
57
|
link_to term, search_path(params.except(:controller, :action).merge q: term)
|
58
58
|
end.to_sentence(last_word_connector: ' or ').html_safe %>?
|
59
59
|
<% end %>
|
@@ -47,13 +47,13 @@
|
|
47
47
|
<hr>
|
48
48
|
</div>
|
49
49
|
|
50
|
-
<% if @articles.size < 1 &&
|
50
|
+
<% if @articles.size < 1 && @articles.response.suggest.present? %>
|
51
51
|
<div class="col-md-12">
|
52
52
|
<p class="alert alert-warning">
|
53
53
|
No documents have been found.
|
54
|
-
<% if
|
54
|
+
<% if @articles.response.suggest['suggest_title'].present? || @articles.response.suggest['suggest_body'].present? %>
|
55
55
|
Maybe you mean
|
56
|
-
<%=
|
56
|
+
<%= @articles.response.suggest.map { |k,v| v.first['options'] }.flatten.map {|v| v['text']}.uniq.map do |term|
|
57
57
|
link_to term, search_path(params.except(:controller, :action).merge q: term)
|
58
58
|
end.to_sentence(last_word_connector: ' or ').html_safe %>?
|
59
59
|
<% end %>
|
@@ -68,11 +68,11 @@
|
|
68
68
|
<p class="panel-heading"><%= link_to 'All Sections →'.html_safe, search_path(params.except(:controller, :action).merge(c: nil))%></p>
|
69
69
|
|
70
70
|
<div class="list-group">
|
71
|
-
<% @articles.response.response['
|
71
|
+
<% @articles.response.response['aggregations']['categories']['categories']['buckets'].each do |c| %>
|
72
72
|
<%=
|
73
|
-
link_to search_path(params.except(:controller, :action).merge(c: c['
|
74
|
-
class: "list-group-item#{' active' if params[:c] == c['
|
75
|
-
c['
|
73
|
+
link_to search_path(params.except(:controller, :action).merge(c: c['key'])),
|
74
|
+
class: "list-group-item#{' active' if params[:c] == c['key']}" do
|
75
|
+
c['key'].titleize.html_safe + content_tag(:small, c['doc_count'], class: 'badge').html_safe
|
76
76
|
end
|
77
77
|
%>
|
78
78
|
<% end %>
|
@@ -83,11 +83,11 @@
|
|
83
83
|
<p class="panel-heading"><%= link_to 'All Authors →'.html_safe, search_path(params.except(:controller, :action).merge(a: nil))%></p>
|
84
84
|
|
85
85
|
<div class="list-group">
|
86
|
-
<% @articles.response.response['
|
86
|
+
<% @articles.response.response['aggregations']['authors']['authors']['buckets'].each do |a| %>
|
87
87
|
<%=
|
88
|
-
link_to search_path(params.except(:controller, :action).merge(a: a['
|
89
|
-
class: "list-group-item#{' active' if params[:a] == a['
|
90
|
-
a['
|
88
|
+
link_to search_path(params.except(:controller, :action).merge(a: a['key'])),
|
89
|
+
class: "list-group-item#{' active' if params[:a] == a['key']}" do
|
90
|
+
a['key'].titleize.html_safe + content_tag(:small, a['doc_count'], class: 'badge').html_safe
|
91
91
|
end
|
92
92
|
%>
|
93
93
|
<% end %>
|
@@ -98,16 +98,16 @@
|
|
98
98
|
<p class="panel-heading"><%= link_to 'Any Date →'.html_safe, search_path(params.except(:controller, :action).merge(w: nil))%></p>
|
99
99
|
|
100
100
|
<div class="list-group">
|
101
|
-
<% @articles.response.response['
|
101
|
+
<% @articles.response.response['aggregations']['published']['published']['buckets'].each do |w| %>
|
102
102
|
<%=
|
103
|
-
__start = Time.at(w['
|
103
|
+
__start = Time.at(w['key']/1000)
|
104
104
|
__end = __start.end_of_week
|
105
105
|
__date = __start.to_date.to_s(:iso)
|
106
106
|
|
107
107
|
link_to search_path(params.except(:controller, :action).merge(w: __date)),
|
108
108
|
class: "list-group-item#{' active' if params[:w] == __date}" do
|
109
109
|
"#{__start.to_date.to_s(:short)} — #{__end.to_date.to_s(:short)}".html_safe + \
|
110
|
-
content_tag(:small, w['
|
110
|
+
content_tag(:small, w['doc_count'], class: 'badge').html_safe
|
111
111
|
end
|
112
112
|
%>
|
113
113
|
<% end %>
|
@@ -58,7 +58,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
58
58
|
get :index, q: 'one'
|
59
59
|
assert_response :success
|
60
60
|
|
61
|
-
suggestions = assigns(:articles).response.
|
61
|
+
suggestions = assigns(:articles).response.suggest
|
62
62
|
|
63
63
|
assert_equal 'one', suggestions['suggest_title'][0]['text']
|
64
64
|
end
|
@@ -30,7 +30,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
30
30
|
|
31
31
|
Article.find_by_title('Article Three').comments.create body: 'One'
|
32
32
|
|
33
|
-
Sidekiq::
|
33
|
+
Sidekiq::Worker.clear_all
|
34
34
|
|
35
35
|
Article.__elasticsearch__.import force: true
|
36
36
|
Article.__elasticsearch__.refresh_index!
|
@@ -45,6 +45,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
45
45
|
test "should return search results in comments" do
|
46
46
|
get :index, q: 'one', comments: 'y'
|
47
47
|
assert_response :success
|
48
|
+
|
48
49
|
assert_equal 4, assigns(:articles).size
|
49
50
|
end
|
50
51
|
|
@@ -58,7 +59,7 @@ class SearchControllerTest < ActionController::TestCase
|
|
58
59
|
get :index, q: 'one'
|
59
60
|
assert_response :success
|
60
61
|
|
61
|
-
suggestions = assigns(:articles).response.
|
62
|
+
suggestions = assigns(:articles).response.suggest
|
62
63
|
|
63
64
|
assert_equal 'one', suggestions['suggest_title'][0]['text']
|
64
65
|
end
|
@@ -67,15 +68,15 @@ class SearchControllerTest < ActionController::TestCase
|
|
67
68
|
get :index, q: 'one'
|
68
69
|
assert_response :success
|
69
70
|
|
70
|
-
|
71
|
+
aggregations = assigns(:articles).response.response['aggregations']
|
71
72
|
|
72
|
-
assert_equal 2,
|
73
|
-
assert_equal 2,
|
74
|
-
assert_equal 2,
|
73
|
+
assert_equal 2, aggregations['categories']['categories']['buckets'].size
|
74
|
+
assert_equal 2, aggregations['authors']['authors']['buckets'].size
|
75
|
+
assert_equal 2, aggregations['published']['published']['buckets'].size
|
75
76
|
|
76
|
-
assert_equal 'One',
|
77
|
-
assert_equal 'John Smith',
|
78
|
-
assert_equal 1425254400000,
|
77
|
+
assert_equal 'One', aggregations['categories']['categories']['buckets'][0]['key']
|
78
|
+
assert_equal 'John Smith', aggregations['authors']['authors']['buckets'][0]['key']
|
79
|
+
assert_equal 1425254400000, aggregations['published']['published']['buckets'][0]['key']
|
79
80
|
end
|
80
81
|
|
81
82
|
test "should sort on the published date" do
|
@@ -104,13 +105,13 @@ class SearchControllerTest < ActionController::TestCase
|
|
104
105
|
|
105
106
|
assert_equal 2, assigns(:articles).size
|
106
107
|
|
107
|
-
|
108
|
+
aggregations = assigns(:articles).response.response['aggregations']
|
108
109
|
|
109
|
-
assert_equal 1,
|
110
|
-
assert_equal 1,
|
110
|
+
assert_equal 1, aggregations['authors']['authors']['buckets'].size
|
111
|
+
assert_equal 1, aggregations['published']['published']['buckets'].size
|
111
112
|
|
112
113
|
# Do NOT filter the category facet
|
113
|
-
assert_equal 2,
|
114
|
+
assert_equal 2, aggregations['categories']['categories']['buckets'].size
|
114
115
|
end
|
115
116
|
|
116
117
|
test "should filter search results and the category and published date facets when user selects a category" do
|
@@ -119,12 +120,12 @@ class SearchControllerTest < ActionController::TestCase
|
|
119
120
|
|
120
121
|
assert_equal 1, assigns(:articles).size
|
121
122
|
|
122
|
-
|
123
|
+
aggregations = assigns(:articles).response.response['aggregations']
|
123
124
|
|
124
|
-
assert_equal 1,
|
125
|
-
assert_equal 1,
|
125
|
+
assert_equal 1, aggregations['categories']['categories']['buckets'].size
|
126
|
+
assert_equal 1, aggregations['published']['published']['buckets'].size
|
126
127
|
|
127
128
|
# Do NOT filter the authors facet
|
128
|
-
assert_equal 2,
|
129
|
+
assert_equal 2, aggregations['authors']['authors']['buckets'].size
|
129
130
|
end
|
130
131
|
end
|
@@ -71,15 +71,14 @@ module Searchable
|
|
71
71
|
#
|
72
72
|
def self.search(query, options={})
|
73
73
|
|
74
|
-
# Prefill and set the filters (top-level `
|
74
|
+
# Prefill and set the filters (top-level `post_filter` and aggregation `filter` elements)
|
75
75
|
#
|
76
76
|
__set_filters = lambda do |key, f|
|
77
|
+
@search_definition[:post_filter][:and] ||= []
|
78
|
+
@search_definition[:post_filter][:and] |= [f]
|
77
79
|
|
78
|
-
@search_definition[:filter][:
|
79
|
-
@search_definition[:filter][:
|
80
|
-
|
81
|
-
@search_definition[:facets][key.to_sym][:facet_filter][:and] ||= []
|
82
|
-
@search_definition[:facets][key.to_sym][:facet_filter][:and] |= [f]
|
80
|
+
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] ||= []
|
81
|
+
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] |= [f]
|
83
82
|
end
|
84
83
|
|
85
84
|
@search_definition = {
|
@@ -95,27 +94,22 @@ module Searchable
|
|
95
94
|
}
|
96
95
|
},
|
97
96
|
|
98
|
-
|
97
|
+
post_filter: {},
|
99
98
|
|
100
|
-
|
99
|
+
aggregations: {
|
101
100
|
categories: {
|
102
|
-
|
103
|
-
|
104
|
-
},
|
105
|
-
facet_filter: {}
|
101
|
+
filter: { bool: { must: [ match_all: {} ] } },
|
102
|
+
aggregations: { categories: { terms: { field: 'categories' } } }
|
106
103
|
},
|
107
104
|
authors: {
|
108
|
-
|
109
|
-
|
110
|
-
},
|
111
|
-
facet_filter: {}
|
105
|
+
filter: { bool: { must: [ match_all: {} ] } },
|
106
|
+
aggregations: { authors: { terms: { field: 'authors.full_name.raw' } } }
|
112
107
|
},
|
113
108
|
published: {
|
114
|
-
|
115
|
-
|
116
|
-
interval: 'week'
|
117
|
-
}
|
118
|
-
facet_filter: {}
|
109
|
+
filter: { bool: { must: [ match_all: {} ] } },
|
110
|
+
aggregations: {
|
111
|
+
published: { date_histogram: { field: 'published_on', interval: 'week' } }
|
112
|
+
}
|
119
113
|
}
|
120
114
|
}
|
121
115
|
}
|
@@ -174,7 +168,7 @@ module Searchable
|
|
174
168
|
query: {
|
175
169
|
multi_match: {
|
176
170
|
query: query,
|
177
|
-
fields: ['body'],
|
171
|
+
fields: ['comments.body'],
|
178
172
|
operator: 'and'
|
179
173
|
}
|
180
174
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '11.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "<"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '11.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: elasticsearch-extensions
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|