mongoid_search 0.2.0 → 0.2.1
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/.gitignore +22 -0
- data/Gemfile +1 -7
- data/Gemfile.lock +40 -25
- data/README.md +19 -19
- data/Rakefile +6 -8
- data/VERSION +1 -1
- data/lib/mongoid_search.rb +1 -1
- data/lib/mongoid_search/mongoid_search.rb +14 -14
- data/lib/mongoid_search/util.rb +2 -2
- data/mongoid_search.gemspec +30 -52
- data/spec/models/category.rb +1 -1
- data/spec/models/subproduct.rb +2 -2
- data/spec/models/tag.rb +1 -1
- data/spec/mongoid_search_spec.rb +17 -17
- data/spec/util_spec.rb +9 -9
- metadata +8 -124
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,48 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongoid_search (0.2.0)
|
5
|
+
bson_ext (~> 1.2)
|
6
|
+
fast-stemmer (~> 1.0.0)
|
7
|
+
mongoid (~> 2.0.0)
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: http://rubygems.org/
|
3
11
|
specs:
|
4
|
-
activemodel (3.0.
|
5
|
-
activesupport (= 3.0.
|
12
|
+
activemodel (3.0.6)
|
13
|
+
activesupport (= 3.0.6)
|
6
14
|
builder (~> 2.1.2)
|
7
|
-
i18n (~> 0.
|
8
|
-
activesupport (3.0.
|
9
|
-
bson (1.
|
15
|
+
i18n (~> 0.5.0)
|
16
|
+
activesupport (3.0.6)
|
17
|
+
bson (1.3.0)
|
18
|
+
bson_ext (1.3.0)
|
10
19
|
builder (2.1.2)
|
11
|
-
database_cleaner (0.6.
|
20
|
+
database_cleaner (0.6.6)
|
12
21
|
diff-lcs (1.1.2)
|
13
22
|
fast-stemmer (1.0.0)
|
23
|
+
gemcutter (0.6.1)
|
14
24
|
git (1.2.5)
|
15
25
|
i18n (0.5.0)
|
16
|
-
jeweler (1.
|
17
|
-
|
26
|
+
jeweler (1.4.0)
|
27
|
+
gemcutter (>= 0.1.0)
|
18
28
|
git (>= 1.2.5)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
rubyforge (>= 2.0.0)
|
30
|
+
json_pure (1.5.1)
|
31
|
+
mongo (1.3.0)
|
32
|
+
bson (>= 1.3.0)
|
33
|
+
mongoid (2.0.0)
|
23
34
|
activemodel (~> 3.0)
|
24
35
|
mongo (~> 1.2)
|
25
36
|
tzinfo (~> 0.3.22)
|
26
37
|
will_paginate (~> 3.0.pre)
|
27
38
|
rake (0.8.7)
|
28
|
-
rspec (2.
|
29
|
-
rspec-core (~> 2.
|
30
|
-
rspec-expectations (~> 2.
|
31
|
-
rspec-mocks (~> 2.
|
32
|
-
rspec-core (2.
|
33
|
-
rspec-expectations (2.
|
39
|
+
rspec (2.5.0)
|
40
|
+
rspec-core (~> 2.5.0)
|
41
|
+
rspec-expectations (~> 2.5.0)
|
42
|
+
rspec-mocks (~> 2.5.0)
|
43
|
+
rspec-core (2.5.1)
|
44
|
+
rspec-expectations (2.5.0)
|
34
45
|
diff-lcs (~> 1.1.2)
|
35
|
-
rspec-mocks (2.
|
36
|
-
|
46
|
+
rspec-mocks (2.5.0)
|
47
|
+
rubyforge (2.0.4)
|
48
|
+
json_pure (>= 1.1.7)
|
49
|
+
tzinfo (0.3.26)
|
37
50
|
will_paginate (3.0.pre2)
|
38
51
|
|
39
52
|
PLATFORMS
|
40
53
|
ruby
|
41
54
|
|
42
55
|
DEPENDENCIES
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
bson_ext (~> 1.2)
|
57
|
+
database_cleaner (~> 0.6.4)
|
58
|
+
fast-stemmer (~> 1.0.0)
|
59
|
+
jeweler (~> 1.4.0)
|
60
|
+
mongoid (~> 2.0.0)
|
61
|
+
mongoid_search!
|
47
62
|
rake (= 0.8.7)
|
48
|
-
rspec (
|
63
|
+
rspec (~> 2.4)
|
data/README.md
CHANGED
@@ -9,9 +9,9 @@ Installation
|
|
9
9
|
In your Gemfile:
|
10
10
|
|
11
11
|
gem 'mongoid_search'
|
12
|
-
|
12
|
+
|
13
13
|
Then:
|
14
|
-
|
14
|
+
|
15
15
|
bundle install
|
16
16
|
|
17
17
|
Examples
|
@@ -25,7 +25,7 @@ Examples
|
|
25
25
|
|
26
26
|
references_many :tags
|
27
27
|
refereced_in :category
|
28
|
-
|
28
|
+
|
29
29
|
search_in :brand, :name, :tags => :name, :category => :name
|
30
30
|
end
|
31
31
|
|
@@ -35,7 +35,7 @@ Examples
|
|
35
35
|
|
36
36
|
referenced_in :product
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
class Category
|
40
40
|
include Mongoid::Document
|
41
41
|
field :name
|
@@ -44,7 +44,7 @@ Examples
|
|
44
44
|
end
|
45
45
|
|
46
46
|
Now when you save a product, you get a _keywords field automatically:
|
47
|
-
|
47
|
+
|
48
48
|
p = Product.new :brand => "Apple", :name => "iPhone"
|
49
49
|
p.tags << Tag.new(:name => "Amazing")
|
50
50
|
p.tags << Tag.new(:name => "Awesome")
|
@@ -52,45 +52,45 @@ Now when you save a product, you get a _keywords field automatically:
|
|
52
52
|
p.save
|
53
53
|
=> true
|
54
54
|
p._keywords
|
55
|
-
|
55
|
+
|
56
56
|
Now you can run search, which will look in the _keywords field and return all matching results:
|
57
57
|
|
58
58
|
Product.search("apple iphone").size
|
59
59
|
=> 1
|
60
|
-
|
60
|
+
|
61
61
|
Note that the search is case insensitive, and accept partial searching too:
|
62
62
|
|
63
63
|
Product.search("ipho").size
|
64
64
|
=> 1
|
65
|
-
|
65
|
+
|
66
66
|
Options
|
67
67
|
-------
|
68
68
|
|
69
|
-
match:
|
70
|
-
_:any_ - match any occurrence
|
71
|
-
_:all_ - match all ocurrences
|
69
|
+
match:
|
70
|
+
_:any_ - match any occurrence
|
71
|
+
_:all_ - match all ocurrences
|
72
72
|
Default is _:any_.
|
73
73
|
|
74
74
|
search_in :brand, :name, { :tags => :name }, { :match => :any }
|
75
|
-
|
75
|
+
|
76
76
|
Product.search("apple motorola").size
|
77
77
|
=> 1
|
78
78
|
|
79
79
|
search_in :brand, :name, { :tags => :name }, { :match => :all }
|
80
|
-
|
80
|
+
|
81
81
|
Product.search("apple motorola").size
|
82
82
|
=> 0
|
83
|
-
|
84
|
-
allow_empty_search:
|
85
|
-
_true_ - match any occurrence
|
86
|
-
_false_ - match all ocurrences
|
83
|
+
|
84
|
+
allow_empty_search:
|
85
|
+
_true_ - match any occurrence
|
86
|
+
_false_ - match all ocurrences
|
87
87
|
Default is _false_.
|
88
88
|
|
89
89
|
search_in :brand, :name, { :tags => :name }, { :allow_empty_search => true }
|
90
|
-
|
90
|
+
|
91
91
|
Product.search("").size
|
92
92
|
=> 1
|
93
|
-
|
93
|
+
|
94
94
|
TODO
|
95
95
|
----
|
96
96
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.rspec_opts = ["-c", "-f progress"]
|
7
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
8
|
+
end
|
9
|
+
|
4
10
|
begin
|
5
11
|
require 'jeweler'
|
6
12
|
Jeweler::Tasks.new do |gem|
|
@@ -10,19 +16,11 @@ begin
|
|
10
16
|
gem.email = "mauricio@papodenerd.net"
|
11
17
|
gem.homepage = "http://www.papodenerd.net/mongoid-search-full-text-search-for-your-mongoid-models/"
|
12
18
|
gem.authors = ["Mauricio Zaffari"]
|
13
|
-
gem.add_dependency("mongoid", ["~> 2.0.0"])
|
14
|
-
gem.add_development_dependency "rspec", ">= 2.0.1"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
19
|
end
|
17
20
|
Jeweler::GemcutterTasks.new
|
18
21
|
rescue LoadError
|
19
22
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
23
|
end
|
21
24
|
|
22
|
-
require 'rspec/core/rake_task'
|
23
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
24
|
-
spec.rspec_opts = ["-c", "-f progress"]
|
25
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
26
|
-
end
|
27
25
|
|
28
26
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/mongoid_search.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'mongoid_search/util'
|
2
|
-
require 'mongoid_search/mongoid_search'
|
2
|
+
require 'mongoid_search/mongoid_search'
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Mongoid::Search
|
2
2
|
extend ActiveSupport::Concern
|
3
|
-
|
3
|
+
|
4
4
|
included do
|
5
5
|
cattr_accessor :search_fields, :match, :allow_empty_search, :relevant_search, :stem_keywords, :ignore_list
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
module ClassMethods #:nodoc:
|
9
9
|
# Set a field or a number of fields as sources for search
|
10
10
|
def search_in(*args)
|
@@ -18,10 +18,10 @@ module Mongoid::Search
|
|
18
18
|
|
19
19
|
field :_keywords, :type => Array
|
20
20
|
index :_keywords
|
21
|
-
|
21
|
+
|
22
22
|
before_save :set_keywords
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def search(query, options={})
|
26
26
|
if relevant_search
|
27
27
|
search_relevant(query, options)
|
@@ -29,17 +29,17 @@ module Mongoid::Search
|
|
29
29
|
search_without_relevance(query, options)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def search_without_relevance(query, options={})
|
34
34
|
return self.all if query.blank? && allow_empty_search
|
35
35
|
self.send("#{(options[:match]||self.match).to_s}_in", :_keywords => Util.keywords(query, stem_keywords, ignore_list).map { |q| /#{q}/ })
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def search_relevant(query, options={})
|
39
39
|
return self.all if query.blank? && allow_empty_search
|
40
|
-
|
40
|
+
|
41
41
|
keywords = Util.keywords(query, stem_keywords, ignore_list)
|
42
|
-
|
42
|
+
|
43
43
|
map = <<-EOS
|
44
44
|
function() {
|
45
45
|
var entries = 0
|
@@ -57,27 +57,27 @@ module Mongoid::Search
|
|
57
57
|
return(values[0])
|
58
58
|
}
|
59
59
|
EOS
|
60
|
-
|
60
|
+
|
61
61
|
#raise [self.class, self.inspect].inspect
|
62
|
-
|
62
|
+
|
63
63
|
kw_conditions = keywords.map do |kw|
|
64
64
|
{:_keywords => kw}
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
criteria = self.any_of(*kw_conditions)
|
68
|
-
|
68
|
+
|
69
69
|
query = criteria.selector
|
70
70
|
|
71
71
|
options.delete(:limit)
|
72
72
|
options.delete(:skip)
|
73
73
|
options.merge! :scope => {:keywords => keywords}, :query => query
|
74
|
-
|
74
|
+
|
75
75
|
res = collection.map_reduce(map, reduce, options)
|
76
76
|
|
77
77
|
res.find.sort(['value', -1]) # Cursor
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
private
|
82
82
|
|
83
83
|
# TODO: This need some refatoring..
|
data/lib/mongoid_search/util.rb
CHANGED
data/mongoid_search.gemspec
CHANGED
@@ -1,54 +1,56 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid_search}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mauricio Zaffari"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-07}
|
13
13
|
s.description = %q{Simple full text search implementation.}
|
14
14
|
s.email = %q{mauricio@papodenerd.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/mongoid_search.rb",
|
29
|
+
"lib/mongoid_search/mongoid_search.rb",
|
30
|
+
"lib/mongoid_search/util.rb",
|
31
|
+
"mongoid_search.gemspec",
|
32
|
+
"spec/config/ignorelist.yml",
|
33
|
+
"spec/models/category.rb",
|
34
|
+
"spec/models/product.rb",
|
35
|
+
"spec/models/subproduct.rb",
|
36
|
+
"spec/models/tag.rb",
|
37
|
+
"spec/mongoid_search_spec.rb",
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/util_spec.rb"
|
39
40
|
]
|
40
41
|
s.homepage = %q{http://www.papodenerd.net/mongoid-search-full-text-search-for-your-mongoid-models/}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
43
|
s.require_paths = ["lib"]
|
42
44
|
s.rubygems_version = %q{1.3.7}
|
43
45
|
s.summary = %q{Search implementation for Mongoid ORM}
|
44
46
|
s.test_files = [
|
45
47
|
"spec/models/category.rb",
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
"spec/models/product.rb",
|
49
|
+
"spec/models/subproduct.rb",
|
50
|
+
"spec/models/tag.rb",
|
51
|
+
"spec/mongoid_search_spec.rb",
|
52
|
+
"spec/spec_helper.rb",
|
53
|
+
"spec/util_spec.rb"
|
52
54
|
]
|
53
55
|
|
54
56
|
if s.respond_to? :specification_version then
|
@@ -56,33 +58,9 @@ Gem::Specification.new do |s|
|
|
56
58
|
s.specification_version = 3
|
57
59
|
|
58
60
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
-
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
60
|
-
s.add_runtime_dependency(%q<database_cleaner>, [">= 0"])
|
61
|
-
s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.19"])
|
62
|
-
s.add_runtime_dependency(%q<rake>, ["= 0.8.7"])
|
63
|
-
s.add_runtime_dependency(%q<rspec>, ["= 2.3.0"])
|
64
|
-
s.add_runtime_dependency(%q<fast-stemmer>, ["= 1.0.0"])
|
65
|
-
s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0"])
|
66
|
-
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
67
61
|
else
|
68
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
69
|
-
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
70
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.19"])
|
71
|
-
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
72
|
-
s.add_dependency(%q<rspec>, ["= 2.3.0"])
|
73
|
-
s.add_dependency(%q<fast-stemmer>, ["= 1.0.0"])
|
74
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0"])
|
75
|
-
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
76
62
|
end
|
77
63
|
else
|
78
|
-
s.add_dependency(%q<jeweler>, [">= 0"])
|
79
|
-
s.add_dependency(%q<database_cleaner>, [">= 0"])
|
80
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.19"])
|
81
|
-
s.add_dependency(%q<rake>, ["= 0.8.7"])
|
82
|
-
s.add_dependency(%q<rspec>, ["= 2.3.0"])
|
83
|
-
s.add_dependency(%q<fast-stemmer>, ["= 1.0.0"])
|
84
|
-
s.add_dependency(%q<mongoid>, ["~> 2.0.0"])
|
85
|
-
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
86
64
|
end
|
87
65
|
end
|
88
66
|
|
data/spec/models/category.rb
CHANGED
data/spec/models/subproduct.rb
CHANGED
data/spec/models/tag.rb
CHANGED
data/spec/mongoid_search_spec.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
4
|
|
5
5
|
describe Mongoid::Search do
|
6
|
-
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
Product.stem_keywords = false
|
9
9
|
Product.ignore_list = nil
|
@@ -13,7 +13,7 @@ describe Mongoid::Search do
|
|
13
13
|
:category => Category.new(:name => "Mobile"),
|
14
14
|
:subproducts => [Subproduct.new(:brand => "Apple", :name => "Craddle")]
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
context "utf-8 characters" do
|
18
18
|
before(:each) {
|
19
19
|
Product.stem_keywords = false
|
@@ -24,28 +24,28 @@ describe Mongoid::Search do
|
|
24
24
|
:category => Category.new(:name => "процессоры"),
|
25
25
|
:subproducts => []
|
26
26
|
}
|
27
|
-
|
27
|
+
|
28
28
|
it "should leave utf8 characters" do
|
29
29
|
@product._keywords.should == ["amazing", "awesome", "ole", "Процессор", "Эльбрус", "процессоры"]
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should set the _keywords field" do
|
34
34
|
@product._keywords.should == ["amazing", "apple", "apple", "awesome", "craddle", "iphone", "mobile", "ole"]
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should set the _keywords field with stemmed words if stem is enabled" do
|
38
38
|
Product.stem_keywords = true
|
39
39
|
@product.save!
|
40
40
|
@product._keywords.should == ["amaz", "appl", "appl", "awesom", "craddl", "iphon", "mobil", "ol"]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should ignore keywords in an ignore list" do
|
44
44
|
Product.ignore_list = YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]
|
45
45
|
@product.save!
|
46
46
|
@product._keywords.should == ["apple", "apple", "craddle", "iphone", "mobile", "ole"]
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it "should return results in search" do
|
50
50
|
Product.search("apple").size.should == 1
|
51
51
|
end
|
@@ -55,47 +55,47 @@ describe Mongoid::Search do
|
|
55
55
|
@product.save!
|
56
56
|
Product.search("online").size.should == 1
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "should return results in search even searching a accented word" do
|
60
60
|
Product.search("Ole").size.should == 1
|
61
61
|
Product.search("Olé").size.should == 1
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
it "should return results in search even if the case doesn't match" do
|
65
65
|
Product.search("oLe").size.should == 1
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should return results in search with a partial word" do
|
69
69
|
Product.search("iph").size.should == 1
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
it "should return results for any matching word with default search" do
|
73
73
|
Product.search("apple motorola").size.should == 1
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
it "should not return results when all words do not match, if using :match => :all" do
|
77
77
|
Product.match = :all
|
78
78
|
Product.search("apple motorola").size.should == 0
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should return results for any matching word, using :match => :all, passing :match => :any to .search" do
|
82
82
|
Product.match = :all
|
83
83
|
Product.search("apple motorola", :match => :any).size.should == 1
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should not return results when all words do not match, passing :match => :all to .search" do
|
87
87
|
Product.search("apple motorola", :match => :all).size.should == 0
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should return no results when a blank search is made" do
|
91
91
|
Product.search("").size.should == 0
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
it "should return results when a blank search is made when :allow_empty_search is true" do
|
95
95
|
Product.allow_empty_search = true
|
96
96
|
Product.search("").size.should == 1
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "should search for embedded documents" do
|
100
100
|
Product.search("craddle").size.should == 1
|
101
101
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -5,35 +5,35 @@ describe Util do
|
|
5
5
|
it "should return an empty array if no text is passed" do
|
6
6
|
Util.keywords("", false, "").should == []
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should return an array of keywords" do
|
10
10
|
Util.keywords("keyword", false, "").class.should == Array
|
11
|
-
end
|
12
|
-
|
11
|
+
end
|
12
|
+
|
13
13
|
it "should return an array of strings" do
|
14
14
|
Util.keywords("keyword", false, "").first.class.should == String
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should remove accents from the text passed" do
|
18
18
|
Util.keywords("café", false, "").should == ["cafe"]
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "should downcase the text passed" do
|
22
22
|
Util.keywords("CaFé", false, "").should == ["cafe"]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should split whitespaces, hifens, dots, underlines, etc.." do
|
26
26
|
Util.keywords("CaFé-express.com delicious;come visit, and 'win' an \"iPad\"", false, "").should == ["cafe", "express", "com", "delicious", "come", "visit", "and", "win", "an", "ipad"]
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should stem keywords" do
|
30
30
|
Util.keywords("A runner running and eating", true, "").should == ["runner", "run", "and", "eat"]
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should ignore keywords from ignore list" do
|
34
34
|
Util.keywords("An amazing awesome runner running and eating", true, YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]).should == ["an", "runner", "run", "and", "eat"]
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should ignore keywords with less than two words" do
|
38
38
|
Util.keywords("A runner running", false, "").should_not include "a"
|
39
39
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mauricio Zaffari
|
@@ -14,127 +14,10 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-07 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
name: jeweler
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
type: :runtime
|
31
|
-
prerelease: false
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: database_cleaner
|
35
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 0
|
42
|
-
version: "0"
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: *id002
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: mongoid
|
48
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 2
|
55
|
-
- 0
|
56
|
-
- 0
|
57
|
-
- beta
|
58
|
-
- 19
|
59
|
-
version: 2.0.0.beta.19
|
60
|
-
type: :runtime
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: rake
|
65
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
|
-
requirements:
|
68
|
-
- - "="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 0
|
72
|
-
- 8
|
73
|
-
- 7
|
74
|
-
version: 0.8.7
|
75
|
-
type: :runtime
|
76
|
-
prerelease: false
|
77
|
-
version_requirements: *id004
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: rspec
|
80
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - "="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
segments:
|
86
|
-
- 2
|
87
|
-
- 3
|
88
|
-
- 0
|
89
|
-
version: 2.3.0
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: *id005
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: fast-stemmer
|
95
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
|
-
requirements:
|
98
|
-
- - "="
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
segments:
|
101
|
-
- 1
|
102
|
-
- 0
|
103
|
-
- 0
|
104
|
-
version: 1.0.0
|
105
|
-
type: :runtime
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: *id006
|
108
|
-
- !ruby/object:Gem::Dependency
|
109
|
-
name: mongoid
|
110
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
|
-
requirements:
|
113
|
-
- - ~>
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
segments:
|
116
|
-
- 2
|
117
|
-
- 0
|
118
|
-
- 0
|
119
|
-
version: 2.0.0
|
120
|
-
type: :runtime
|
121
|
-
prerelease: false
|
122
|
-
version_requirements: *id007
|
123
|
-
- !ruby/object:Gem::Dependency
|
124
|
-
name: rspec
|
125
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
|
-
requirements:
|
128
|
-
- - ">="
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
segments:
|
131
|
-
- 2
|
132
|
-
- 0
|
133
|
-
- 1
|
134
|
-
version: 2.0.1
|
135
|
-
type: :development
|
136
|
-
prerelease: false
|
137
|
-
version_requirements: *id008
|
19
|
+
dependencies: []
|
20
|
+
|
138
21
|
description: Simple full text search implementation.
|
139
22
|
email: mauricio@papodenerd.net
|
140
23
|
executables: []
|
@@ -146,6 +29,7 @@ extra_rdoc_files:
|
|
146
29
|
- README.md
|
147
30
|
files:
|
148
31
|
- .document
|
32
|
+
- .gitignore
|
149
33
|
- Gemfile
|
150
34
|
- Gemfile.lock
|
151
35
|
- LICENSE
|
@@ -169,8 +53,8 @@ homepage: http://www.papodenerd.net/mongoid-search-full-text-search-for-your-mon
|
|
169
53
|
licenses: []
|
170
54
|
|
171
55
|
post_install_message:
|
172
|
-
rdoc_options:
|
173
|
-
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
174
58
|
require_paths:
|
175
59
|
- lib
|
176
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|