ximate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), 'ximate/search')
2
- require File.join(File.dirname(__FILE__), 'ximate/activerecord/relation')
2
+ #require File.join(File.dirname(__FILE__), 'ximate/activerecord/relation')
3
3
  require File.join(File.dirname(__FILE__), '../ext/fuzzy_search')
4
4
 
5
5
  ActiveRecord::Base.send(:include, Ximate)
@@ -1,9 +1,9 @@
1
1
  module Ximate
2
2
 
3
3
  DATA = {}
4
- OPTIONS = {:order_by_rank => true,
5
- :match_error_percent => 20,
4
+ OPTIONS = {:match_error_percent => 20,
6
5
  :ignore_word_short_than => 2,
6
+ #:order_by_rank => true,
7
7
  :logger => true,
8
8
  :debug => false}
9
9
 
@@ -27,7 +27,7 @@ module Ximate
27
27
  self.to_s.classify.constantize.all.each do |p|
28
28
  p.update_index(locale, &block)
29
29
  end
30
- puts "\b\b=> Build XIMATE hash data for '#{table}' in #{Time.now - now}." if OPTIONS[:logger]
30
+ puts "\b\b=> Build XIMATE hash data for '#{table}' in #{Time.now - now}s." if OPTIONS[:logger]
31
31
  end
32
32
  end
33
33
 
@@ -55,9 +55,23 @@ module Ximate
55
55
  end
56
56
  end
57
57
  return where('1 = 0') if matches.empty?
58
- rel = scoped
59
- rel.ranks = matches if OPTIONS[:order_by_rank]
60
- rel.where("#{table}.id IN (#{matches.keys.join(',')})")
58
+ #rel = scoped
59
+ #rel.ranks = matches if OPTIONS[:order_by_rank]
60
+ #rel.where("#{table}.id IN (#{matches.keys.join(',')})")
61
+ select("*, #{gen_if_select(matches)} AS RANK").where("#{table}.id IN (#{matches.keys.join(',')})")
62
+ end
63
+
64
+ private
65
+
66
+ def gen_if_select(matches)
67
+ tmp = 'IF(id=myid,myrank,if)'
68
+ str = 'IF(id=myid,myrank,if)'
69
+ matches.each do |id, rank|
70
+ str.gsub!('myid', id.to_s)
71
+ str.gsub!('myrank', rank.to_s)
72
+ str.gsub!('if', tmp)
73
+ end
74
+ return str.gsub(tmp, '0')
61
75
  end
62
76
 
63
77
  end
@@ -1,3 +1,3 @@
1
1
  module Ximate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ximate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Enrico Pilotto
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-05 00:00:00 +02:00
13
+ date: 2011-05-09 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16