search_flip 3.0.0.beta → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f16c0308f14d764aab7fa477c8ba4169bf7d493e774cd8f435d8fa0ecd9ce991
4
- data.tar.gz: 7a91d1a23b846eb17466369d82ec5583b6346d237037cd12c0cd8e036df2498d
3
+ metadata.gz: 3ed1af68a35f862ad7a429b646afeab420d78161b29e8833daf3a2e37048cb26
4
+ data.tar.gz: 499dfeffd4abd5b21fc966b6d04b61130fe6bf1ffb771b3d97f92e4473592701
5
5
  SHA512:
6
- metadata.gz: e5ccd27acffd9cd2e91a66c3b4e99c9fb09d30d8c720785cedaf233ba314e28d2317c331fc7d63a29ef29d9951bd071d8ed849ffd0e3486e6890d428b3c94317
7
- data.tar.gz: a7f5b2f4969d7daa6aa578f4a31588b263f44f7e48aa4729bc820032923b804254cb0ad941dc961b8f36c508f07b27ef2ac7198802b02db2385cd1487b32cdc8
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: must_values.to_a,
160
- must_not: must_not_values.to_a + post_must_not_values.to_a,
161
- filter: post_must_values.to_a + filter_values.to_a + post_filter_values.to_a
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
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "3.0.0.beta"
2
+ VERSION = "3.0.0.beta1"
3
3
  end
@@ -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.beta
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-10 00:00:00.000000000 Z
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord