searchkick 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/searchkick/search.rb +1 -1
- data/lib/searchkick/version.rb +1 -1
- data/test/boost_test.rb +8 -0
- data/test/facets_test.rb +8 -2
- data/test/sql_test.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b43a0209f8d9f4e32f3c21c190ea82d5f2a0b4b
|
4
|
+
data.tar.gz: 016d4568bfd949ba047e6ce59024f795861f24d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76307b462984c715a68d9e0e71edd0139811a3274ad9682ad97034ac2ceb9f9b74b5094750a53ac8c449db5f1b4c5d6be6f5cdb22e1aa19a8b21fd7230f31798
|
7
|
+
data.tar.gz: 236fbf2c4e83877a03eed6728263b6af62094ee1139e88fd3ec86a4fd6da8269fcd2972f29f5bf2bafd3e667f7ee5ce40945509ea56c24f4d3746e4fed688be6
|
data/lib/searchkick/search.rb
CHANGED
@@ -3,7 +3,7 @@ module Searchkick
|
|
3
3
|
|
4
4
|
def search(term, options = {})
|
5
5
|
term = term.to_s
|
6
|
-
fields = options[:fields]
|
6
|
+
fields = options[:fields] ? options[:fields].map{|f| "#{f}.analyzed" } : ["_all"]
|
7
7
|
operator = options[:partial] ? "or" : "and"
|
8
8
|
load = options[:load].nil? ? true : options[:load]
|
9
9
|
load = (options[:include] ? {include: options[:include]} : true) if load
|
data/lib/searchkick/version.rb
CHANGED
data/test/boost_test.rb
CHANGED
@@ -38,4 +38,12 @@ class TestBoost < Minitest::Unit::TestCase
|
|
38
38
|
assert_order "zero", ["Zero Boost"], boost: "orders_count"
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_conversions_weight
|
42
|
+
store [
|
43
|
+
{name: "Product Boost", orders_count: 20},
|
44
|
+
{name: "Product Conversions", conversions: {"product" => 10}}
|
45
|
+
]
|
46
|
+
assert_order "product", ["Product Conversions", "Product Boost"], boost: "orders_count"
|
47
|
+
end
|
48
|
+
|
41
49
|
end
|
data/test/facets_test.rb
CHANGED
@@ -2,15 +2,21 @@ require_relative "test_helper"
|
|
2
2
|
|
3
3
|
class TestFacets < Minitest::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
5
|
+
def setup
|
6
|
+
super
|
6
7
|
store [
|
7
8
|
{name: "Product Show", store_id: 1, in_stock: true, color: "blue"},
|
8
9
|
{name: "Product Hide", store_id: 2, in_stock: false, color: "green"},
|
9
10
|
{name: "Product B", store_id: 2, in_stock: false, color: "red"}
|
10
11
|
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_basic
|
11
15
|
assert_equal 2, Product.search("Product", facets: [:store_id]).facets["store_id"]["terms"].size
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_where
|
12
19
|
assert_equal 1, Product.search("Product", facets: {store_id: {where: {in_stock: true}}}).facets["store_id"]["terms"].size
|
13
|
-
assert_equal 1, Product.search("Product", facets: {store_id: {where: {in_stock: true, color: "blue"}}}).facets["store_id"]["terms"].size
|
14
20
|
end
|
15
21
|
|
16
22
|
end
|
data/test/sql_test.rb
CHANGED
@@ -4,22 +4,22 @@ class TestSql < Minitest::Unit::TestCase
|
|
4
4
|
|
5
5
|
def test_limit
|
6
6
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
7
|
-
|
7
|
+
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_offset
|
11
11
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
12
|
-
|
12
|
+
assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_pagination
|
16
16
|
store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
|
17
|
-
|
17
|
+
assert_order "product", ["Product C", "Product D"], order: {name: :asc}, page: 2, per_page: 2
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_pagination_nil_page
|
21
21
|
store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
|
22
|
-
|
22
|
+
assert_order "product", ["Product A", "Product B"], order: {name: :asc}, page: nil, per_page: 2
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_where
|
@@ -59,12 +59,12 @@ class TestSql < Minitest::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_order_hash
|
61
61
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
62
|
-
|
62
|
+
assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_order_string
|
66
66
|
store_names ["Product A", "Product B", "Product C", "Product D"]
|
67
|
-
|
67
|
+
assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name"
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_partial
|
@@ -75,8 +75,8 @@ class TestSql < Minitest::Unit::TestCase
|
|
75
75
|
|
76
76
|
def test_fields
|
77
77
|
store [
|
78
|
-
{name: "red", color: "blue"},
|
79
|
-
{name: "blue", color: "red"}
|
78
|
+
{name: "red", color: "light blue"},
|
79
|
+
{name: "blue", color: "red fish"}
|
80
80
|
]
|
81
81
|
assert_search "blue", ["red"], fields: ["color"]
|
82
82
|
end
|