mongomapper_ext 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 CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -10,7 +10,7 @@ module MongoMapperExt
10
10
  klass.class_eval do
11
11
  extend ClassMethods
12
12
 
13
- key :_keywords, Array
13
+ key :_keywords, Set
14
14
  ensure_index :_keywords
15
15
 
16
16
  before_save :_update_keywords
@@ -55,33 +55,123 @@ module MongoMapperExt
55
55
  stemmer = Lingua::Stemmer.new(:language => lang)
56
56
  end
57
57
 
58
+ stop_words = []
59
+ if self.respond_to?("#{lang}_stop_words")
60
+ stop_words = Set.new(self.send("#{lang}_stop_words"))
61
+ end
62
+
58
63
  self._keywords = []
59
64
  self.class.filterable_keys.each do |key|
60
- self._keywords += keywords_for_value(read_attribute(key), stemmer)
65
+ self._keywords += keywords_for_value(read_attribute(key), stemmer, stop_words)
61
66
  end
62
67
  end
63
68
 
64
69
  private
65
- def keywords_for_value(val, stemmer=nil)
70
+ def keywords_for_value(val, stemmer=nil, stop_words = [])
66
71
  if val.kind_of?(String)
67
- val.downcase.split.map do |word|
72
+ words = []
73
+ val.downcase.split.each do |word|
74
+ next if word.length < 3
75
+ next if word =~ %r{'|"|\/|\\}
76
+ next if stop_words.include?(word)
77
+
68
78
  stem = word
69
79
  if stemmer
70
80
  stem = stemmer.stem(word)
71
81
  end
72
82
 
73
- if stem != word
74
- [stem, word]
83
+ if stem && stem != word
84
+ words += [stem, word]
75
85
  else
76
- word
86
+ words << word
77
87
  end
78
- end.flatten
88
+ end
89
+
90
+ words
79
91
  elsif val.kind_of?(Array)
80
- val.map { |e| keywords_for_value(e, stemmer) }.flatten
81
- else
92
+ val.map { |e| keywords_for_value(e, stemmer, stop_words) }.flatten
93
+ elsif val
82
94
  [val]
95
+ else
96
+ []
83
97
  end
84
98
  end
99
+
100
+ def en_stop_words
101
+ ["a", "about", "above", "after", "again", "against", "all", "am", "an",
102
+ "and", "any", "are", "aren't", "as", "at", "be", "because", "been",
103
+ "before", "being", "below", "between", "both", "but", "by", "cannot",
104
+ "can't", "could", "couldn't", "did", "didn't", "do", "does", "doesn't",
105
+ "doing", "don't", "down", "during", "each", "few", "for", "from",
106
+ "further", "had", "hadn't", "has", "hasn't", "have", "haven't", "having",
107
+ "he", "he'd", "he'll", "her", "here", "here's", "hers", "herself", "he's",
108
+ "him", "himself", "his", "how", "how's", "i", "i'd", "if", "i'll", "i'm",
109
+ "in", "into", "is", "isn't", "it", "its", "it's", "itself", "i've", "let's",
110
+ "me", "more", "most", "mustn't", "my", "myself", "no", "nor", "not", "of",
111
+ "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves",
112
+ "out", "over", "own", "same", "shan't", "she", "she'd", "she'll", "she's",
113
+ "should", "shouldn't", "so", "some", "such", "than", "that", "that's", "the",
114
+ "their", "theirs", "them", "themselves", "then", "there", "there's", "these",
115
+ "they", "they'd", "they'll", "they're", "they've", "this", "those", "through",
116
+ "to", "too", "under", "until", "up", "very", "was", "wasn't", "we", "we'd",
117
+ "we'll", "were", "we're", "weren't", "we've", "what", "what's", "when",
118
+ "when's", "where", "where's", "which", "while", "who", "whom", "who's",
119
+ "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd",
120
+ "you'll", "your", "you're", "yours", "yourself", "yourselves", "you've",
121
+ "the", "how"]
122
+ end
123
+
124
+ def es_stop_words
125
+ ["de", "la", "que", "el", "en", "y", "a",
126
+ "los", "del", "se", "las", "por", "un", "para", "con", "no", "una", "su",
127
+ "al", "lo", "como", "mas", "pero", "sus", "le", "ya", "o", "este", "sus",
128
+ "si", "porque", "esta", "entre",
129
+ "cuando", "muy", "sin", "sobre", "tambien", "me", "hasta", "hay",
130
+ "donde", "quien", "desde", "todo", "nos", "durante", "todos", "uno", "les",
131
+ "ni", "contra", "otros", "ese", "eso", "ante", "ellos", "e", "esto",
132
+ "mi", "antes", "algunos", "que", "unos", "yo", "otro",
133
+ "otras", "otra", "al", "tanto", "esa", "estos", "mucho", "quienes",
134
+ "nada", "muchos", "cual", "poco", "ella", "estar", "estas", "algunas",
135
+ "algo", "nosotros", "mi", "mis", "tus", "ellas", "sus", "una", "uno",
136
+ "nosotras", "vosostros", "vosostras", "os", "mio", "mia",
137
+ "mios", "mias", "tuyo", "tuya", "tuyos", "tuyas", "suyo",
138
+ "suya", "suyos", "suyas", "nuestro", "nuestra", "nuestros", "nuestras",
139
+ "vuestro", "vuestra", "vuestros", "vuestras", "esos", "esas", "estoy",
140
+ "estas", "esta", "estamos", "estais", "estan",
141
+ "este", "estes", "estemos", "esteis", "esten",
142
+ "estare", "estareis", "estara", "estaremos", "como",
143
+ "estareis", "estarin", "estaria", "estarias",
144
+ "estariamos", "estariais", "estarian", "estaba",
145
+ "estabas", "estabamos", "estabais", "estaban", "estuve",
146
+ "estuviste", "estuvo", "estuvimos", "estuvisteis", "estuvieron", "estuviera",
147
+ "estuvieras", "estuvieramos", "estuvierais", "estuvieran", "estuviese",
148
+ "estuvieses", "estuviesemos", "estuvieseis", "estuviesen", "estando",
149
+ "estado", "estada", "estados", "estadas", "estad", "he", "has", "ha", "hemos",
150
+ "habeis", "han", "haya", "hayas", "hayamos", "hayais", "hayan",
151
+ "habre", "habras", "habra", "habremos", "habreis",
152
+ "habran", "habria", "habrias", "habriamos",
153
+ "habriais", "habrian", "habia", "habias",
154
+ "habiamos", "habiais", "habian", "hube", "hubiste",
155
+ "hubo", "hubimos", "hubisteis", "hubieron", "hubiera", "hubieras", "hubieramos",
156
+ "hubierais", "hubieran", "hubiese", "hubieses", "hubiesemos", "hubieseis",
157
+ "hubiesen", "habiendo", "habido", "habida", "habidos", "habidas", "soy", "eres",
158
+ "es", "somos", "sois", "son", "sea", "seas", "seamos", "seais",
159
+ "sean", "sere", "seras", "sera", "seremos", "sereis",
160
+ "seran", "seria", "serias", "seriamos", "seriais",
161
+ "serian", "era", "eras", "eramos", "erais", "eran", "fui",
162
+ "fuiste", "fue", "fuimos", "fuisteis", "fueron", "fuera", "fueras",
163
+ "fueramos", "fuerais", "fueran", "fuese", "fueses", "fuesemos",
164
+ "fueseis", "fuesen", "sintiendo", "sentido", "sentida", "sentidos", "sentidas",
165
+ "siente", "sentid", "tengo", "tienes", "tiene", "tenemos", "teneis",
166
+ "tienen", "tenga", "tengas", "tengamos", "tengais", "tengan", "tendre",
167
+ "tendras", "tendra", "tendremos", "tendreis", "tendran",
168
+ "tendria", "tendrias", "tendriamos", "tendriais",
169
+ "tendrian", "tenia", "tenias", "teniamos",
170
+ "teniais", "tenian", "tuve", "tuviste", "tuvo", "tuvimos",
171
+ "tuvisteis", "tuvieron", "tuviera", "tuvieras", "tuvieramos",
172
+ "tuvierais", "tuvieran", "tuviese", "tuvieses", "tuviesemos",
173
+ "tuvieseis", "tuviesen", "teniendo", "tenido", "tenida", "tenidos", "tenidas", "tened"]
174
+ end
85
175
  end
86
176
  end
87
177
 
@@ -18,12 +18,14 @@ module MongoMapperExt
18
18
  protected
19
19
  def generate_slug
20
20
  if self.slug.blank?
21
- slug = self[self.class.slug_key].gsub(/[^A-Za-z0-9\s\-]/, "")[0,20].strip.gsub(/\s+/, "-").downcase
22
- if !self.class.slug_options[:unique]
23
- key = UUIDTools::UUID.random_create.hexdigest[0,4] #optimize
24
- self.slug = key+"-"+slug
25
- else
26
- self.slug = slug
21
+ unless self[self.class.slug_key].blank?
22
+ slug = self[self.class.slug_key].gsub(/[^A-Za-z0-9\s\-]/, "")[0,20].strip.gsub(/\s+/, "-").downcase
23
+ if !self.class.slug_options[:unique]
24
+ key = UUIDTools::UUID.random_create.hexdigest[0,4] #optimize
25
+ self.slug = key+"-"+slug
26
+ else
27
+ self.slug = slug
28
+ end
27
29
  end
28
30
  end
29
31
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongomapper_ext}
8
- s.version = "0.1.3"
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 = ["David A. Cuadrado"]
12
- s.date = %q{2010-02-28}
12
+ s.date = %q{2010-03-04}
13
13
  s.description = %q{MongoMapper extensions}
