lycra 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lycra.rb +1 -0
- data/lib/lycra/monkeypatches.rb +46 -0
- data/lib/lycra/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bf98e0a1f8a9f2bbf07e8ec4ed449669079f2cb
|
4
|
+
data.tar.gz: cc1efe7e1ee2bdb305488dc0a97bebbf34a065a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 314c097c97abde4c8887a8a6fc24cdbd2ce72c2a691f1f46316b7a7cecb708260bf7cb75be9ecb08deb480e1dd71466d6c4ed2e9a85df5809587d47b1720d8af
|
7
|
+
data.tar.gz: 3d328434187df390fe1a50f845f2c237d124ec0dafe579b7d089dbe7783b38a6d973e79494cb118fc60219d18de5fcc13bef48d4b41924d2c722aff477275d07
|
data/lib/lycra.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# The Problem:
|
2
|
+
#
|
3
|
+
# https://github.com/elastic/elasticsearch-rails/issues/421
|
4
|
+
#
|
5
|
+
# We create our indices with a timestamp, then alias the basename (without the timestamp) to the timestamped index. When
|
6
|
+
# you ask the elasticsearch-model gem for records (instead of results), and it tries to use your models to look them up,
|
7
|
+
# it decides which model to use based on the index name and document type. This is a problem for us because our documents
|
8
|
+
# use the alias name (i.e. 'my-index') as their index name, but the hits that come back when searching use the timestamped
|
9
|
+
# index name (i.e. 'my-index-123456789'), which don't match up using the `==` operator in the original implementation of
|
10
|
+
# this method.
|
11
|
+
|
12
|
+
# The Solution:
|
13
|
+
#
|
14
|
+
# Instead of checking whether the hit's index name and the model's index name are exactly equal, we use a simple regex pattern
|
15
|
+
# to match the index names against each other. The regex pattern used below makes the timestamp optional, and allows for both
|
16
|
+
# 'my-index' and 'my-index-123456789' to match against 'my-index'
|
17
|
+
|
18
|
+
module Elasticsearch
|
19
|
+
module Model
|
20
|
+
module Adapter
|
21
|
+
module Multiple
|
22
|
+
module Records
|
23
|
+
# Returns the class of the model corresponding to a specific `hit` in Elasticsearch results
|
24
|
+
#
|
25
|
+
# @see Elasticsearch::Model::Registry
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
def __type_for_hit(hit)
|
30
|
+
@@__types ||= {}
|
31
|
+
|
32
|
+
@@__types[ "#{hit[:_index]}::#{hit[:_type]}" ] ||= begin
|
33
|
+
Registry.all.detect do |model|
|
34
|
+
# Original Implementation
|
35
|
+
#model.index_name == hit[:_index] && model.document_type == hit[:_type]
|
36
|
+
|
37
|
+
# Our Monkeypatch
|
38
|
+
hit[:_index] =~ /\A#{model.index_name}(-\d+)?\Z/ && model.document_type == hit[:_type]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/lycra/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lycra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- lib/lycra/engine.rb
|
164
164
|
- lib/lycra/errors.rb
|
165
165
|
- lib/lycra/model.rb
|
166
|
+
- lib/lycra/monkeypatches.rb
|
166
167
|
- lib/lycra/search.rb
|
167
168
|
- lib/lycra/search/aggregations.rb
|
168
169
|
- lib/lycra/search/enumerable.rb
|