lunar 0.5.1 → 0.5.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -4,7 +4,7 @@ require 'nest'
4
4
  require 'text'
5
5
 
6
6
  module Lunar
7
- VERSION = '0.5.1'
7
+ VERSION = '0.5.2'
8
8
 
9
9
  autoload :Connection, "lunar/connection"
10
10
  autoload :LunarNest, "lunar/lunar_nest"
@@ -83,7 +83,7 @@ module Lunar
83
83
  # @return Lunar::ResultSet an Enumerable object.
84
84
  def self.search(namespace, options, finder = lambda { |id| namespace[id] })
85
85
  sets = find_and_combine_sorted_sets_for(namespace, options)
86
- key = try_intersection_of_sorted_sets(namespace, sets)
86
+ key = try_intersection_of_sorted_sets(namespace, sets, options)
87
87
 
88
88
  ResultSet.new(key, nest[namespace], finder)
89
89
  end
@@ -121,7 +121,9 @@ private
121
121
  end
122
122
  end
123
123
 
124
- def self.try_intersection_of_sorted_sets(namespace, sets)
124
+ def self.try_intersection_of_sorted_sets(namespace, sets, options)
125
+ return if sets.empty?
126
+
125
127
  if sets.size == 1
126
128
  sets.first
127
129
  else
@@ -11,6 +11,8 @@ module Lunar
11
11
  end
12
12
 
13
13
  def distkey
14
+ return if keys.flatten.empty?
15
+
14
16
  nest[{ att => value }.hash].tap do |dk|
15
17
  dk.zunionstore keys.flatten
16
18
  end
@@ -29,4 +31,4 @@ module Lunar
29
31
  Words.new(value).map { |word| Lunar.metaphone(word) }
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -33,6 +33,8 @@ module Lunar
33
33
  end
34
34
 
35
35
  def each
36
+ return if not distkey
37
+
36
38
  objects(distkey.zrange(0, -1)).each { |e| yield e }
37
39
  end
38
40
 
@@ -86,6 +88,8 @@ module Lunar
86
88
  # @return [Array] Array of objects as defined by the `finder`.
87
89
  # @see http://code.google.com/p/redis/wiki/SortCommand
88
90
  def sort(opts = {})
91
+ return [] if not distkey
92
+
89
93
  opts[:by] = sortables[opts[:by]] if opts[:by]
90
94
  objects(distkey.sort(opts))
91
95
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lunar}
8
- s.version = "0.5.1"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril David"]
@@ -67,6 +67,19 @@ class TestLunar < Test::Unit::TestCase
67
67
  assert_equal %w{1003}, q(:q => '9000')
68
68
  end
69
69
 
70
+ test "searching non-existent words" do
71
+ assert_equal [], q(:q => "ericson")
72
+ assert_equal [], q(:q => "ericson", :title => "apple")
73
+ assert_equal [], q(:q => "ericson", :description => "nokia")
74
+ assert_equal [], q(:q => "ericson", :description => "FooBar")
75
+ assert_equal [], q(:q => "ericson", :fuzzy => { :code => "a" })
76
+ assert_equal [], q(:q => "ericson", :price => 150..200)
77
+ end
78
+
79
+ test "sorting empty result sets" do
80
+ assert_equal [], Lunar.search(Gadget, :q => "ericson").sort(:by => :price)
81
+ end
82
+
70
83
  test "fulltext searching with key value pairs" do
71
84
  assert_equal %w{1001}, q(:q => 'apple', :tags => 'mobile')
72
85
  assert_equal %w{1001}, q(:q => 'apple', :tags => 'smartphone')
@@ -178,4 +191,4 @@ class TestLunar < Test::Unit::TestCase
178
191
  assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mobile' })
179
192
  end
180
193
  end
181
- end
194
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 1
9
- version: 0.5.1
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David