has_searcher 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/app/models/boostificator.rb +56 -0
- data/lib/has_searcher/formtastic.rb +54 -52
- data/lib/has_searcher/version.rb +1 -1
- metadata +7 -6
@@ -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
|
-
|
1
|
+
begin
|
2
|
+
require 'formtastic'
|
2
3
|
|
3
|
-
module Formtastic
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
+
alias_method_chain :default_input_type, :text_as_string_on_search
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
52
|
+
alias_method_chain :inputs, :search
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
59
|
+
alias_method_chain :buttons, :search
|
59
60
|
|
60
|
-
|
61
|
+
protected
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
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.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-
|
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: &
|
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: *
|
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: -
|
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: -
|
69
|
+
hash: -1870017393970293371
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project: has_searcher
|
71
72
|
rubygems_version: 1.8.15
|