elasticsearch-model-globalize 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f0b5b689830ed73d970fc292f946df65d4543c5
|
4
|
+
data.tar.gz: 65c64bd1d0a1c28c78c79dda0152d72974519b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e38850098a974fb27823a0e61003eb24a4f5e1628e746aabb845ee2280db3a60f516e6dac95e81c3c8eb4bba7a7ff75cfb54b1b1a864938ffc8965814e3b8c
|
7
|
+
data.tar.gz: 28469f813d0cefec20e9cec1e224e8a275203e48ba61fd5dab9b6f3c078a7322121bf88197846f5b2968fb78238fa71390316d4c7da675c92319cf274de2e365
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Elasticsearch::Model::Globalize
|
2
2
|
|
3
|
-
`elasticsearch-model-globalize` library allows you to use
|
4
|
-
|
3
|
+
`elasticsearch-model-globalize` library allows you to use
|
4
|
+
[elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
|
5
|
+
\[[LICENSE](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/LICENSE.txt)\]
|
6
|
+
with [Globalize](https://github.com/globalize/globalize) \[[LICENSE](https://github.com/globalize/globalize/blob/master/LICENSE)\].
|
5
7
|
|
6
8
|
|
7
9
|
## Installation
|
@@ -21,7 +23,9 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
## Usage
|
23
25
|
|
24
|
-
There are a few ways to use
|
26
|
+
There are a few ways to use
|
27
|
+
[elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
|
28
|
+
with [Globalize](https://github.com/globalize/globalize).
|
25
29
|
|
26
30
|
This gem has two modules, one is `MultipleFields` and the other is `OneIndexPerLanguage`.
|
27
31
|
You can choose one for each model to fit your needs by simply including a module.
|
@@ -48,14 +52,6 @@ class Item < ActiveRecord::Base
|
|
48
52
|
include Elasticsearch::Model
|
49
53
|
include Elasticsearch::Model::Callbacks
|
50
54
|
include Elasticsearch::Model::Globalize::MultipleFields
|
51
|
-
|
52
|
-
mapping do
|
53
|
-
indexes :id, type: 'integer'
|
54
|
-
indexes :name_ja, analyzer: 'kuromoji'
|
55
|
-
indexes :name_en, analyzer: 'snowball'
|
56
|
-
indexes :description_ja, analyzer: 'kuromoji'
|
57
|
-
indexes :description_en, analyzer: 'snowball'
|
58
|
-
end
|
59
55
|
end
|
60
56
|
```
|
61
57
|
|
@@ -73,7 +69,50 @@ Elasticsearch::Model::Globalize::MultipleFields.localized_name do |name, locale|
|
|
73
69
|
end
|
74
70
|
```
|
75
71
|
|
76
|
-
|
72
|
+
The way to define `mappings` and `as_indexed_json` is same as
|
73
|
+
[elasticsearch-model](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model)
|
74
|
+
without this library.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class Item < ActiveRecord::Base
|
78
|
+
translates :name, :description
|
79
|
+
include Elasticsearch::Model
|
80
|
+
include Elasticsearch::Model::Callbacks
|
81
|
+
include Elasticsearch::Model::Globalize::MultipleFields
|
82
|
+
|
83
|
+
mapping do
|
84
|
+
indexes :id, type: 'integer'
|
85
|
+
indexes :name_ja, analyzer: 'kuromoji'
|
86
|
+
indexes :name_en, analyzer: 'snowball'
|
87
|
+
indexes :description_ja, analyzer: 'kuromoji'
|
88
|
+
indexes :description_en, analyzer: 'snowball'
|
89
|
+
end
|
90
|
+
|
91
|
+
def as_indexed_json(options={})
|
92
|
+
{ id: id,
|
93
|
+
name_ja: name_ja,
|
94
|
+
name_en: name_en,
|
95
|
+
description_ja: description_ja,
|
96
|
+
description_en: description_en }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
Getters and setters of the derived fields are automatically added by `MultipleFields` module.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
I18n.locale = :en
|
105
|
+
item = Item.new
|
106
|
+
item.name_ja = '輪ゴム'
|
107
|
+
item.name_ja # => "輪ゴム"
|
108
|
+
item.name # => nil
|
109
|
+
Globalize.with_locale(:ja) { item.name } # => "輪ゴム"
|
110
|
+
item.name = 'elastic'
|
111
|
+
item.name # => "elastic"
|
112
|
+
item.name_en # => "elastic"
|
113
|
+
```
|
114
|
+
|
115
|
+
One thing you have to care about is that put `translates` line before including
|
77
116
|
`Elasticsearch::Model::Globalize::MultipleFields`, otherwise `MultipleFields` module are not able to
|
78
117
|
know from which fields to derive localized fields.
|
79
118
|
|
@@ -107,8 +107,9 @@ module Elasticsearch
|
|
107
107
|
else
|
108
108
|
errors = Hash.new
|
109
109
|
I18n.available_locales.each do |locale|
|
110
|
+
super_options = options.clone
|
110
111
|
::Globalize.with_locale(locale) do
|
111
|
-
errors[locale] = super(
|
112
|
+
errors[locale] = super(super_options, &block)
|
112
113
|
end
|
113
114
|
end
|
114
115
|
self.find_each do |record|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-model-globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Imai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch-model
|