Class: AdvancedSearch
- Inherits:
-
Object
show all
- Defined in:
- common/advanced_search.rb
Defined Under Namespace
Classes: AdvancedSearchField
Class Method Summary
collapse
Class Method Details
.define_field(opts) ⇒ Object
3
4
5
6
|
# File 'common/advanced_search.rb', line 3
def self.define_field(opts)
@fields ||= {}
@fields[opts.fetch(:name).to_s] = AdvancedSearchField.new(opts)
end
|
.fields_matching(query) ⇒ Object
9
10
11
12
13
14
15
|
# File 'common/advanced_search.rb', line 9
def self.fields_matching(query)
load_definitions
@fields.values.select {|field|
query.all? {|k, v| Array(field[k]).map(&:to_s).include?(v.to_s)}
}
end
|
.load_definitions ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'common/advanced_search.rb', line 32
def self.load_definitions
unless @loaded
require 'search_definitions'
ASUtils.find_local_directories("search_definitions.rb").each do |file|
if File.exist?(file)
load File.absolute_path(file)
end
end
@loaded = true
end
end
|
.set_default(type, name) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'common/advanced_search.rb', line 47
def self.set_default(type, name)
raise "Unknown field: #{name}" unless @fields.has_key?(name)
@fields.values.each do |field|
if field.type == type.to_s
field.is_default = (field.name == name)
end
end
end
|
.solr_field_for(field, protect_unpublished: false) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'common/advanced_search.rb', line 18
def self.solr_field_for(field, protect_unpublished: false)
load_definitions
field = @fields.fetch(field.to_s) do
return field
end
if protect_unpublished && field[:protects_unpublished]
"#{field.solr_field}_published"
else
field.solr_field
end
end
|