has_searcher 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ class Boostificator
2
+ MILLIS_IN_YEAR = 1000 * 60 * 60 * 24 * 365
3
+
4
+ attr_accessor :search, :field
5
+
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
14
+
15
+ def a
16
+ 1.1
17
+ end
18
+
19
+ def b
20
+ 1
21
+ end
22
+
23
+ def precision
24
+ 6
25
+ end
26
+
27
+ def recip_min
28
+ sprintf("%f", (recip * 10**precision).floor/10.0**precision)
29
+ end
30
+
31
+ def recip_max
32
+ sprintf("%f", (recip * 10**precision).ceil/10.0**precision)
33
+ end
34
+
35
+ def recip
36
+ a / (m*now_ms + b)
37
+ end
38
+
39
+ def now
40
+ 1.hour.since.change(:min => 0)
41
+ end
42
+
43
+ def now_ms
44
+ now.to_i * 1000
45
+ end
46
+
47
+ def now_s
48
+ now.utc.to_datetime.to_time.iso8601
49
+ end
50
+
51
+ def adjust_solr_params
52
+ 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]}"
54
+ end
55
+ end
56
+ end
@@ -1,70 +1,72 @@
1
- require 'formtastic'
1
+ begin
2
+ require 'formtastic'
2
3
 
3
- module Formtastic
4
- module Helpers
5
- module FormHelper
6
- def semantic_search_form_for(name, *args, &proc)
7
- options = args.extract_options!
8
- options.reverse_merge! :html => {:method => :get}
9
- url = params[:controller].sub(/\/\w+$/, '').split("/").map(&:underscore)
10
- options[:url] ||= url.push name.to_s.pluralize
11
- semantic_form_for searcher_for(name), *(args << options), &proc
4
+ module Formtastic
5
+ module Helpers
6
+ module FormHelper
7
+ def semantic_search_form_for(name, *args, &proc)
8
+ options = args.extract_options!
9
+ options.reverse_merge! :html => {:method => :get}
10
+ url = params[:controller].sub(/\/\w+$/, '').split("/").map(&:underscore)
11
+ options[:url] ||= url.push name.to_s.pluralize
12
+ semantic_form_for searcher_for(name), *(args << options), &proc
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- module SemanticFormHelper
17
- def semantic_search_form_for(*args)
18
- Formtastic::Helpers::FormHelper.semantic_search_form_for(args)
17
+ module SemanticFormHelper
18
+ def semantic_search_form_for(*args)
19
+ Formtastic::Helpers::FormHelper.semantic_search_form_for(args)
20
+ end
19
21
  end
20
- end
21
22
 
22
- class SemanticFormBuilder
23
- def search_button(options={})
24
- commit_button I18n.t('search'), options.merge(button_html: {name: nil},
25
- wrapper_html: {class: 'button'})
26
- end
23
+ class SemanticFormBuilder
24
+ def search_button(options={})
25
+ commit_button I18n.t('search'), options.merge(button_html: {name: nil},
26
+ wrapper_html: {class: 'button'})
27
+ end
27
28
 
28
- def default_input_type_with_text_as_string_on_search(method, options={})
29
- if object.is_a?(Search) && object.class.respond_to?(:has_enum?) && !object.class.has_enum?(method) && object.column_for_attribute(method).try(:type) == :text
30
- :string
31
- else
32
- default_input_type_without_text_as_string_on_search(method, options)
29
+ def default_input_type_with_text_as_string_on_search(method, options={})
30
+ if object.is_a?(Search) && object.class.respond_to?(:has_enum?) && !object.class.has_enum?(method) && object.column_for_attribute(method).try(:type) == :text
31
+ :string
32
+ else
33
+ default_input_type_without_text_as_string_on_search(method, options)
34
+ end
33
35
  end
34
- end
35
36
 
36
- alias_method_chain :default_input_type, :text_as_string_on_search
37
+ alias_method_chain :default_input_type, :text_as_string_on_search
37
38
 
38
- def inputs_with_search(*args, &block)
39
- if args.empty? && object.is_a?(Search)
40
- args = object.class.column_names.collect do | column |
41
- if belongs_to? column
42
- column = column.gsub /_id$/, ''
43
- end
44
- column
45
- end.map(&:to_sym)
46
- args -= [:term, :order_by, :per_page]
39
+ def inputs_with_search(*args, &block)
40
+ if args.empty? && object.is_a?(Search)
41
+ args = object.class.column_names.collect do | column |
42
+ if belongs_to? column
43
+ column = column.gsub /_id$/, ''
44
+ end
45
+ column
46
+ end.map(&:to_sym)
47
+ args -= [:term, :order_by, :per_page]
48
+ end
49
+ inputs_without_search(*args, &block)
47
50
  end
48
- inputs_without_search(*args, &block)
49
- end
50
51
 
51
- alias_method_chain :inputs, :search
52
+ alias_method_chain :inputs, :search
52
53
 
53
- def buttons_with_search(*args, &block)
54
- args = :search if args.empty? && object.is_a?(Search)
55
- buttons_without_search(*args, &block)
56
- end
54
+ def buttons_with_search(*args, &block)
55
+ args = :search if args.empty? && object.is_a?(Search)
56
+ buttons_without_search(*args, &block)
57
+ end
57
58
 
58
- alias_method_chain :buttons, :search
59
+ alias_method_chain :buttons, :search
59
60
 
60
- protected
61
+ protected
61
62
 
62
- def belongs_to?(method)
63
- method = method.to_s
64
- method =~ /_id$/ &&
65
- (reflect = object.class.reflect_on_association(method.gsub(/_id$/, '').to_sym)) &&
66
- reflect.macro == :belongs_to
67
- end
63
+ def belongs_to?(method)
64
+ method = method.to_s
65
+ method =~ /_id$/ &&
66
+ (reflect = object.class.reflect_on_association(method.gsub(/_id$/, '').to_sym)) &&
67
+ reflect.macro == :belongs_to
68
+ end
69
+ end
68
70
  end
71
+ rescue LoadError
69
72
  end
70
-
@@ -1,3 +1,3 @@
1
1
  module HasSearcher
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
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.13
4
+ version: 0.0.14
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-03-28 00:00:00.000000000 Z
12
+ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &19854360 !ruby/object:Gem::Requirement
16
+ requirement: &16220020 !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: *19854360
24
+ version_requirements: *16220020
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:
@@ -36,6 +36,7 @@ files:
36
36
  - has_searcher.gemspec
37
37
  - lib/app/controllers/crud_controller.rb
38
38
  - lib/app/controllers/suggestions_controller.rb
39
+ - lib/app/models/boostificator.rb
39
40
  - lib/app/models/search.rb
40
41
  - lib/has_searcher.rb
41
42
  - lib/has_searcher/base.rb
@@ -56,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
57
  version: '0'
57
58
  segments:
58
59
  - 0
59
- hash: -2105223472168161994
60
+ hash: -1870017393970293371
60
61
  required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  none: false
62
63
  requirements:
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  version: '0'
66
67
  segments:
67
68
  - 0
68
- hash: -2105223472168161994
69
+ hash: -1870017393970293371
69
70
  requirements: []
70
71
  rubyforge_project: has_searcher
71
72
  rubygems_version: 1.8.15