14
14
  s.email = %q{krawek@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -57,7 +57,7 @@ Gem::Specification.new do |s|
57
57
  s.homepage = %q{http://github.com/dcu/mongomapper_ext}
58
58
  s.rdoc_options = ["--charset=UTF-8"]
59
59
  s.require_paths = ["lib"]
60
- s.rubygems_version = %q{1.3.5}
60
+ s.rubygems_version = %q{1.3.6}
61
61
  s.summary = %q{MongoMapper extensions}
62
62
  s.test_files = [
63
63
  "test/test_slugizer.rb",
@@ -12,6 +12,11 @@ class TestSlugizer < Test::Unit::TestCase
12
12
  @blogpost.slug.should =~ /\w+-blog-post-title/
13
13
  end
14
14
 
15
+ should "not generate the slug if the slug key is blank" do
16
+ @empty_blogpost = BlogPost.new
17
+ @empty_blogpost.slug.should be_nil
18
+ end
19
+
15
20
  should "return the slug as param" do
16
21
  @blogpost.to_param =~ /\w+-blog-post-title/
17
22
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomapper_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 4
9
+ version: 0.1.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - David A. Cuadrado
@@ -9,59 +14,79 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-28 00:00:00 -05:00
17
+ date: 2010-03-04 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: mongo_mapper
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 6
30
+ - 10
23
31
  version: 0.6.10
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: uuidtools
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 0
44
+ - 0
33
45
  version: 2.0.0
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: shoulda
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 10
58
+ - 2
43
59
  version: 2.10.2
44
- version:
60
+ type: :development
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: jnunemaker-matchy
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - "="
52
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 4
72
+ - 0
53
73
  version: 0.4.0
54
- version:
74
+ type: :development
75
+ version_requirements: *id004
55
76
  - !ruby/object:Gem::Dependency
56
77
  name: mocha
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
60
80
  requirements:
61
81
  - - ">="
62
82
  - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ - 9
86
+ - 4
63
87
  version: 0.9.4
64
- version:
88
+ type: :development
89
+ version_requirements: *id005
65
90
  description: MongoMapper extensions
66
91
  email: krawek@gmail.com
67
92
  executables: []
@@ -121,18 +146,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
146
  requirements:
122
147
  - - ">="
123
148
  - !ruby/object:Gem::Version
149
+ segments:
150
+ - 0
124
151
  version: "0"
125
- version:
126
152
  required_rubygems_version: !ruby/object:Gem::Requirement
127
153
  requirements:
128
154
  - - ">="
129
155
  - !ruby/object:Gem::Version
156
+ segments:
157
+ - 0
130
158
  version: "0"
131
- version:
132
159
  requirements: []
133
160
 
134
161
  rubyforge_project:
135
- rubygems_version: 1.3.5
162
+ rubygems_version: 1.3.6
136
163
  signing_key:
137
164
  specification_version: 3
138
165
  summary: MongoMapper extensions