search_flip 3.0.0.beta → 3.0.0.beta1
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/lib/search_flip/filterable.rb +12 -3
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/criteria_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed1af68a35f862ad7a429b646afeab420d78161b29e8833daf3a2e37048cb26
|
4
|
+
data.tar.gz: 499dfeffd4abd5b21fc966b6d04b61130fe6bf1ffb771b3d97f92e4473592701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c1a401732c4ee47aa7e23e750496afa445e274c7fed20f28c27dbf136e2f795123cb805bc9f3513c26be1f2330ed6a0f82da145a4110e8c35858c951d3a8297
|
7
|
+
data.tar.gz: 61ffd4396bb2e3c4372fd5389ffdff0b695dbc80a74c1439855cb7e8fb7f8fe4c6d1aab127d22bc789485427d43f5dad0835c8325c575c295d82a4de5235893d
|
@@ -151,14 +151,23 @@ module SearchFlip
|
|
151
151
|
# CommentIndex.where(state: "new").search("text").to_query
|
152
152
|
# # => {:bool=>{:filter=>[{:term=>{:state=>"new"}}], :must=>[{:query_string=>{:query=>"text", ...}}]}}
|
153
153
|
#
|
154
|
+
# CommentIndex.must(term: { state: "new" }).to_query
|
155
|
+
# # => {:term=>{:state=>"new"}}
|
156
|
+
#
|
154
157
|
# @return [Hash] The raw query
|
155
158
|
|
156
159
|
def to_query
|
160
|
+
must_clauses = must_values.to_a
|
161
|
+
must_not_clauses = must_not_values.to_a + post_must_not_values.to_a
|
162
|
+
filter_clauses = post_must_values.to_a + filter_values.to_a + post_filter_values.to_a
|
163
|
+
|
164
|
+
return must_clauses.first if must_clauses.size == 1 && must_not_clauses.empty? && filter_clauses.empty?
|
165
|
+
|
157
166
|
{
|
158
167
|
bool: {
|
159
|
-
must:
|
160
|
-
must_not:
|
161
|
-
filter:
|
168
|
+
must: must_clauses,
|
169
|
+
must_not: must_not_clauses,
|
170
|
+
filter: filter_clauses
|
162
171
|
}.reject { |_, value| value.empty? }
|
163
172
|
}
|
164
173
|
end
|
data/lib/search_flip/version.rb
CHANGED
@@ -35,6 +35,12 @@ RSpec.describe SearchFlip::Criteria do
|
|
35
35
|
)
|
36
36
|
end
|
37
37
|
|
38
|
+
it "returns only the must clause, if there is only a single must clause" do
|
39
|
+
query = ProductIndex.must(term: { category: "category" })
|
40
|
+
|
41
|
+
expect(query.to_query).to eq(term: { category: "category" })
|
42
|
+
end
|
43
|
+
|
38
44
|
it "generates an executable query for must, filter and must_not clauses" do
|
39
45
|
query =
|
40
46
|
ProductIndex
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|