mongoid_fulltext 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,6 +4,12 @@ Mongoid Fulltext Search
4
4
  Full-text search using n-gram matching for the Mongoid ODM. Tested on MongoDB 1.6 and above, but
5
5
  probably works on earlier versions as well.
6
6
 
7
+ MongoDB currently has no native full-text search capabilities, so this gem is a good fit for cases
8
+ where you want something a little less than a full-blown indexing service like Solr. mongoid_fulltext
9
+ lets you do a fuzzy string search across relatively short strings, which makes it good for populating
10
+ autocomplete boxes based on the display names of your Rails models but not appropriate for, say,
11
+ indexing hundreds of thousands of HTML documents.
12
+
7
13
  Some examples:
8
14
  --------------
9
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -24,7 +24,7 @@ module Mongoid::FullTextSearch
24
24
 
25
25
  config = {
26
26
  :alphabet => 'abcdefghijklmnopqrstuvwxyz0123456789 ',
27
- :word_separators => ' ',
27
+ :word_separators => "- \n\t",
28
28
  :ngram_width => 3,
29
29
  :max_ngrams_to_search => 6,
30
30
  :apply_prefix_scoring_to_all_words => true,
@@ -219,11 +219,17 @@ module Mongoid::FullTextSearch
219
219
 
220
220
  # If an ngram appears multiple times in the query string, keep the max score
221
221
  ngram_array = ngram_array.group_by{ |h| h[:ngram] }.map{ |key, values| {:ngram => key, :score => values.map{ |v| v[:score] }.max} }
222
+
223
+ if config[:index_short_prefixes] or config[:index_full_words]
224
+ split_regex_def = config[:word_separators].keys.map{ |k| Regexp.escape(k) }.join
225
+ split_regex = Regexp.compile("[#{split_regex_def}]")
226
+ all_words = filtered_str.split(split_regex)
227
+ end
222
228
 
223
229
  # Add 'short prefix' records to the array: prefixes of the string that are length (ngram_width - 1)
224
230
  if config[:index_short_prefixes]
225
231
  prefixes_seen = {}
226
- filtered_str.split(Regexp.compile(config[:word_separators].keys.join)).each do |word|
232
+ all_words.each do |word|
227
233
  next if word.length < config[:ngram_width]-1
228
234
  prefix = word[0...config[:ngram_width]-1]
229
235
  if prefixes_seen[prefix].nil? and (config[:stop_words][word].nil? or word == filtered_str)
@@ -236,7 +242,7 @@ module Mongoid::FullTextSearch
236
242
  # Add records to the array of ngrams for each full word in the string that isn't a stop word
237
243
  if config[:index_full_words]
238
244
  full_words_seen = {}
239
- filtered_str.split(Regexp.compile(config[:word_separators].keys.join)).each do |word|
245
+ all_words.each do |word|
240
246
  if word.length > 1 and full_words_seen[word].nil? and (config[:stop_words][word].nil? or word == filtered_str)
241
247
  ngram_array << {:ngram => word, :score => 1 + 1.0/filtered_str.length}
242
248
  full_words_seen[word] = true
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_fulltext}
8
- s.version = "0.5.4"
8
+ s.version = "0.5.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Windsor"]
12
- s.date = %q{2011-11-08}
12
+ s.date = %q{2011-12-19}
13
13
  s.description = %q{Full-text search for the Mongoid ORM, using n-grams extracted from text}
14
14
  s.email = %q{aaron.windsor@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_fulltext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-08 00:00:00.000000000 -05:00
12
+ date: 2011-12-19 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: unicode_utils
17
- requirement: &83097910 !ruby/object:Gem::Requirement
17
+ requirement: &74785740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *83097910
25
+ version_requirements: *74785740
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &83097670 !ruby/object:Gem::Requirement
28
+ requirement: &74785500 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *83097670
36
+ version_requirements: *74785500
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bson_ext
39
- requirement: &83097430 !ruby/object:Gem::Requirement
39
+ requirement: &74785260 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.3.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *83097430
47
+ version_requirements: *74785260
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &83097190 !ruby/object:Gem::Requirement
50
+ requirement: &74785020 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.5.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *83097190
58
+ version_requirements: *74785020
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &83096950 !ruby/object:Gem::Requirement
61
+ requirement: &74784780 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: 1.5.2
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *83096950
69
+ version_requirements: *74784780
70
70
  description: Full-text search for the Mongoid ORM, using n-grams extracted from text
71
71
  email: aaron.windsor@gmail.com
72
72
  executables: []
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 321098159
123
+ hash: -329929775
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements: