has_searcher 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app/models/boostificator.rb +27 -22
- data/lib/has_searcher/version.rb +1 -1
- metadata +3 -9
@@ -6,38 +6,43 @@ class Boostificator
|
|
6
6
|
|
7
7
|
attr_accessor :m, :x, :a, :b
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(options)
|
12
|
-
options.reverse_merge!(:a => 1.0, :b => 1.0, :m => 1.0 / MILLIS_IN_YEAR, :now => 1.hour.since.change(:min => 0))
|
9
|
+
def initialize(options={})
|
10
|
+
options.reverse_merge!(:a => 1.0, :b => 1.0, :m => 1.0 / MILLIS_IN_YEAR)
|
13
11
|
options.each do |field, value|
|
14
12
|
self.send("#{field}=", value)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
def recip_min
|
19
|
-
sprintf("%f", (recip * 10**PRECISION).floor/10.0**PRECISION)
|
20
|
-
end
|
21
16
|
|
22
|
-
def
|
23
|
-
|
17
|
+
def adjust_solr_params
|
18
|
+
search.adjust_solr_params do |params|
|
19
|
+
params[:q] = "{!boost b=map(recip(abs(ms(#{now_s},#{field})),#{m},#{a},#{b}),#{recip_min},#{recip_max},1) defType=dismax}#{params[:q]}" if params[:q]
|
20
|
+
end
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
private
|
24
|
+
def now
|
25
|
+
@now ||= DateTime.now.change(:min => 0)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def recip
|
29
|
+
@recip ||= a / (m * now_ms + b)
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def now_ms
|
33
|
+
@now_ms ||= now.to_i * 1000
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
params[:q] = "{!boost b=map(recip(ms(#{now_s},#{field}),#{m},#{a},#{b}),#{recip_min},#{recip_max},1) defType=dismax}#{params[:q]}" if params[:q]
|
36
|
+
def now_s
|
37
|
+
@now_s ||= now.utc.to_datetime.to_time.iso8601
|
41
38
|
end
|
42
|
-
|
39
|
+
|
40
|
+
def recip_min
|
41
|
+
@recip_min ||= sprintf("%f", (recip * 10**PRECISION).floor/10.0**PRECISION)
|
42
|
+
end
|
43
|
+
|
44
|
+
def recip_max
|
45
|
+
@recip_max ||= sprintf("%f", (recip * 10**PRECISION).ceil/10.0**PRECISION)
|
46
|
+
end
|
47
|
+
|
43
48
|
end
|
data/lib/has_searcher/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &13490880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *13490880
|
25
25
|
description: ! "This gem adds ability to construct search objects for indexed models.\n
|
26
26
|
\ It works with sunspot, inherited_resources and formtastic"
|
27
27
|
email:
|
@@ -55,18 +55,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- - ! '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
hash: -3427877683254692333
|
61
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
59
|
none: false
|
63
60
|
requirements:
|
64
61
|
- - ! '>='
|
65
62
|
- !ruby/object:Gem::Version
|
66
63
|
version: '0'
|
67
|
-
segments:
|
68
|
-
- 0
|
69
|
-
hash: -3427877683254692333
|
70
64
|
requirements: []
|
71
65
|
rubyforge_project: has_searcher
|
72
66
|
rubygems_version: 1.8.15
|