search_flip 4.0.0.beta13 → 4.0.0.beta15
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 +4 -4
- data/.github/workflows/test.yml +41 -13
- data/CHANGELOG.md +17 -0
- data/Gemfile +15 -1
- data/README.md +14 -4
- data/UPDATING.md +8 -4
- data/lib/search_flip/aggregation.rb +1 -1
- data/lib/search_flip/bulk.rb +1 -1
- data/lib/search_flip/connection.rb +24 -14
- data/lib/search_flip/criteria.rb +4 -4
- data/lib/search_flip/index.rb +4 -4
- data/lib/search_flip/json.rb +1 -1
- data/lib/search_flip/response.rb +4 -4
- data/lib/search_flip/result.rb +2 -28
- data/lib/search_flip/version.rb +1 -1
- data/search_flip.gemspec +4 -11
- data/spec/search_flip/bulk_spec.rb +1 -1
- data/spec/search_flip/connection_spec.rb +41 -19
- data/spec/search_flip/criteria_spec.rb +7 -7
- data/spec/search_flip/index_spec.rb +8 -8
- data/spec/search_flip/json_spec.rb +1 -1
- data/spec/search_flip/response_spec.rb +2 -2
- data/spec/search_flip/result_spec.rb +3 -12
- data/spec/spec_helper.rb +4 -4
- metadata +6 -143
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbf6d1f0c653af6bc398768eff11d7715c1cea101a06f4eefb1c6078ad33abc1
|
4
|
+
data.tar.gz: c2568175d32374201ea212abfdebd709d8933c92c19cc646225b7bd90244498c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f28cc23ad081e6345764799b2f70b957c9be97fab7781f22fbee580ed2c28b8da0bb0b3a9c4ef5d4ec200c94a6799a5c082489d9a62b2e24f94c49e29bcd4d1
|
7
|
+
data.tar.gz: 1f773fcf838215595db93760a66359acf77a19f63758447a9f30498be90dcce079a2ba21e2ce3350f2b6295e3906b3bb3ea3b5472f0804965b6003e61d94460d
|
data/.github/workflows/test.yml
CHANGED
@@ -7,30 +7,58 @@ jobs:
|
|
7
7
|
fail-fast: false
|
8
8
|
matrix:
|
9
9
|
elasticsearch:
|
10
|
-
- plainpicture/elasticsearch:2.4.1_delete-by-query
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
|
10
|
+
- image: plainpicture/elasticsearch:2.4.1_delete-by-query
|
11
|
+
env:
|
12
|
+
discovery.type: single-node
|
13
|
+
xpack.security.enabled: false
|
14
|
+
- image: elasticsearch:5.4
|
15
|
+
env:
|
16
|
+
discovery.type: single-node
|
17
|
+
xpack.security.enabled: false
|
18
|
+
- image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
|
19
|
+
env:
|
20
|
+
discovery.type: single-node
|
21
|
+
xpack.security.enabled: false
|
22
|
+
- image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0
|
23
|
+
env:
|
24
|
+
discovery.type: single-node
|
25
|
+
xpack.security.enabled: false
|
26
|
+
- image: docker.elastic.co/elasticsearch/elasticsearch:7.11.2
|
27
|
+
env:
|
28
|
+
discovery.type: single-node
|
29
|
+
xpack.security.enabled: false
|
30
|
+
- image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
|
31
|
+
env:
|
32
|
+
discovery.type: single-node
|
33
|
+
xpack.security.enabled: false
|
34
|
+
- image: opensearchproject/opensearch:1.3.14
|
35
|
+
env:
|
36
|
+
discovery.type: single-node
|
37
|
+
plugins.security.disabled: true
|
38
|
+
- image: opensearchproject/opensearch:2.11.1
|
39
|
+
env:
|
40
|
+
discovery.type: single-node
|
41
|
+
plugins.security.disabled: true
|
42
|
+
- image: opensearchproject/opensearch:2.13.0
|
43
|
+
env:
|
44
|
+
discovery.type: single-node
|
45
|
+
DISABLE_SECURITY_PLUGIN: true
|
16
46
|
ruby:
|
17
|
-
- 2.6
|
18
47
|
- 2.7
|
19
48
|
- 3.0
|
49
|
+
- 3.1
|
50
|
+
- 3.2
|
20
51
|
services:
|
21
52
|
elasticsearch:
|
22
|
-
image: ${{ matrix.elasticsearch }}
|
23
|
-
env:
|
24
|
-
discovery.type: single-node
|
25
|
-
xpack.security.enabled: false
|
53
|
+
image: ${{ matrix.elasticsearch.image }}
|
54
|
+
env: ${{ matrix.elasticsearch.env }}
|
26
55
|
ports:
|
27
56
|
- 9200:9200
|
28
57
|
steps:
|
29
58
|
- uses: actions/checkout@v1
|
30
|
-
- uses:
|
59
|
+
- uses: ruby/setup-ruby@v1
|
31
60
|
with:
|
32
61
|
ruby-version: ${{ matrix.ruby }}
|
33
|
-
- run: gem install bundler
|
34
62
|
- run: bundle
|
35
63
|
- run: bundle exec rspec
|
36
64
|
- run: bundle exec rubocop
|
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,23 @@
|
|
11
11
|
* Added `SearchFlip::Connection#get_cluster_settings` and
|
12
12
|
`#update_cluster_settings`
|
13
13
|
|
14
|
+
## v3.9.0
|
15
|
+
|
16
|
+
* Allow to configure the elasticsearch version no matter which elasticsearch
|
17
|
+
version is actually in use. The version information is needed to support
|
18
|
+
version dependent features. Please note that manually configuring the version
|
19
|
+
is usually not need as the version by default is determined by sending one
|
20
|
+
request to elasticsearch.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
SearchFlip::Config[:version] = { number: "8.1.1" }
|
24
|
+
SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
|
25
|
+
```
|
26
|
+
|
27
|
+
## v3.8.0
|
28
|
+
|
29
|
+
* Support Opensearch 1.x and 2.x
|
30
|
+
|
14
31
|
## v3.7.2
|
15
32
|
|
16
33
|
* Fix wrong AWS signatures by generating the json before passing it to http-rb
|
data/Gemfile
CHANGED
@@ -2,4 +2,18 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
|
6
|
+
gem "activerecord", ">= 3.0", "< 5"
|
7
|
+
else
|
8
|
+
gem "activerecord", ">= 3.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "aws-sdk-core"
|
12
|
+
gem "bundler"
|
13
|
+
gem "factory_bot"
|
14
|
+
gem "rake"
|
15
|
+
gem "rspec"
|
16
|
+
gem "rubocop"
|
17
|
+
gem "sqlite3", "~> 1.4"
|
18
|
+
gem "timecop"
|
19
|
+
gem "webmock"
|
data/README.md
CHANGED
@@ -9,8 +9,9 @@
|
|
9
9
|
Using SearchFlip it is dead-simple to create index classes that correspond to
|
10
10
|
[Elasticsearch](https://www.elastic.co/) indices and to manipulate, query and
|
11
11
|
aggregate these indices using a chainable, concise, yet powerful DSL. Finally,
|
12
|
-
SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x and 8.x
|
13
|
-
[Feature Support](#feature-support) for
|
12
|
+
SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x and 8.x as well as
|
13
|
+
Opensearch 1.x and 2.x. Check section [Feature Support](#feature-support) for
|
14
|
+
version dependent features.
|
14
15
|
|
15
16
|
```ruby
|
16
17
|
CommentIndex.search("hello world", default_field: "title").where(visible: true).aggregate(:user_id).sort(id: "desc")
|
@@ -97,6 +98,16 @@ Available config options are:
|
|
97
98
|
* `auto_refresh` tells SearchFlip to automatically refresh an index after
|
98
99
|
import, index, delete, etc operations. This is e.g. useful for testing, etc.
|
99
100
|
Defaults to false.
|
101
|
+
* `version` allows to configure the elasticsearch version no matter which
|
102
|
+
elasticsearch version is actually in use. The version information is needed to
|
103
|
+
support version dependent features. Please note that manually configuring the
|
104
|
+
version is usually not need as the version by default is determined by sending
|
105
|
+
one request to elasticsearch.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
SearchFlip::Config[:version] = { number: "8.1.1" }
|
109
|
+
SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
|
110
|
+
```
|
100
111
|
|
101
112
|
## Usage
|
102
113
|
|
@@ -852,7 +863,7 @@ performance tracing, etc.
|
|
852
863
|
To use instrumentation, configure the instrumenter:
|
853
864
|
|
854
865
|
```ruby
|
855
|
-
SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications
|
866
|
+
SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications
|
856
867
|
```
|
857
868
|
|
858
869
|
Subsequently, you can subscribe to notifcations for `request.search_flip`:
|
@@ -970,7 +981,6 @@ SearchFlip is using Semantic Versioning: [SemVer](http://semver.org/)
|
|
970
981
|
|
971
982
|
* Elasticsearch: [https://www.elastic.co/](https://www.elastic.co/)
|
972
983
|
* Reference Docs: [http://www.rubydoc.info/github/mrkamel/search_flip](http://www.rubydoc.info/github/mrkamel/search_flip)
|
973
|
-
* Travis: [http://travis-ci.org/mrkamel/search_flip](http://travis-ci.org/mrkamel/search_flip)
|
974
984
|
* will_paginate: [https://github.com/mislav/will_paginate](https://github.com/mislav/will_paginate)
|
975
985
|
* kaminari: [https://github.com/kaminari/kaminari](https://github.com/kaminari/kaminari)
|
976
986
|
* Oj: [https://github.com/ohler55/oj](https://github.com/ohler55/oj)
|
data/UPDATING.md
CHANGED
@@ -8,14 +8,14 @@ inherits `Hashie::Mash`
|
|
8
8
|
|
9
9
|
* It no longer supports symbol based access like `result[:id]`
|
10
10
|
|
11
|
-
|
11
|
+
3.x:
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
CommentIndex.match_all.results.first[:id]
|
15
15
|
CommentIndex.aggregate(:tags).aggregations(:tags).values.first[:doc_count]
|
16
16
|
```
|
17
17
|
|
18
|
-
|
18
|
+
4.x
|
19
19
|
|
20
20
|
```ruby
|
21
21
|
CommentIndex.match_all.results.first["id"] # or .id
|
@@ -24,16 +24,20 @@ CommentIndex.aggregate(:tags).aggregations(:tags).values.first["doc_count"] # or
|
|
24
24
|
|
25
25
|
* It no longer supports question mark methods like `result.title?`
|
26
26
|
|
27
|
-
|
27
|
+
3.x:
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
CommentIndex.match_all.results.first.is_published?
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
4.x
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
CommentIndex.match_all.results.first.is_published == true
|
37
|
+
|
38
|
+
# or
|
39
|
+
|
40
|
+
!! CommentIndex.match_all.results.first.is_published
|
37
41
|
```
|
38
42
|
|
39
43
|
* It no longer supports method based assignment like `result.some_key = "value"`.
|
@@ -30,7 +30,7 @@ module SearchFlip
|
|
30
30
|
res[:aggregations] = aggregation_values if aggregation_values
|
31
31
|
|
32
32
|
if must_values || must_not_values || filter_values
|
33
|
-
if target.connection.version.to_i >= 2
|
33
|
+
if target.connection.distribution || target.connection.version.to_i >= 2
|
34
34
|
res[:filter] = {
|
35
35
|
bool: {}
|
36
36
|
.merge(must_values ? { must: must_values } : {})
|
data/lib/search_flip/bulk.rb
CHANGED
@@ -16,7 +16,17 @@ module SearchFlip
|
|
16
16
|
@base_url = options[:base_url] || SearchFlip::Config[:base_url]
|
17
17
|
@http_client = options[:http_client] || SearchFlip::HTTPClient.new
|
18
18
|
@bulk_limit = options[:bulk_limit] || SearchFlip::Config[:bulk_limit]
|
19
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
# Queries and returns the Elasticsearch distribution used.
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# connection.distribution # => e.g. "opensearch"
|
25
|
+
#
|
26
|
+
# @return [String] The Elasticsearch distribution
|
27
|
+
|
28
|
+
def distribution
|
29
|
+
@distribution ||= SearchFlip::Config.dig(:version, :distribution) || SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
|
20
30
|
end
|
21
31
|
|
22
32
|
# Queries the cluster settings from Elasticsearch
|
@@ -51,18 +61,12 @@ module SearchFlip
|
|
51
61
|
# Queries and returns the Elasticsearch version used.
|
52
62
|
#
|
53
63
|
# @example
|
54
|
-
# connection.version # => e.g. 2.4.1
|
64
|
+
# connection.version # => e.g. "2.4.1"
|
55
65
|
#
|
56
66
|
# @return [String] The Elasticsearch version
|
57
67
|
|
58
68
|
def version
|
59
|
-
@
|
60
|
-
@version ||= begin
|
61
|
-
response = http_client.headers(accept: "application/json").get("#{base_url}/")
|
62
|
-
|
63
|
-
SearchFlip::JSON.parse(response.to_s)["version"]["number"]
|
64
|
-
end
|
65
|
-
end
|
69
|
+
@version ||= SearchFlip::Config.dig(:version, :number) || SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
|
66
70
|
end
|
67
71
|
|
68
72
|
# Queries and returns the Elasticsearch cluster health.
|
@@ -93,7 +97,7 @@ module SearchFlip
|
|
93
97
|
def msearch(criterias)
|
94
98
|
payload = criterias.flat_map do |criteria|
|
95
99
|
[
|
96
|
-
SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(version.to_i < 8 ? { type: criteria.target.type_name } : {})),
|
100
|
+
SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(distribution.nil? && version.to_i < 8 ? { type: criteria.target.type_name } : {})),
|
97
101
|
SearchFlip::JSON.generate(criteria.request)
|
98
102
|
]
|
99
103
|
end
|
@@ -329,8 +333,8 @@ module SearchFlip
|
|
329
333
|
# @return [Boolean] Returns true or raises SearchFlip::ResponseError
|
330
334
|
|
331
335
|
def update_mapping(index_name, mapping, type_name: nil)
|
332
|
-
url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
333
|
-
params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
336
|
+
url = type_name && distribution.nil? && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
337
|
+
params = type_name && distribution.nil? && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
334
338
|
|
335
339
|
http_client.put("#{url}/_mapping", params: params, json: mapping)
|
336
340
|
|
@@ -347,8 +351,8 @@ module SearchFlip
|
|
347
351
|
# @return [Hash] The current type mapping
|
348
352
|
|
349
353
|
def get_mapping(index_name, type_name: nil)
|
350
|
-
url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
351
|
-
params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
354
|
+
url = type_name && distribution.nil? && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
355
|
+
params = type_name && distribution.nil? && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
352
356
|
|
353
357
|
response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
|
354
358
|
|
@@ -451,5 +455,11 @@ module SearchFlip
|
|
451
455
|
def index_url(index_name)
|
452
456
|
"#{base_url}/#{index_name}"
|
453
457
|
end
|
458
|
+
|
459
|
+
private
|
460
|
+
|
461
|
+
def version_response
|
462
|
+
@version_response ||= http_client.headers(accept: "application/json").get("#{base_url}/")
|
463
|
+
end
|
454
464
|
end
|
455
465
|
end
|
data/lib/search_flip/criteria.rb
CHANGED
@@ -350,8 +350,8 @@ module SearchFlip
|
|
350
350
|
http_request = connection.http_client
|
351
351
|
http_request = http_request.timeout(http_timeout_value) if http_timeout_value
|
352
352
|
|
353
|
-
if connection.version.to_i >= 5
|
354
|
-
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
353
|
+
if connection.distribution || connection.version.to_i >= 5
|
354
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
|
355
355
|
|
356
356
|
http_request.post("#{url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
|
357
357
|
else
|
@@ -622,7 +622,7 @@ module SearchFlip
|
|
622
622
|
json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] }
|
623
623
|
)
|
624
624
|
elsif scroll_args
|
625
|
-
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
625
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
|
626
626
|
|
627
627
|
http_request.post(
|
628
628
|
"#{url}/_search",
|
@@ -630,7 +630,7 @@ module SearchFlip
|
|
630
630
|
json: request
|
631
631
|
)
|
632
632
|
else
|
633
|
-
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
633
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
|
634
634
|
|
635
635
|
http_request.post("#{url}/_search", params: request_params, json: request)
|
636
636
|
end
|
data/lib/search_flip/index.rb
CHANGED
@@ -438,7 +438,7 @@ module SearchFlip
|
|
438
438
|
# equal to _doc.
|
439
439
|
|
440
440
|
def include_type_name?
|
441
|
-
type_name != "_doc" || connection.version.to_i < 7
|
441
|
+
type_name != "_doc" || (connection.distribution.nil? && connection.version.to_i < 7)
|
442
442
|
end
|
443
443
|
|
444
444
|
# Retrieves the document specified by id from Elasticsearch. Raises
|
@@ -455,7 +455,7 @@ module SearchFlip
|
|
455
455
|
# @return [Hash] The specified document
|
456
456
|
|
457
457
|
def get(id, params = {})
|
458
|
-
url = connection.version.to_i < 8 ? type_url : "#{index_url}/_doc"
|
458
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : "#{index_url}/_doc"
|
459
459
|
response = connection.http_client.headers(accept: "application/json").get("#{url}/#{id}", params: params)
|
460
460
|
|
461
461
|
SearchFlip::JSON.parse(response.to_s)
|
@@ -474,7 +474,7 @@ module SearchFlip
|
|
474
474
|
# @return [Hash] The raw response
|
475
475
|
|
476
476
|
def mget(request, params = {})
|
477
|
-
url = connection.version.to_i < 8 ? type_url : index_url
|
477
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : index_url
|
478
478
|
response = connection.http_client.headers(accept: "application/json").post("#{url}/_mget", json: request, params: params)
|
479
479
|
|
480
480
|
SearchFlip::JSON.parse(response.to_s)
|
@@ -633,7 +633,7 @@ module SearchFlip
|
|
633
633
|
bulk_max_mb: connection.bulk_max_mb
|
634
634
|
}
|
635
635
|
|
636
|
-
url = connection.version.to_i < 8 ? type_url : index_url
|
636
|
+
url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : index_url
|
637
637
|
|
638
638
|
SearchFlip::Bulk.new("#{url}/_bulk", default_options.merge(options)) do |indexer|
|
639
639
|
yield indexer
|
data/lib/search_flip/json.rb
CHANGED
data/lib/search_flip/response.rb
CHANGED
@@ -223,7 +223,7 @@ module SearchFlip
|
|
223
223
|
|
224
224
|
def records
|
225
225
|
@records ||= begin
|
226
|
-
sort_map = ids.each_with_index.
|
226
|
+
sort_map = ids.each_with_index.with_object({}) { |(id, index), hash| hash[id.to_s] = index }
|
227
227
|
|
228
228
|
scope.to_a.sort_by { |record| sort_map[criteria.target.record_id(record).to_s] }
|
229
229
|
end
|
@@ -305,11 +305,11 @@ module SearchFlip
|
|
305
305
|
if response["aggregations"].nil? || response["aggregations"][key].nil?
|
306
306
|
SearchFlip::Result.new
|
307
307
|
elsif response["aggregations"][key]["buckets"].is_a?(Array)
|
308
|
-
response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] =
|
308
|
+
response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = bucket }
|
309
309
|
elsif response["aggregations"][key]["buckets"].is_a?(Hash)
|
310
|
-
|
310
|
+
response["aggregations"][key]["buckets"]
|
311
311
|
else
|
312
|
-
|
312
|
+
response["aggregations"][key]
|
313
313
|
end
|
314
314
|
end
|
315
315
|
end
|
data/lib/search_flip/result.rb
CHANGED
@@ -8,32 +8,6 @@ module SearchFlip
|
|
8
8
|
# result.some_key # => "value"
|
9
9
|
|
10
10
|
class Result < Hash
|
11
|
-
def self.convert(hash)
|
12
|
-
res = self[hash]
|
13
|
-
|
14
|
-
res.each do |key, value|
|
15
|
-
if value.is_a?(Hash)
|
16
|
-
res[key] = convert(value)
|
17
|
-
elsif value.is_a?(Array)
|
18
|
-
res[key] = convert_array(value)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
res
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.convert_array(arr)
|
26
|
-
arr.map do |obj|
|
27
|
-
if obj.is_a?(Hash)
|
28
|
-
convert(obj)
|
29
|
-
elsif obj.is_a?(Array)
|
30
|
-
convert_array(obj)
|
31
|
-
else
|
32
|
-
obj
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
11
|
def method_missing(name, *args, &block)
|
38
12
|
self[name.to_s]
|
39
13
|
end
|
@@ -43,8 +17,8 @@ module SearchFlip
|
|
43
17
|
end
|
44
18
|
|
45
19
|
def self.from_hit(hit)
|
46
|
-
res =
|
47
|
-
res["_hit"] =
|
20
|
+
res = self[hit["_source"] || {}]
|
21
|
+
res["_hit"] = self[hit].tap { |hash| hash.delete("_source") }
|
48
22
|
res
|
49
23
|
end
|
50
24
|
end
|
data/lib/search_flip/version.rb
CHANGED
data/search_flip.gemspec
CHANGED
@@ -13,6 +13,10 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/mrkamel/search_flip"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/mrkamel/search_flip"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/mrkamel/search_flip/blob/master/CHANGELOG.md"
|
19
|
+
|
16
20
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
22
|
spec.require_paths = ["lib"]
|
@@ -23,17 +27,6 @@ Gem::Specification.new do |spec|
|
|
23
27
|
https://github.com/mrkamel/search_flip/blob/master/UPDATING.md
|
24
28
|
MESSAGE
|
25
29
|
|
26
|
-
spec.add_development_dependency "activerecord", ">= 3.0"
|
27
|
-
spec.add_development_dependency "aws-sdk-core"
|
28
|
-
spec.add_development_dependency "bundler"
|
29
|
-
spec.add_development_dependency "factory_bot"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_development_dependency "rspec"
|
32
|
-
spec.add_development_dependency "rubocop"
|
33
|
-
spec.add_development_dependency "sqlite3"
|
34
|
-
spec.add_development_dependency "timecop"
|
35
|
-
spec.add_development_dependency "webmock"
|
36
|
-
|
37
30
|
spec.add_dependency "http"
|
38
31
|
spec.add_dependency "json"
|
39
32
|
spec.add_dependency "oj"
|
@@ -60,7 +60,7 @@ RSpec.describe SearchFlip::Bulk do
|
|
60
60
|
|
61
61
|
it "uses the specified http_client" do
|
62
62
|
product = create(:product)
|
63
|
-
url = ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url
|
63
|
+
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url
|
64
64
|
|
65
65
|
stub_request(:put, "#{url}/_bulk").with(headers: { "X-Header" => "Value" }).to_return(status: 200, body: "{}")
|
66
66
|
|
@@ -1,10 +1,32 @@
|
|
1
1
|
require File.expand_path("../spec_helper", __dir__)
|
2
2
|
|
3
3
|
RSpec.describe SearchFlip::Connection do
|
4
|
+
describe "#distribution" do
|
5
|
+
it "reutrns the distribution" do
|
6
|
+
expect([nil, "opensearch"]).to include(SearchFlip::Connection.new.distribution)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the distribution from the config when given" do
|
10
|
+
SearchFlip::Config[:version] = { distribution: "distribution" }
|
11
|
+
|
12
|
+
expect(SearchFlip::Connection.new.distribution).to eq("distribution")
|
13
|
+
ensure
|
14
|
+
SearchFlip::Config.delete(:version)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
describe "#version" do
|
5
19
|
it "returns the version" do
|
6
20
|
expect(SearchFlip::Connection.new.version).to match(/\A[0-9.]+\z/)
|
7
21
|
end
|
22
|
+
|
23
|
+
it "returns the version from the config when given" do
|
24
|
+
SearchFlip::Config[:version] = { number: "1.2.3" }
|
25
|
+
|
26
|
+
expect(SearchFlip::Connection.new.version).to eq("1.2.3")
|
27
|
+
ensure
|
28
|
+
SearchFlip::Config.delete(:version)
|
29
|
+
end
|
8
30
|
end
|
9
31
|
|
10
32
|
describe "#cluster_health" do
|
@@ -29,11 +51,11 @@ RSpec.describe SearchFlip::Connection do
|
|
29
51
|
let(:connection) { SearchFlip::Connection.new }
|
30
52
|
|
31
53
|
after do
|
32
|
-
connection.update_cluster_settings(persistent: { action: { auto_create_index: false } }) if connection.version.to_i > 2
|
54
|
+
connection.update_cluster_settings(persistent: { action: { auto_create_index: false } }) if connection.distribution || connection.version.to_i > 2
|
33
55
|
end
|
34
56
|
|
35
57
|
it "updates the cluster settings" do
|
36
|
-
if connection.version.to_i > 2
|
58
|
+
if connection.distribution || connection.version.to_i > 2
|
37
59
|
connection.update_cluster_settings(persistent: { action: { auto_create_index: false } })
|
38
60
|
connection.update_cluster_settings(persistent: { action: { auto_create_index: true } })
|
39
61
|
|
@@ -42,7 +64,7 @@ RSpec.describe SearchFlip::Connection do
|
|
42
64
|
end
|
43
65
|
|
44
66
|
it "returns true" do
|
45
|
-
if connection.version.to_i > 2
|
67
|
+
if connection.distribution || connection.version.to_i > 2
|
46
68
|
expect(connection.update_cluster_settings(persistent: { action: { auto_create_index: false } })).to eq(true)
|
47
69
|
end
|
48
70
|
end
|
@@ -121,7 +143,7 @@ RSpec.describe SearchFlip::Connection do
|
|
121
143
|
it "returns the specified indices" do
|
122
144
|
connection = SearchFlip::Connection.new
|
123
145
|
|
124
|
-
expect(connection.get_indices.map { |index| index["index"] }.to_set).to eq(["comments", "products"].to_set)
|
146
|
+
expect(connection.get_indices.map { |index| index["index"] }.grep_v(/^\./).to_set).to eq(["comments", "products"].to_set)
|
125
147
|
expect(connection.get_indices("com*").map { |index| index["index"] }).to eq(["comments"])
|
126
148
|
end
|
127
149
|
|
@@ -199,7 +221,7 @@ RSpec.describe SearchFlip::Connection do
|
|
199
221
|
it "freezes the specified index" do
|
200
222
|
connection = SearchFlip::Connection.new
|
201
223
|
|
202
|
-
if connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
224
|
+
if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
203
225
|
begin
|
204
226
|
connection.create_index("index_name")
|
205
227
|
connection.freeze_index("index_name")
|
@@ -216,7 +238,7 @@ RSpec.describe SearchFlip::Connection do
|
|
216
238
|
it "unfreezes the specified index" do
|
217
239
|
connection = SearchFlip::Connection.new
|
218
240
|
|
219
|
-
if connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
241
|
+
if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
220
242
|
begin
|
221
243
|
connection.create_index("index_name")
|
222
244
|
connection.freeze_index("index_name")
|
@@ -270,7 +292,7 @@ RSpec.describe SearchFlip::Connection do
|
|
270
292
|
end
|
271
293
|
|
272
294
|
describe "#update_mapping" do
|
273
|
-
if SearchFlip::Connection.new.version.to_i >= 7
|
295
|
+
if SearchFlip::Connection.new.then { |connection| connection.distribution || connection.version.to_i >= 7 }
|
274
296
|
it "updates the mapping of an index without type name" do
|
275
297
|
begin
|
276
298
|
connection = SearchFlip::Connection.new
|
@@ -295,7 +317,7 @@ RSpec.describe SearchFlip::Connection do
|
|
295
317
|
|
296
318
|
connection.create_index("index_name")
|
297
319
|
|
298
|
-
if connection.version.to_i < 8
|
320
|
+
if connection.distribution.nil? && connection.version.to_i < 8
|
299
321
|
connection.update_mapping("index_name", { "type_name" => mapping }, type_name: "type_name")
|
300
322
|
|
301
323
|
expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => { "type_name" => mapping } })
|
@@ -350,9 +372,9 @@ RSpec.describe SearchFlip::Connection do
|
|
350
372
|
|
351
373
|
bulk = proc do
|
352
374
|
connection.bulk do |indexer|
|
353
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
354
|
-
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
355
|
-
indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
|
375
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
376
|
+
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
377
|
+
indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
|
356
378
|
end
|
357
379
|
end
|
358
380
|
|
@@ -375,14 +397,14 @@ RSpec.describe SearchFlip::Connection do
|
|
375
397
|
connection = SearchFlip::Connection.new
|
376
398
|
|
377
399
|
connection.bulk do |indexer|
|
378
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
379
|
-
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
400
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
401
|
+
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
380
402
|
end
|
381
403
|
|
382
404
|
bulk = proc do
|
383
405
|
connection.bulk do |indexer|
|
384
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
385
|
-
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
406
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
407
|
+
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
386
408
|
end
|
387
409
|
end
|
388
410
|
|
@@ -390,8 +412,8 @@ RSpec.describe SearchFlip::Connection do
|
|
390
412
|
|
391
413
|
bulk = proc do
|
392
414
|
connection.bulk ignore_errors: [409] do |indexer|
|
393
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
394
|
-
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
415
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
416
|
+
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
395
417
|
end
|
396
418
|
end
|
397
419
|
|
@@ -404,7 +426,7 @@ RSpec.describe SearchFlip::Connection do
|
|
404
426
|
connection = SearchFlip::Connection.new
|
405
427
|
|
406
428
|
connection.bulk do |indexer|
|
407
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
429
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
408
430
|
end
|
409
431
|
|
410
432
|
expect(SearchFlip::Bulk).to have_received(:new).with(
|
@@ -427,7 +449,7 @@ RSpec.describe SearchFlip::Connection do
|
|
427
449
|
}
|
428
450
|
|
429
451
|
connection.bulk(options) do |indexer|
|
430
|
-
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
452
|
+
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
|
431
453
|
end
|
432
454
|
|
433
455
|
expect(SearchFlip::Bulk).to have_received(:new).with(anything, options)
|
@@ -435,7 +435,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
435
435
|
|
436
436
|
describe "#match_none" do
|
437
437
|
it "does not match any documents" do
|
438
|
-
if ProductIndex.connection.version.to_i >= 5
|
438
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
|
439
439
|
ProductIndex.import create(:product)
|
440
440
|
|
441
441
|
query = ProductIndex.match_none
|
@@ -479,7 +479,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
479
479
|
|
480
480
|
describe "#post_search" do
|
481
481
|
it "sets up the constraints correctly and is chainable" do
|
482
|
-
if ProductIndex.connection.version.to_i >= 2
|
482
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 2
|
483
483
|
product1 = create(:product, title: "title1", category: "category1")
|
484
484
|
product2 = create(:product, title: "title2", category: "category2")
|
485
485
|
product3 = create(:product, title: "title3", category: "category1")
|
@@ -886,7 +886,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
886
886
|
|
887
887
|
describe "#profile" do
|
888
888
|
it "sets up the constraints correctly" do
|
889
|
-
if ProductIndex.connection.version.to_i >= 2
|
889
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 2
|
890
890
|
expect(ProductIndex.profile(true).raw_response["profile"]).not_to be_nil
|
891
891
|
end
|
892
892
|
end
|
@@ -1322,7 +1322,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
1322
1322
|
|
1323
1323
|
describe "#track_total_hits" do
|
1324
1324
|
it "is added to the request" do
|
1325
|
-
if ProductIndex.connection.version.to_i >= 7
|
1325
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 7
|
1326
1326
|
query = ProductIndex.track_total_hits(false)
|
1327
1327
|
|
1328
1328
|
expect(query.request[:track_total_hits]).to eq(false)
|
@@ -1350,7 +1350,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
1350
1350
|
|
1351
1351
|
describe "#preference" do
|
1352
1352
|
it "sets the preference" do
|
1353
|
-
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1353
|
+
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1354
1354
|
|
1355
1355
|
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?preference=value")
|
1356
1356
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
@@ -1363,7 +1363,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
1363
1363
|
|
1364
1364
|
describe "#search_type" do
|
1365
1365
|
it "sets the search_type" do
|
1366
|
-
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1366
|
+
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1367
1367
|
|
1368
1368
|
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?search_type=value")
|
1369
1369
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
@@ -1376,7 +1376,7 @@ RSpec.describe SearchFlip::Criteria do
|
|
1376
1376
|
|
1377
1377
|
describe "#routing" do
|
1378
1378
|
it "sets the search_type" do
|
1379
|
-
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1379
|
+
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
1380
1380
|
|
1381
1381
|
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?routing=value")
|
1382
1382
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
@@ -77,7 +77,7 @@ RSpec.describe SearchFlip::Index do
|
|
77
77
|
include SearchFlip::Index
|
78
78
|
end
|
79
79
|
|
80
|
-
expect(klass.include_type_name?).to eq(klass.connection.version.to_i < 7)
|
80
|
+
expect(klass.include_type_name?).to eq(klass.connection.distribution.nil? && klass.connection.version.to_i < 7)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "returns true if the type name is not equal to _doc" do
|
@@ -185,7 +185,7 @@ RSpec.describe SearchFlip::Index do
|
|
185
185
|
end
|
186
186
|
|
187
187
|
describe ".update_mapping" do
|
188
|
-
if TestIndex.connection.version.to_i >= 7
|
188
|
+
if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
|
189
189
|
context "without type name" do
|
190
190
|
it "delegates to connection" do
|
191
191
|
TestIndex.create_index
|
@@ -215,7 +215,7 @@ RSpec.describe SearchFlip::Index do
|
|
215
215
|
|
216
216
|
TestIndex.update_mapping
|
217
217
|
|
218
|
-
if TestIndex.connection.version.to_i < 8
|
218
|
+
if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
|
219
219
|
expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
|
220
220
|
else
|
221
221
|
expect(TestIndex.connection).to have_received(:update_mapping).with("test", mapping)
|
@@ -245,7 +245,7 @@ RSpec.describe SearchFlip::Index do
|
|
245
245
|
end
|
246
246
|
|
247
247
|
describe ".get_mapping" do
|
248
|
-
if TestIndex.connection.version.to_i >= 7
|
248
|
+
if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
|
249
249
|
context "without type name" do
|
250
250
|
it "delegates to connection" do
|
251
251
|
allow(TestIndex).to receive(:include_type_name?).and_return(false)
|
@@ -272,7 +272,7 @@ RSpec.describe SearchFlip::Index do
|
|
272
272
|
|
273
273
|
TestIndex.get_mapping
|
274
274
|
|
275
|
-
if TestIndex.connection.version.to_i < 8
|
275
|
+
if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
|
276
276
|
expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
|
277
277
|
else
|
278
278
|
expect(TestIndex.connection).to have_received(:get_mapping).with("test")
|
@@ -340,7 +340,7 @@ RSpec.describe SearchFlip::Index do
|
|
340
340
|
|
341
341
|
TestIndex.type_url
|
342
342
|
|
343
|
-
expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
|
343
|
+
expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
@@ -433,7 +433,7 @@ RSpec.describe SearchFlip::Index do
|
|
433
433
|
|
434
434
|
products = create_list(:product, 2)
|
435
435
|
|
436
|
-
if ProductIndex.connection.version.to_i >= 5
|
436
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
|
437
437
|
expect { ProductIndex.create products, {}, routing: "r1" }.to(change { ProductIndex.total_count }.by(2))
|
438
438
|
|
439
439
|
expect(ProductIndex.get(products.first.id, routing: "r1")["_routing"]).to eq("r1")
|
@@ -447,7 +447,7 @@ RSpec.describe SearchFlip::Index do
|
|
447
447
|
it "allows respects class options" do
|
448
448
|
products = create_list(:product, 2)
|
449
449
|
|
450
|
-
if ProductIndex.connection.version.to_i >= 5
|
450
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
|
451
451
|
allow(ProductIndex).to receive(:index_options).and_return(routing: "r1")
|
452
452
|
|
453
453
|
expect { ProductIndex.create products }.to(change { ProductIndex.total_count }.by(2))
|
@@ -82,7 +82,7 @@ RSpec.describe SearchFlip::Response do
|
|
82
82
|
|
83
83
|
ProductIndex.import products
|
84
84
|
|
85
|
-
expect(ProductIndex.match_all.results.
|
85
|
+
expect(ProductIndex.match_all.results.to_set(&:id)).to eq(products.to_set(&:id))
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -126,7 +126,7 @@ RSpec.describe SearchFlip::Response do
|
|
126
126
|
|
127
127
|
response = ProductIndex.match_all.response
|
128
128
|
|
129
|
-
expect(response.ids.to_set).to eq(products.map(&:id).
|
129
|
+
expect(response.ids.to_set).to eq(products.map(&:id).to_set(&:to_s))
|
130
130
|
expect(response.ids).to eq(response.raw_response["hits"]["hits"].map { |hit| hit["_id"] })
|
131
131
|
end
|
132
132
|
end
|
@@ -1,26 +1,17 @@
|
|
1
1
|
require File.expand_path("../spec_helper", __dir__)
|
2
2
|
|
3
3
|
RSpec.describe SearchFlip::Result do
|
4
|
-
describe ".convert" do
|
5
|
-
it "deeply converts hashes and arrays" do
|
6
|
-
result = described_class.convert("parent" => { "child" => [{ "key1" => "value" }, { "key2" => 3 }] })
|
7
|
-
|
8
|
-
expect(result.parent.child[0].key1).to eq("value")
|
9
|
-
expect(result.parent.child[1].key2).to eq(3)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
4
|
describe "#method_missing" do
|
14
5
|
it "returns the value of the key equal to the message name" do
|
15
|
-
expect(described_class
|
6
|
+
expect(described_class["some_key" => "value"].some_key).to eq("value")
|
16
7
|
expect(described_class.new.some_key).to be_nil
|
17
8
|
end
|
18
9
|
end
|
19
10
|
|
20
11
|
describe "#responds_to_missing?" do
|
21
12
|
it "returns true/false if the key equal to the message name is present or not" do
|
22
|
-
expect(described_class
|
23
|
-
expect(described_class
|
13
|
+
expect(described_class["some_key" => nil].respond_to?(:some_key)).to eq(true)
|
14
|
+
expect(described_class["some_key" => nil].respond_to?(:other_key)).to eq(false)
|
24
15
|
end
|
25
16
|
end
|
26
17
|
|
data/spec/spec_helper.rb
CHANGED
@@ -86,7 +86,7 @@ class CommentIndex
|
|
86
86
|
include SearchFlip::Index
|
87
87
|
|
88
88
|
def self.type_name
|
89
|
-
connection.version.to_i < 8 ? "comments" : "_doc"
|
89
|
+
connection.distribution.nil? && connection.version.to_i < 8 ? "comments" : "_doc"
|
90
90
|
end
|
91
91
|
|
92
92
|
def self.index_name
|
@@ -113,7 +113,7 @@ class ProductIndex
|
|
113
113
|
include SearchFlip::Index
|
114
114
|
|
115
115
|
def self.mapping
|
116
|
-
if ProductIndex.connection.version.to_i >= 5
|
116
|
+
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
|
117
117
|
{
|
118
118
|
properties: {
|
119
119
|
category: {
|
@@ -136,7 +136,7 @@ class ProductIndex
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def self.type_name
|
139
|
-
connection.version.to_i < 8 ? "products" : "_doc"
|
139
|
+
connection.distribution.nil? && connection.version.to_i < 8 ? "products" : "_doc"
|
140
140
|
end
|
141
141
|
|
142
142
|
def self.index_name
|
@@ -177,7 +177,7 @@ class TestIndex
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def self.type_name
|
180
|
-
connection.version.to_i < 8 ? "test" : "_doc"
|
180
|
+
connection.distribution.nil? && connection.version.to_i < 8 ? "test" : "_doc"
|
181
181
|
end
|
182
182
|
|
183
183
|
def self.index_name
|
metadata
CHANGED
@@ -1,155 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.beta15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activerecord
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws-sdk-core
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: factory_bot
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: sqlite3
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: timecop
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: webmock
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
13
|
- !ruby/object:Gem::Dependency
|
154
14
|
name: http
|
155
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,7 +128,10 @@ files:
|
|
268
128
|
homepage: https://github.com/mrkamel/search_flip
|
269
129
|
licenses:
|
270
130
|
- MIT
|
271
|
-
metadata:
|
131
|
+
metadata:
|
132
|
+
homepage_uri: https://github.com/mrkamel/search_flip
|
133
|
+
source_code_uri: https://github.com/mrkamel/search_flip
|
134
|
+
changelog_uri: https://github.com/mrkamel/search_flip/blob/master/CHANGELOG.md
|
272
135
|
post_install_message: |
|
273
136
|
Thanks for using search_flip!
|
274
137
|
When upgrading major versions, please check out
|