lunar 0.5.4 → 0.5.5
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 +1 -1
- data/lib/lunar.rb +1 -1
- data/lib/lunar/fuzzy_matches.rb +4 -2
- data/lib/lunar/words.rb +5 -4
- data/lunar.gemspec +2 -2
- data/test/test_lunar.rb +3 -1
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.5.
|
|
1
|
+
0.5.5
|
data/lib/lunar.rb
CHANGED
data/lib/lunar/fuzzy_matches.rb
CHANGED
|
@@ -11,6 +11,8 @@ module Lunar
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def distkey
|
|
14
|
+
return if keys.empty?
|
|
15
|
+
|
|
14
16
|
nest[{ att => value }.hash].tap do |dk|
|
|
15
17
|
dk.zunionstore keys.flatten
|
|
16
18
|
end
|
|
@@ -18,7 +20,7 @@ module Lunar
|
|
|
18
20
|
|
|
19
21
|
protected
|
|
20
22
|
def keys
|
|
21
|
-
Words.new(value).map { |w| nest[:Fuzzies][att][Lunar.encode(w)] }
|
|
23
|
+
Words.new(value, false).map { |w| nest[:Fuzzies][att][Lunar.encode(w)] }
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
|
-
end
|
|
26
|
+
end
|
data/lib/lunar/words.rb
CHANGED
|
@@ -6,11 +6,12 @@ module Lunar
|
|
|
6
6
|
class Words < Array
|
|
7
7
|
SEPARATOR = /\s+/
|
|
8
8
|
|
|
9
|
-
def initialize(str)
|
|
9
|
+
def initialize(str, stopwords = true)
|
|
10
10
|
words = str.split(SEPARATOR).
|
|
11
11
|
reject { |w| w.to_s.strip.empty? }.
|
|
12
|
-
map { |w| sanitize(w) }
|
|
13
|
-
|
|
12
|
+
map { |w| sanitize(w) }
|
|
13
|
+
|
|
14
|
+
words.reject! { |w| Stopwords.include?(w) } if stopwords
|
|
14
15
|
|
|
15
16
|
super(words)
|
|
16
17
|
end
|
|
@@ -21,4 +22,4 @@ module Lunar
|
|
|
21
22
|
gsub(/[^a-zA-Z0-9\-_]/, '').downcase
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
|
-
end
|
|
25
|
+
end
|
data/lunar.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{lunar}
|
|
8
|
-
s.version = "0.5.
|
|
8
|
+
s.version = "0.5.5"
|
|
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"]
|
|
12
|
-
s.date = %q{2010-05-
|
|
12
|
+
s.date = %q{2010-05-31}
|
|
13
13
|
s.description = %q{Features full text searching via metaphones, range querying for numbers, fuzzy searching and sorting based on custom fields}
|
|
14
14
|
s.email = %q{cyx.ucron@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_lunar.rb
CHANGED
|
@@ -15,7 +15,7 @@ class TestLunar < Test::Unit::TestCase
|
|
|
15
15
|
i.text :tags, 'mobile smartphone apple'
|
|
16
16
|
i.number :price, 200
|
|
17
17
|
i.number :score, 35.5
|
|
18
|
-
i.fuzzy :code, 'apple iphone mobile'
|
|
18
|
+
i.fuzzy :code, 'apple iphone mobile tmobile'
|
|
19
19
|
|
|
20
20
|
i.sortable :price, 200
|
|
21
21
|
i.sortable :score, 35.5
|
|
@@ -164,6 +164,8 @@ class TestLunar < Test::Unit::TestCase
|
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
test "fuzzy matching on code apple iphone" do
|
|
167
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'T' })
|
|
168
|
+
|
|
167
169
|
assert_equal %w{1001}, q(:fuzzy => { :code => 'a' })
|
|
168
170
|
assert_equal %w{1001}, q(:fuzzy => { :code => 'ap' })
|
|
169
171
|
assert_equal %w{1001}, q(:fuzzy => { :code => 'app' })
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 5
|
|
8
|
-
-
|
|
9
|
-
version: 0.5.
|
|
8
|
+
- 5
|
|
9
|
+
version: 0.5.5
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Cyril David
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-05-
|
|
17
|
+
date: 2010-05-31 00:00:00 +08:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|