has_searcher 0.0.95.3 → 0.0.95.4
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/searcher/boostificator.rb +35 -29
- data/lib/has_searcher/version.rb +1 -1
- metadata +4 -4
@@ -6,50 +6,56 @@ class Searcher::Boostificator
|
|
6
6
|
|
7
7
|
attr_accessor :m, :x, :a, :b
|
8
8
|
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :now
|
10
|
+
|
11
|
+
attr_accessor :boosts
|
10
12
|
|
11
13
|
def initialize(boost_field, options={})
|
12
14
|
self.boost_field = boost_field
|
13
|
-
options.reverse_merge!(:a => 1.0, :b => 1.0, :m => 1.0 / MILLIS_IN_YEAR
|
15
|
+
options.reverse_merge!(:a => 1.0, :b => 1.0, :m => 1.0 / MILLIS_IN_YEAR)
|
14
16
|
options.each do |attribute, value|
|
15
17
|
self.send("#{attribute}=", value)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def adjust_solr_params(searcher)
|
22
|
+
searcher.configuration.scope do |sunspot|
|
23
|
+
sunspot.adjust_solr_params do |params|
|
24
|
+
params[:boost] = boosts + [recip_s]
|
25
|
+
params[:defType] = 'edismax'
|
26
|
+
end
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
30
|
+
def boosts
|
31
|
+
@boosts ||= []
|
32
|
+
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def recip_s
|
35
|
+
@recip_s ||= "map(recip(abs(ms(#{now_s},#{boost_field})),#{m},#{a},#{b}),#{recip_min},#{recip_max},1)"
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def now
|
39
|
+
@now ||= HasSearcher.cacheable_now
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def recip
|
43
|
+
@recip ||= a / (m * now_ms + b)
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
def now_ms
|
47
|
+
@now_ms ||= now.to_i * 1000
|
48
|
+
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
def now_s
|
51
|
+
@now_s ||= now.utc.to_datetime.to_time.iso8601
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
def recip_min
|
55
|
+
@recip_min ||= sprintf("%f", (recip * 10**PRECISION).floor/10.0**PRECISION)
|
56
|
+
end
|
57
|
+
|
58
|
+
def recip_max
|
59
|
+
@recip_max ||= sprintf("%f", (recip * 10**PRECISION).ceil/10.0**PRECISION)
|
60
|
+
end
|
55
61
|
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.95.
|
4
|
+
version: 0.0.95.4
|
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: 2012-10-
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
segments:
|
148
148
|
- 0
|
149
|
-
hash:
|
149
|
+
hash: 979056079572079856
|
150
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
151
|
none: false
|
152
152
|
requirements:
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
segments:
|
157
157
|
- 0
|
158
|
-
hash:
|
158
|
+
hash: 979056079572079856
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
161
|
rubygems_version: 1.8.24
|