redis_autocomplete 0.1.3 → 0.1.4
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/redis_autocomplete.rb +15 -0
- data/redis_autocomplete.gemspec +1 -1
- data/spec/redis_autocomplete_spec.rb +39 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/redis_autocomplete.rb
CHANGED
@@ -26,6 +26,21 @@ class RedisAutocomplete
|
|
26
26
|
def add_words(words, set_name = nil)
|
27
27
|
words.flatten.compact.uniq.each { |word| add_word word, set_name }
|
28
28
|
end
|
29
|
+
|
30
|
+
def remove_word(word, set_name = nil, remove_stems = true)
|
31
|
+
set_name ||= @set_name
|
32
|
+
@redis.zrem(set_name, "#{word}#{@terminal}")
|
33
|
+
# remove_word_stem is inefficient and is best done later on with a cron job
|
34
|
+
remove_word_stem(word, set_name) if remove_stems
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_word_stem(stem, set_name)
|
38
|
+
if suggest(stem, 1, set_name).empty?
|
39
|
+
@redis.zrem(set_name, stem)
|
40
|
+
remove_word_stem(stem[0...-1], set_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
protected :remove_word_stem
|
29
44
|
|
30
45
|
def suggest(prefix, count = 10, set_name = nil)
|
31
46
|
set_name ||= @set_name
|
data/redis_autocomplete.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{redis_autocomplete}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joe Johnston (simple10)", "Ben Woosley (Empact)", "Salvatore Sanfilippo (antirez)"]
|
@@ -78,6 +78,45 @@ describe RedisAutocomplete do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
describe "#remove_word" do
|
83
|
+
context "with default options" do
|
84
|
+
before do
|
85
|
+
@r.remove_word('Catherine')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not include word after removing it" do
|
89
|
+
@r.suggest('Cath').should_not include('Catherine')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should remove unique word stems" do
|
93
|
+
@r.redis.zrank(@set, 'Catherine').should be_nil
|
94
|
+
@r.redis.zrank(@set, 'Catheri').should == nil
|
95
|
+
@r.redis.zrank(@set, 'Cather').should == nil
|
96
|
+
@r.redis.zrank(@set, 'Cathe').should == nil
|
97
|
+
@r.redis.zrank(@set, 'Cath').should_not == nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when remove_stems is false" do
|
102
|
+
before do
|
103
|
+
@r.remove_word('Catherine', nil, false)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should not include word after removing it" do
|
107
|
+
@r.suggest('Cath').should_not include('Catherine')
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should remove unique word stems" do
|
111
|
+
@r.redis.zrank(@set, 'Catherine+').should be_nil
|
112
|
+
@r.redis.zrank(@set, 'Catherine').should_not be_nil
|
113
|
+
@r.redis.zrank(@set, 'Catheri').should_not be_nil
|
114
|
+
@r.redis.zrank(@set, 'Cather').should_not be_nil
|
115
|
+
@r.redis.zrank(@set, 'Cathe').should_not be_nil
|
116
|
+
@r.redis.zrank(@set, 'Cath').should_not be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
81
120
|
end
|
82
121
|
|
83
122
|
context "with :case_sensitive => false" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: redis_autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joe Johnston (simple10)
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
hash: -
|
109
|
+
hash: -1638761389715983542
|
110
110
|
segments:
|
111
111
|
- 0
|
112
112
|
version: "0"
|