elasticated 2.3.0 → 2.4.0

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: 0a8153fc5ed863fc035edd819e032298c140942d
4
- data.tar.gz: b92fbd97b92746e57982ae8d053214242986b239
3
+ metadata.gz: 0c21bce40f279a26bfc18215caed1f0e2869584d
4
+ data.tar.gz: b6b33eabf8cb3ea40a848b4ba012201c630c6b2b
5
5
  SHA512:
6
- metadata.gz: 3455584f5b597ec4c21df45378ee2f23f0694f6129bb40d0b3392bfba3e8efeeb4582f30ee636fc716bc2a72ede184b0b37e40af8665c3f78890279f00387b53
7
- data.tar.gz: eccb09df3c2ab43a38e795c7d063b4a36551652053f821be0304dfc3c60e5456e18b00f7d2a0e15986f8192c53e574e9876049d9fb309aa0f0299ae2db156e07
6
+ metadata.gz: 1f6b73bf87e1c6da918a9dcbe88ddec3f7cc2a0fa1dbe49133c3170908f58ecf095a197082846506b5dc8e23ef3be5cfd5be7f4a86bbf48f9196f98d6f3d2fd6
7
+ data.tar.gz: 51fdff057ce01cce2113d448c7426ec89fb0304e76b7fe646f28071730118b17b5805e1779b0843f153200bcf24d9e0a54e0fc68973a3c8aeba548a2580e765e
@@ -53,16 +53,23 @@ module Elasticated
53
53
  end
54
54
  alias_method :offset, :from
55
55
 
56
- def sort(field, method=nil)
56
+ def custom_sort(custom_hash)
57
57
  self._sort ||= Array.new
58
- _sort << { field => { order: method || :asc } }
58
+ _sort << custom_hash
59
59
  self
60
60
  end
61
61
 
62
+ def sort(field, method=nil)
63
+ custom_sort(field => { order: method || :asc })
64
+ end
65
+ alias_method :sort_by_field, :sort
66
+
67
+ def sort_by_script(script_hash)
68
+ custom_sort(_script: script_hash)
69
+ end
70
+
62
71
  def sort_randomly
63
- self._sort ||= Array.new
64
- _sort << { _script: { script: "Math.random()", type: "number" } }
65
- self
72
+ sort_by_script(script: "Math.random()", type: "number")
66
73
  end
67
74
 
68
75
  def source(*fields_array)
data/lib/version.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  module Elasticated
2
- VERSION = '2.3.0'
2
+ VERSION = '2.4.0'
3
3
  end
4
4
 
5
5
  # Changelog
6
6
 
7
+ # 2.4.0
8
+ # Ahora se puede ordenar un search por un campo, script o hash custom
9
+
10
+ # 2.3.0
7
11
  # Ahora DateFieldDelimiter admite multiples fechas declaradas en un TermsCondition
8
12
 
9
13
  # 2.2.0
data/spec/query_spec.rb CHANGED
@@ -67,6 +67,16 @@ module Elasticated
67
67
 
68
68
  describe "the build method (over other fields)" do
69
69
 
70
+ it "should build a 'match_all' query sorted by a custom hash" do
71
+ my_custom_hash = { any_key: 'any_value' }
72
+ q.custom_sort(my_custom_hash)
73
+ expected_result = {
74
+ query: { match_all: {} },
75
+ sort: [my_custom_hash]
76
+ }
77
+ expect(q.build).to eq expected_result
78
+ end
79
+
70
80
  it "should build a 'match_all' query sorted by a single field" do
71
81
  q.sort :field
72
82
  expected_result = {
@@ -94,6 +104,16 @@ module Elasticated
94
104
  expect(q.build).to eq expected_result
95
105
  end
96
106
 
107
+ it "should build a 'match_all' query sorted by a custom script" do
108
+ my_script_hash = { script: "my_script", type: "my_type" }
109
+ q.sort_by_script(my_script_hash)
110
+ expected_result = {
111
+ query: { match_all: {} },
112
+ sort: [ { _script: my_script_hash } ]
113
+ }
114
+ expect(q.build).to eq expected_result
115
+ end
116
+
97
117
  it "should build a 'match_all' query sorted randomly" do
98
118
  q.sort_randomly
99
119
  expected_result = {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticated
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Fernandez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler