has_searcher 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +1,30 @@
1
1
  class Boostificator
2
2
  MILLIS_IN_YEAR = 1000 * 60 * 60 * 24 * 365
3
+ PRECISION = 6
3
4
 
4
5
  attr_accessor :search, :field
5
6
 
6
- def initialize(options)
7
- self.search = options[:search]
8
- self.field = options[:field]
9
- end
10
-
11
- def m
12
- 1.0 / MILLIS_IN_YEAR
13
- end
7
+ attr_accessor :m, :x, :a, :b
14
8
 
15
- def a
16
- 1.1
17
- end
9
+ attr_accessor :now
18
10
 
19
- def b
20
- 1
21
- end
22
-
23
- def precision
24
- 6
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))
13
+ options.each do |field, value|
14
+ self.send("#{field}=", value)
15
+ end
25
16
  end
26
17
 
27
18
  def recip_min
28
- sprintf("%f", (recip * 10**precision).floor/10.0**precision)
19
+ sprintf("%f", (recip * 10**PRECISION).floor/10.0**PRECISION)
29
20
  end
30
21
 
31
22
  def recip_max
32
- sprintf("%f", (recip * 10**precision).ceil/10.0**precision)
23
+ sprintf("%f", (recip * 10**PRECISION).ceil/10.0**PRECISION)
33
24
  end
34
25
 
35
26
  def recip
36
- a / (m*now_ms + b)
37
- end
38
-
39
- def now
40
- 1.hour.since.change(:min => 0)
27
+ a / (m * now_ms + b)
41
28
  end
42
29
 
43
30
  def now_ms
@@ -50,7 +37,7 @@ class Boostificator
50
37
 
51
38
  def adjust_solr_params
52
39
  search.adjust_solr_params do |params|
53
- params[:q] = "{!boost b=map(recip(ms(#{now_s},#{field}),#{m},#{a},#{b}),#{recip_min},#{recip_max},1) defType=dismax}#{params[:q]}"
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]
54
41
  end
55
42
  end
56
43
  end
@@ -1,3 +1,3 @@
1
1
  module HasSearcher
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
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.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &16220020 !ruby/object:Gem::Requirement
16
+ requirement: &7410960 !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: *16220020
24
+ version_requirements: *7410960
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:
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  segments:
59
59
  - 0
60
- hash: -1870017393970293371
60
+ hash: -3427877683254692333
61
61
  required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  segments:
68
68
  - 0
69
- hash: -1870017393970293371
69
+ hash: -3427877683254692333
70
70
  requirements: []
71
71
  rubyforge_project: has_searcher
72
72
  rubygems_version: 1.8.15