lycra 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d27bab410270aa40ec1423f7f5c5d3934e6235f
4
- data.tar.gz: 7da381430a05731f12ac5fff47c66bc94e2b8585
3
+ metadata.gz: 3bf98e0a1f8a9f2bbf07e8ec4ed449669079f2cb
4
+ data.tar.gz: cc1efe7e1ee2bdb305488dc0a97bebbf34a065a6
5
5
  SHA512:
6
- metadata.gz: 091f3735691bed6d06340f67879a6490a0f9a6c1ca7194d0973e749251b55ab6014cc0e390bacecdf3bce96ad1326c6f1de7bc5a5b5edbdc3e432e6f7597125c
7
- data.tar.gz: 6c885b617b7a83d03650ebb5df08417af76c4bd7b9643b11c149c736fc693f2d95ece8dba1db8b58f7a8bb1c6f186e701b538f48fad01fb3fa3790d53b38d3d6
6
+ metadata.gz: 314c097c97abde4c8887a8a6fc24cdbd2ce72c2a691f1f46316b7a7cecb708260bf7cb75be9ecb08deb480e1dd71466d6c4ed2e9a85df5809587d47b1720d8af
7
+ data.tar.gz: 3d328434187df390fe1a50f845f2c237d124ec0dafe579b7d089dbe7783b38a6d973e79494cb118fc60219d18de5fcc13bef48d4b41924d2c722aff477275d07
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require 'canfig'
3
3
  require 'elasticsearch/persistence'
4
4
  require 'elasticsearch/model'
5
+ require 'lycra/monkeypatches'
5
6
  require 'lycra/errors'
6
7
  require 'lycra/model'
7
8
  require 'lycra/search'
@@ -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
@@ -2,7 +2,7 @@ module Lycra
2
2
  module Version
3
3
  MAJOR = '0'
4
4
  MINOR = '0'
5
- PATCH = '5'
5
+ PATCH = '6'
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
 
8
8
  class << self
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.5
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