ximate 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.rdoc +11 -4
- data/ext/extconf.rb +8 -12
- data/lib/ximate/activerecord/relation.rb +2 -7
- data/lib/ximate/search.rb +14 -7
- data/lib/ximate/version.rb +1 -1
- metadata +8 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6701f4492e8a2bdfb6172881723dfd260ca05086
|
4
|
+
data.tar.gz: 33d89743a8233d50c137ed750f8501e019760d4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4360ef2a9467614f7bb722fc01c21c0992639a8e464f06180a239a0810c1858d50a4b9a2818f5f79ecb7b9553f75dab939b16d782e499e07904e13a28681bf0
|
7
|
+
data.tar.gz: b3781c4999b35bdabb504d813ad34f993acbfdbe0a8bb2c9f07efb42a06248edb202919ede79b97899430e241179fdddfb75b5f04b55d004edb415cc42b3c6c1
|
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -42,13 +42,10 @@ Then you can perform a search
|
|
42
42
|
Post.asearch('Hello world').where(:public => true).limit(5)
|
43
43
|
|
44
44
|
+asearch+ method is chainable with the usual activerecord methods.
|
45
|
-
You can also order the results by rank (calculate by ximate)
|
46
|
-
|
47
|
-
Post.asearch('Hello world').order('rank DESC').where(:public => true)
|
48
45
|
|
49
46
|
The cool stuff is that if you search with
|
50
47
|
|
51
|
-
Post.asearch('Hello worlds').
|
48
|
+
Post.asearch('Hello worlds').where(:public => true)
|
52
49
|
|
53
50
|
the results will be the same!
|
54
51
|
The error allowed by Ximate can be expressed as a percentage by setting the option <tt>Ximate::OPTIONS[:match_error_percent]</tt>.
|
@@ -58,9 +55,19 @@ Finally you can set some Ximate options in your initializers.
|
|
58
55
|
|
59
56
|
Ximate::OPTIONS[:match_error_percent] = 20
|
60
57
|
Ximate::OPTIONS[:ignore_word_short_than] = 2
|
58
|
+
Ximate::OPTIONS[:async] = false
|
61
59
|
Ximate::OPTIONS[:logger] = true
|
62
60
|
Ximate::OPTIONS[:debug] = false
|
63
61
|
|
62
|
+
=== Ordering
|
63
|
+
|
64
|
+
You can order the results by rank (calculate by Ximate)
|
65
|
+
|
66
|
+
Post.asearch('Hello world').order('rank DESC').where(:public => true)
|
67
|
+
|
68
|
+
Unfortunately to do this, Ximate use the +FIELD+ function supported only by MySQL.
|
69
|
+
So <b>the ordering by rank works only with MySQL</b>.
|
70
|
+
|
64
71
|
== Questions or problems?
|
65
72
|
|
66
73
|
If you have any issues please add an {issue on
|
data/ext/extconf.rb
CHANGED
@@ -2,31 +2,27 @@ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
|
|
2
2
|
|
3
3
|
require 'mkmf'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# First search /opt/local for macports
|
5
|
+
INCLUDE_DIRS = [
|
6
|
+
# Check the ruby install locations
|
7
|
+
RbConfig::CONFIG['includedir'],
|
8
|
+
# First earch /opt/local for macports
|
10
9
|
'/opt/local/include',
|
11
10
|
# Then search /usr/local for people that installed from source
|
12
11
|
'/usr/local/include',
|
13
|
-
# Check the ruby install locations
|
14
|
-
INCLUDEDIR,
|
15
12
|
# Finally fall back to /usr
|
16
13
|
'/usr/include',
|
17
14
|
]
|
18
15
|
|
19
16
|
LIB_DIRS = [
|
17
|
+
# Check the ruby install locations
|
18
|
+
RbConfig::CONFIG['libdir'],
|
20
19
|
# First search /opt/local for macports
|
21
20
|
'/opt/local/lib',
|
22
21
|
# Then search /usr/local for people that installed from source
|
23
22
|
'/usr/local/lib',
|
24
|
-
# Check the ruby install locations
|
25
|
-
LIBDIR,
|
26
23
|
# Finally fall back to /usr
|
27
24
|
'/usr/lib',
|
28
25
|
]
|
29
26
|
|
30
|
-
dir_config('fuzzy_search', HEADER_DIRS, LIB_DIRS)
|
31
|
-
|
32
|
-
create_makefile('fuzzy_search/fuzzy_search')
|
27
|
+
#dir_config('fuzzy_search', HEADER_DIRS, LIB_DIRS)
|
28
|
+
create_makefile('fuzzy_search/fuzzy_search')
|
@@ -3,15 +3,10 @@ module ActiveRecord
|
|
3
3
|
class Relation
|
4
4
|
attr_accessor :ranks
|
5
5
|
|
6
|
-
alias_method :orig_initialize, :initialize
|
7
6
|
alias_method :orig_order, :order
|
8
7
|
|
9
|
-
def initialize(klass, table)
|
10
|
-
@ranks = {}
|
11
|
-
orig_initialize(klass, table)
|
12
|
-
end
|
13
|
-
|
14
8
|
def order(*args)
|
9
|
+
@ranks ||= {}
|
15
10
|
if args[0] =~ /^rank/i
|
16
11
|
unless @ranks.empty?
|
17
12
|
tokens = args[0].split(' ')
|
@@ -29,4 +24,4 @@ module ActiveRecord
|
|
29
24
|
|
30
25
|
end
|
31
26
|
|
32
|
-
end
|
27
|
+
end
|
data/lib/ximate/search.rb
CHANGED
@@ -3,6 +3,7 @@ module Ximate
|
|
3
3
|
DATA = {}
|
4
4
|
OPTIONS = {:match_error_percent => 20,
|
5
5
|
:ignore_word_short_than => 2,
|
6
|
+
:async => false,
|
6
7
|
:logger => true,
|
7
8
|
:debug => false}
|
8
9
|
|
@@ -23,11 +24,17 @@ module Ximate
|
|
23
24
|
|
24
25
|
after_save { |proc| proc.update_index(I18n.locale, &block) }
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
calculate_indices = Proc.new do
|
28
|
+
now = Time.now
|
29
|
+
self.to_s.classify.constantize.find_in_batches(batch_size: 100) do |group|
|
30
|
+
group.each do |p|
|
31
|
+
p.update_index(locale, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
puts "\b\b=> Build XIMATE hash data for '#{table}' in #{Time.now - now}s." if OPTIONS[:logger]
|
29
35
|
end
|
30
|
-
|
36
|
+
|
37
|
+
OPTIONS[:async] ? Thread.new{calculate_indices.call} : calculate_indices.call
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
@@ -55,8 +62,8 @@ module Ximate
|
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
58
|
-
return
|
59
|
-
rel =
|
65
|
+
return none if matches.empty?
|
66
|
+
rel = all
|
60
67
|
rel.ranks = matches
|
61
68
|
rel.where("#{table}.id IN (#{matches.keys.join(',')})")
|
62
69
|
# select("*, #{gen_if_select(matches)} AS RANK").where("#{table}.id IN (#{matches.keys.join(',')})")
|
@@ -111,4 +118,4 @@ module Ximate
|
|
111
118
|
|
112
119
|
end
|
113
120
|
|
114
|
-
end
|
121
|
+
end
|
data/lib/ximate/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ximate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Enrico Pilotto
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Approximate fuzzy search for Ruby on Rails activerecord models.
|
15
14
|
email:
|
@@ -19,7 +18,7 @@ extensions:
|
|
19
18
|
- ext/extconf.rb
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
23
22
|
- Gemfile
|
24
23
|
- README.rdoc
|
25
24
|
- Rakefile
|
@@ -35,27 +34,26 @@ files:
|
|
35
34
|
homepage: https://github.com/pioz/ximate
|
36
35
|
licenses:
|
37
36
|
- MIT
|
37
|
+
metadata: {}
|
38
38
|
post_install_message:
|
39
39
|
rdoc_options: []
|
40
40
|
require_paths:
|
41
41
|
- lib
|
42
42
|
- ext
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
44
|
requirements:
|
46
|
-
- -
|
45
|
+
- - ">="
|
47
46
|
- !ruby/object:Gem::Version
|
48
47
|
version: '0'
|
49
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
49
|
requirements:
|
52
|
-
- -
|
50
|
+
- - ">="
|
53
51
|
- !ruby/object:Gem::Version
|
54
52
|
version: '0'
|
55
53
|
requirements: []
|
56
54
|
rubyforge_project: ximate
|
57
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.6.8
|
58
56
|
signing_key:
|
59
|
-
specification_version:
|
57
|
+
specification_version: 4
|
60
58
|
summary: Approximate fuzzy search for Ruby on Rails
|
61
59
|
test_files: []
|