mongoid-searchable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Mongoid Searchable provides simple field search for your Mongoid models using the full-text search technique described in the [MongoDB documentation](http://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo).
4
4
 
5
+ [![travis](https://secure.travis-ci.org/jcoene/mongoid-searchable.png)](http://travis-ci.org/jcoene/mongoid-searchable)
6
+
5
7
  ## Getting Started
6
8
 
7
9
  First, add mongoid-searchable to your Gemfile:
@@ -94,4 +96,4 @@ If you find the project useful but it doesn't meet all of your needs, feel free
94
96
 
95
97
  ## License
96
98
 
97
- MIT license, go wild.
99
+ MIT license, go wild.
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Searchable
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -26,7 +26,7 @@ module Mongoid
26
26
  end
27
27
 
28
28
  def search(query, options={})
29
- keywords = query.to_s.split(' ').map { |s| s.downcase.gsub(/[^a-z0-9]/, '') }.select { |s| s.length >= 2 }.uniq
29
+ keywords = clean_keywords(query)
30
30
  options[:match] ||= :all
31
31
  options[:exact] ||= false
32
32
 
@@ -44,22 +44,18 @@ module Mongoid
44
44
  elsif options[:match].to_sym == :any
45
45
  any_in(keywords_field.to_sym => match)
46
46
  else
47
- where()
47
+ raise "Please specify either :all or :any to match."
48
48
  end
49
49
  else
50
50
  where()
51
51
  end
52
52
  end
53
53
 
54
- end
55
-
56
- module InstanceMethods
57
-
58
54
  def clean_keywords(value)
59
55
  words = []
60
56
 
61
57
  if value.is_a?(String) or value.is_a?(Numeric)
62
- words << value.to_s.split(' ').map { |s| s.downcase.gsub(/[^a-z0-9]/, '') }.select { |s| s.length >= 2 }
58
+ words << value.to_s.downcase.gsub(/<\/?[^>]*>/, '').split(' ').map { |s| s.gsub(/[._:;'"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/, '') }.select { |s| s.length >= 2 }
63
59
  elsif value.is_a?(Array) && value.any?
64
60
  value.each do |v|
65
61
  words << clean_keywords(v)
@@ -73,10 +69,14 @@ module Mongoid
73
69
  words.flatten.uniq
74
70
  end
75
71
 
72
+ end
73
+
74
+ module InstanceMethods
75
+
76
76
  def build_keywords
77
77
  keywords = []
78
78
  self.class.searchable_fields.each do |f|
79
- keywords << clean_keywords(send("#{f}"))
79
+ keywords << self.class.clean_keywords(send("#{f}"))
80
80
  end
81
81
  write_attribute(self.class.keywords_field, keywords.flatten.uniq)
82
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-searchable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &70209780623120 !ruby/object:Gem::Requirement
16
+ requirement: &70175576163600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70209780623120
24
+ version_requirements: *70175576163600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bson_ext
27
- requirement: &70209780602240 !ruby/object:Gem::Requirement
27
+ requirement: &70175576162920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70209780602240
35
+ version_requirements: *70175576162920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: growl
38
- requirement: &70209780588960 !ruby/object:Gem::Requirement
38
+ requirement: &70175576162320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70209780588960
46
+ version_requirements: *70175576162320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70209780575180 !ruby/object:Gem::Requirement
49
+ requirement: &70175576161360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.9.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70209780575180
57
+ version_requirements: *70175576161360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70209780540880 !ruby/object:Gem::Requirement
60
+ requirement: &70175576160100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2.6'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70209780540880
68
+ version_requirements: *70175576160100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &70209780534900 !ruby/object:Gem::Requirement
71
+ requirement: &70175576159400 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.4.3
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70209780534900
79
+ version_requirements: *70175576159400
80
80
  description: Mongoid Searchable allows you to easily perform full-text search your
81
81
  Mongoid models.
82
82
  email: