Rfizzy 0.1.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +7 -0
- data/README.rdoc +75 -0
- data/Rakefile +51 -0
- data/Rfizzy.gemspec +92 -0
- data/VERSION +1 -0
- data/docs/FullTextSearch.html +48 -0
- data/docs/Tagging.html +49 -0
- data/docs/docco.css +186 -0
- data/docs/installation_and_setup.html +23 -0
- data/example_usage/FullTextSearch.rb +95 -0
- data/example_usage/Tagging.rb +94 -0
- data/example_usage/installation_and_setup.rb +55 -0
- data/lib/Rfizzy.rb +83 -0
- data/spec/.DS_Store +0 -0
- data/spec/initialization/rfizzy_searching_initialize_spec.rb +37 -0
- data/spec/searching/.DS_Store +0 -0
- data/spec/searching/rfizzy_searching_create_spec.rb +43 -0
- data/spec/searching/rfizzy_searching_destroy_spec.rb +33 -0
- data/spec/searching/rfizzy_searching_search_spec.rb +55 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/.DS_Store +0 -0
- data/spec/support/Factories/search_factories.rb +37 -0
- data/spec/support/Factories/tagging_factories.rb +37 -0
- data/spec/tagging/rfizzy_tagging_create_spec.rb +43 -0
- data/spec/tagging/rfizzy_tagging_search_spec.rb +56 -0
- metadata +183 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rfizzy, "search search_index" do
|
4
|
+
let(:namespace) { SearchFactory.instance.namespace }
|
5
|
+
let(:tweet) { SearchFactory.instance.tweet }
|
6
|
+
let(:document_key_name) { SearchFactory.instance.document_key_name }
|
7
|
+
let(:document_id) { SearchFactory.instance.document_id }
|
8
|
+
let(:word_key_name) {SearchFactory.instance.word_key_name}
|
9
|
+
let(:word_list) { SearchFactory.instance.word_list }
|
10
|
+
let(:word_size) { SearchFactory.instance.word_size }
|
11
|
+
let(:search_words) { word_list.join(" ") }
|
12
|
+
let(:search_parameters) do
|
13
|
+
{:association => tweet[:association],
|
14
|
+
:attribute_namespace => tweet[:attribute_namespace],
|
15
|
+
:search => search_words}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:search_keys) do
|
19
|
+
search_keys_var = search_words.split(" ").map do |word|
|
20
|
+
"#{namespace}:word:#{tweet[:association]}:#{tweet[:attribute_namespace]}:#{word}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:non_search_keys) do
|
25
|
+
search_keys_var = "shit balls".split(" ").map do |word|
|
26
|
+
"#{namespace}:word:#{tweet[:association]}:#{tweet[:attribute_namespace]}:#{word}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "searching with multiple words" do
|
31
|
+
before(:each) do
|
32
|
+
@search = Rfizzy.new({:redis => R, :namespace => namespace })
|
33
|
+
@search.create_index(tweet)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
context "should find something" do
|
38
|
+
it "should return the document associated" do
|
39
|
+
@search.should_receive(:search_keys).with(search_parameters).and_return(search_keys)
|
40
|
+
found_document_id = @search.search_index search_parameters
|
41
|
+
found_document_id.should include(document_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "should find nothing" do
|
45
|
+
it "should not return the document associated" do
|
46
|
+
@search.should_receive(:search_keys).with(search_parameters).and_return(non_search_keys)
|
47
|
+
found_document_id = @search.search_index search_parameters
|
48
|
+
found_document_id.should_not include(document_id)
|
49
|
+
found_document_id.should be_empty
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'Rfizzy'
|
5
|
+
require "redis"
|
6
|
+
R = Redis.new
|
7
|
+
R.select 10
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.before(:suite) do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
config.before(:each) do
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after(:each) do
|
21
|
+
end
|
22
|
+
|
23
|
+
config.before(:all) do
|
24
|
+
R.select 10
|
25
|
+
R.flushdb
|
26
|
+
|
27
|
+
end
|
28
|
+
config.after(:all) do
|
29
|
+
R.select 10
|
30
|
+
R.flushdb
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
Binary file
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
class SearchFactory
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def namespace
|
6
|
+
"short"
|
7
|
+
end
|
8
|
+
|
9
|
+
def document_id
|
10
|
+
tweet[:document_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def tweet
|
14
|
+
{:attribute_namespace => :tweet,
|
15
|
+
:document_id => "MyPost",
|
16
|
+
:association => "MyUser",
|
17
|
+
:words => "should create the document set with proper key names filled with words"}
|
18
|
+
end
|
19
|
+
|
20
|
+
def document_key_name
|
21
|
+
"#{namespace}:document:#{tweet[:association]}:#{tweet[:attribute_namespace]}:#{tweet[:document_id]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def word_key_name
|
25
|
+
"#{namespace}:word:#{tweet[:association]}:#{tweet[:attribute_namespace]}:"
|
26
|
+
end
|
27
|
+
|
28
|
+
def word_list
|
29
|
+
tweet[:words].split(" ").uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
def word_size
|
33
|
+
word_list.count
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
class TaggingFactory
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def namespace
|
6
|
+
"bali"
|
7
|
+
end
|
8
|
+
|
9
|
+
def document_id
|
10
|
+
article[:document_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def article
|
14
|
+
{:attribute_namespace => :article,
|
15
|
+
:document_id => "MyPost",
|
16
|
+
:association => "MyUser",
|
17
|
+
:words => "food game sleep booze gaysex".split(" ")}
|
18
|
+
end
|
19
|
+
|
20
|
+
def document_key_name
|
21
|
+
"#{namespace}:document:#{article[:association]}:#{article[:attribute_namespace]}:#{article[:document_id]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def word_key_name
|
25
|
+
"#{namespace}:word:#{article[:association]}:#{article[:attribute_namespace]}:"
|
26
|
+
end
|
27
|
+
|
28
|
+
def tag_list
|
29
|
+
article[:words].uniq
|
30
|
+
end
|
31
|
+
|
32
|
+
def tag_size
|
33
|
+
tag_list.count
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rfizzy, "tagging create" do
|
4
|
+
let(:namespace) { TaggingFactory.instance.namespace }
|
5
|
+
let(:article) { TaggingFactory.instance.article }
|
6
|
+
let(:document_key_name) { TaggingFactory.instance.document_key_name }
|
7
|
+
|
8
|
+
let(:word_key_name) {TaggingFactory.instance.word_key_name}
|
9
|
+
let(:tag_list) { TaggingFactory.instance.tag_list }
|
10
|
+
let(:tag_size) { TaggingFactory.instance.tag_size }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@search = Rfizzy.new({:redis => R, :namespace => namespace })
|
14
|
+
@search.create_index(article)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "create an index with" do
|
18
|
+
context "a document that" do
|
19
|
+
it "should exist " do
|
20
|
+
R.exists(document_key_name).should be_true
|
21
|
+
end
|
22
|
+
it "should be of the type set" do
|
23
|
+
R.type(document_key_name).should == "set"
|
24
|
+
end
|
25
|
+
it "should contain tags" do
|
26
|
+
R.smembers(document_key_name).should have(tag_size).things
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "a set for each tag that" do
|
31
|
+
it "should exist" do
|
32
|
+
tag_list.each do |word|
|
33
|
+
R.exists("#{word_key_name}#{word}").should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
it "should refer to the document_id" do
|
37
|
+
tag_list.each do |word|
|
38
|
+
R.sismember("#{word_key_name}#{word}", article[:document_id])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rfizzy, "tagging search_index" do
|
4
|
+
let(:namespace) { TaggingFactory.instance.namespace }
|
5
|
+
let(:article) { TaggingFactory.instance.article }
|
6
|
+
let(:document_key_name) { TaggingFactory.instance.document_key_name }
|
7
|
+
let(:document_id) { TaggingFactory.instance.document_id }
|
8
|
+
let(:tag_key_name) {TaggingFactory.instance.tag_key_name}
|
9
|
+
let(:tag_list) { TaggingFactory.instance.tag_list }
|
10
|
+
let(:tag_size) { TaggingFactory.instance.tag_size }
|
11
|
+
let(:tags) { tag_list }
|
12
|
+
let(:tag_parameters) do
|
13
|
+
{:association => article[:association],
|
14
|
+
:attribute_namespace => article[:attribute_namespace],
|
15
|
+
:search => tags}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:tag_keys) do
|
19
|
+
search_keys_var = tags.map do |word|
|
20
|
+
"#{namespace}:word:#{article[:association]}:#{article[:attribute_namespace]}:#{word}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:non_tag_keys) do
|
25
|
+
search_keys_var = "does not exist".split(" ").map do |word|
|
26
|
+
"#{namespace}:word:#{article[:association]}:#{article[:attribute_namespace]}:#{word}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "searching with multiple tags" do
|
31
|
+
before(:each) do
|
32
|
+
@search = Rfizzy.new({:redis => R, :namespace => namespace })
|
33
|
+
@search.create_index(article)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
context "should find something" do
|
38
|
+
it "should return the document associated" do
|
39
|
+
@search.should_receive(:search_keys).with(tag_parameters).and_return(tag_keys)
|
40
|
+
found_document_id = @search.search_index tag_parameters
|
41
|
+
found_document_id.should include(document_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "should find nothing" do
|
46
|
+
it "should not return the document associated" do
|
47
|
+
@search.should_receive(:search_keys).with(tag_parameters).and_return(non_tag_keys)
|
48
|
+
found_document_id = @search.search_index tag_parameters
|
49
|
+
found_document_id.should_not include(document_id)
|
50
|
+
found_document_id.should be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Rfizzy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Seivan Heidari
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-18 00:00:00.000000000 +08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redis
|
17
|
+
requirement: &2154016400 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2154016400
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2154015920 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2154015920
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
requirement: &2154015360 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.6.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2154015360
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &2154014880 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2154014880
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &2154014400 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.6.4
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2154014400
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &2154013900 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2154013900
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: autotest
|
83
|
+
requirement: &2154013420 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *2154013420
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: syntax
|
94
|
+
requirement: &2154012820 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *2154012820
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: reek
|
105
|
+
requirement: &2154012300 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.2.8
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *2154012300
|
114
|
+
description: Full text search engine with Redis. Works in all Ruby projects. Very
|
115
|
+
simple built, source code is < 300loc including tests. Was built because it's cheaper
|
116
|
+
to go with the 20mb Redis solution with redis than using PostgreSQL's full text
|
117
|
+
search. Also I needed background jobs and might as well use Resque for that.
|
118
|
+
email: seivan@kth.se
|
119
|
+
executables: []
|
120
|
+
extensions: []
|
121
|
+
extra_rdoc_files:
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.rdoc
|
124
|
+
files:
|
125
|
+
- .document
|
126
|
+
- .rspec
|
127
|
+
- Gemfile
|
128
|
+
- Gemfile.lock
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.rdoc
|
131
|
+
- Rakefile
|
132
|
+
- Rfizzy.gemspec
|
133
|
+
- VERSION
|
134
|
+
- docs/FullTextSearch.html
|
135
|
+
- docs/Tagging.html
|
136
|
+
- docs/docco.css
|
137
|
+
- docs/installation_and_setup.html
|
138
|
+
- example_usage/FullTextSearch.rb
|
139
|
+
- example_usage/Tagging.rb
|
140
|
+
- example_usage/installation_and_setup.rb
|
141
|
+
- lib/Rfizzy.rb
|
142
|
+
- spec/.DS_Store
|
143
|
+
- spec/initialization/rfizzy_searching_initialize_spec.rb
|
144
|
+
- spec/searching/.DS_Store
|
145
|
+
- spec/searching/rfizzy_searching_create_spec.rb
|
146
|
+
- spec/searching/rfizzy_searching_destroy_spec.rb
|
147
|
+
- spec/searching/rfizzy_searching_search_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/support/.DS_Store
|
150
|
+
- spec/support/Factories/search_factories.rb
|
151
|
+
- spec/support/Factories/tagging_factories.rb
|
152
|
+
- spec/tagging/rfizzy_tagging_create_spec.rb
|
153
|
+
- spec/tagging/rfizzy_tagging_search_spec.rb
|
154
|
+
has_rdoc: true
|
155
|
+
homepage: http://github.com/seivan/Rfizzy
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
segments:
|
169
|
+
- 0
|
170
|
+
hash: 807837584847606337
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ! '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 1.6.2
|
180
|
+
signing_key:
|
181
|
+
specification_version: 3
|
182
|
+
summary: Full text search engine with Redis. Works in all Ruby projects
|
183
|
+
test_files: []
|