fullname-matcher 1.0.5 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -144,17 +144,27 @@ module Fullname::Matcher
144
144
  private
145
145
 
146
146
  def match_first_last_and_suffix(name)
147
- conditions = []
148
- queries = []
147
+ conditions = []
148
+ queries = []
149
+ firstname_filter = nil
149
150
  conditions << '(' + @condition + ')' if @condition
150
151
  queries << '(placeholder)'
151
- conditions << "(#{@mapping[:first]} = ? OR #{@mapping[:first]} REGEXP ?)"
152
- queries << name[:first]
153
- queries << '^' + name[:first][0].chr + '([.]?' + (name[:first] =~ /^[a-z]\.?$/i ? '|[a-z]+' : '') + ')$'
154
152
  conditions << "#{@mapping[:last]} = ?"
155
153
  queries << name[:last]
154
+ # if first name is abbreviation, fetch all firstnames then filter with Ruby regexp
155
+ if name[:first] =~ /^[a-z]\.?$/i
156
+ firstname_filter = %r{^#{name[:first][0].chr}.*}i
157
+ # otherwise search directly in database, because search with regexp in DB won't use indexer
158
+ else
159
+ conditions << "(#{@mapping[:first]} IN (?, ?, ?))"
160
+ queries << name[:first]
161
+ queries << name[:first][0].chr
162
+ queries << name[:first][0].chr + '.'
163
+ end
156
164
  queries[0] = conditions.join(' AND ')
157
- matched_list = @table.all(:conditions => queries)
165
+ matched_list = @table.all(:conditions => queries)
166
+ matched_list.delete_if{|r| r.send(@mapping[:first]) !~ firstname_filter} if firstname_filter
167
+
158
168
  unless @options[:skip_match_suffix]
159
169
 
160
170
  # exactly match suffix
@@ -1,5 +1,5 @@
1
1
  module Fullname
2
2
  module Matcher
3
- VERSION = '1.0.5'
3
+ VERSION = '1.0.8'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fullname-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-15 00:00:00.000000000 Z
12
+ date: 2013-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fullname-parser