Skip to content

Commit 02d9814

Browse files
committed
[MODEL] Improved the custom analyzer example
Related: elastic#697
1 parent d023d43 commit 02d9814

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

elasticsearch-model/examples/activerecord_custom_analyzer.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Article < ActiveRecord::Base
3333
analyzer: {
3434
pattern: {
3535
type: 'pattern',
36-
pattern: "_|-|\\.",
36+
pattern: "\\s|_|-|\\.",
3737
lowercase: true
3838
},
3939
trigram: {
@@ -50,7 +50,7 @@ class Article < ActiveRecord::Base
5050
}
5151
} } do
5252
mapping do
53-
indexes :title, type: 'text' do
53+
indexes :title, type: 'text', analyzer: 'english' do
5454
indexes :keyword, analyzer: 'keyword'
5555
indexes :pattern, analyzer: 'pattern'
5656
indexes :trigram, analyzer: 'trigram'
@@ -74,7 +74,7 @@ class Article < ActiveRecord::Base
7474

7575
puts '', '-'*80
7676

77-
puts "Fulltext analyzer [Foo_Bar_1_Bazooka]".ansi(:bold),
77+
puts "English analyzer [Foo_Bar_1_Bazooka]".ansi(:bold),
7878
"Tokens: " +
7979
Article.__elasticsearch__.client.indices
8080
.analyze(index: Article.index_name, body: { field: 'title', text: 'Foo_Bar_1_Bazooka' })['tokens']
@@ -106,7 +106,7 @@ class Article < ActiveRecord::Base
106106

107107
response = Article.search query: { match: { 'title' => 'foo' } } ;
108108

109-
puts "Search for 'foo'".ansi(:bold),
109+
puts "English search for 'foo'".ansi(:bold),
110110
"#{response.response.hits.total} matches: " +
111111
response.records.map { |d| d.title }.join(', '),
112112
"\n"

0 commit comments

Comments
 (0)