Class: AdvancedSearch

Inherits:
Object
  • 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_definitionsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'common/advanced_search.rb', line 28

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



43
44
45
46
47
48
49
50
51
# File 'common/advanced_search.rb', line 43

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) ⇒ Object



18
19
20
21
22
23
24
25
# File 'common/advanced_search.rb', line 18

def self.solr_field_for(field)
  load_definitions
  field = @fields.fetch(field.to_s) do
    return field
  end

  field.solr_field
end