Class: ActiveDocument::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/ActiveDocument/finder.rb

Direct Known Subclasses

Base

Class Method Summary collapse

Class Method Details

.co_occurrence(element1, element1_namespace, element2, element2_namespace, query) ⇒ Object

returns a hash where the key is the terms of the co-occurrence separated by a | and the value is the frequency count



72
73
74
75
76
77
78
79
80
# File 'lib/ActiveDocument/finder.rb', line 72

def self.co_occurrence(element1, element1_namespace, element2, element2_namespace, query)
  pairs = @@ml_http.send_xquery(ActiveDocument::CoronaInterface.co_occurrence(element1, element1_namespace, element2, element2_namespace, query)).split("*")
  pair_hash = Hash.new
  pairs.each do |p|
    temp = p.split("|")
    pair_hash[temp[0] + '|' + temp[1]] = temp[2]
  end
  return pair_hash
end

.config(yaml_file) ⇒ Object



27
28
29
30
31
# File 'lib/ActiveDocument/finder.rb', line 27

def self.config(yaml_file)
  config = YAML.load_file(yaml_file)
  @@ml_http = ActiveDocument::MarkLogicHTTP.new(config['uri'], config['user_name'], config['password'])
  configure_logger(config)
end

.execute_attribute_finder(element, attribute, value, root = nil, element_namespace = nil, attribute_namespace = nil, root_namespace = nil, options = nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/ActiveDocument/finder.rb', line 57

def self.execute_attribute_finder(element, attribute, value, root = nil, element_namespace = nil, attribute_namespace = nil, root_namespace = nil, options = nil)
  response_array = ActiveDocument::CoronaInterface.find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, options)
  uri_array = response_array[:uri]
  @@log.info("ActiveDocument.execute_attribute_find_by_word at line #{__LINE__}: #{response_array}")
  SearchResults.new(@@ml_http.send_corona_request(uri_array[0], uri_array[1], nil, response_array[:post_parameters]))
end

.execute_finder(element, value, root = nil, element_namespace = nil, root_namespace = nil, options = nil) ⇒ Object



50
51
52
53
54
55
# File 'lib/ActiveDocument/finder.rb', line 50

def self.execute_finder(element, value, root = nil, element_namespace = nil, root_namespace = nil, options = nil)
  response_array = ActiveDocument::CoronaInterface.find_by_element(element, value, root, element_namespace, root_namespace, options)
  uri_array = response_array[:uri]
  @@log.info("ActiveDocument.execute_element_finder at line #{__LINE__}: #{response_array}")
  SearchResults.new(@@ml_http.send_corona_request(uri_array[0], uri_array[1], nil, response_array[:post_parameters]))
end

.method_missing(method_id, *arguments, &block) ⇒ Object

enables the dynamic finders



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ActiveDocument/finder.rb', line 34

def self.method_missing(method_id, *arguments, &block)
  @@log.debug("ActiveDocument::Finder at line #{__LINE__}: method called is #{method_id} with arguments #{arguments}")
  method = method_id.to_s
  # identify finder methods
  # todo verify these parameters
  if method =~ /find_by_attribute_(.*)$/ and arguments.length > 0
    namespace = arguments[1] if arguments.length == 2
    execute_attribute_finder($1.to_sym, arguments[0], nil, namespace)
  elsif method =~ /find_by_(.*)$/ and arguments.length > 0
    namespace = arguments[1] if arguments.length == 2
    execute_finder($1.to_sym, arguments[0], nil, namespace)
  else
    super
  end
end

.search(search_string, start = 1, page_length = 10, options = nil) ⇒ Object



64
65
66
67
68
69
# File 'lib/ActiveDocument/finder.rb', line 64

def self.search(search_string, start = 1, page_length = 10, options = nil)
  start ||= 1
  page_length ||= 10
  corona_array = ActiveDocument::CoronaInterface.search(search_string, start, page_length, options)
  SearchResults.new(@@ml_http.send_corona_request(corona_array[0], corona_array[1]))
end