Class: ActiveDocument::Finder
- Inherits:
-
Object
- Object
- ActiveDocument::Finder
- Defined in:
- lib/ActiveDocument/finder.rb
Direct Known Subclasses
Constant Summary collapse
- @@xquery_builder =
ActiveDocument::MarkLogicQueryBuilder.new
Class Method Summary collapse
-
.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.
- .config(yaml_file) ⇒ Object
- .execute_attribute_finder(element, attribute, value, root = nil, element_namespace = nil, attribute_namespace = nil, root_namespace = nil, options = nil) ⇒ Object
- .execute_finder(element, value, root = nil, element_namespace = nil, root_namespace = nil, options = nil) ⇒ Object
-
.method_missing(method_id, *arguments, &block) ⇒ Object
enables the dynamic finders.
- .search(search_string, start = 1, page_length = 10, options = nil) ⇒ Object
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(@@xquery_builder.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
29 30 31 32 33 |
# File 'lib/ActiveDocument/finder.rb', line 29 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
58 59 60 61 62 |
# File 'lib/ActiveDocument/finder.rb', line 58 def self.execute_attribute_finder(element, attribute, value, root = nil, element_namespace = nil, attribute_namespace = nil, root_namespace = nil, = nil) xquery = @@xquery_builder.find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, ) @@log.info("Finder.execute_attribute_finder at line #{__LINE__}: #{xquery}") SearchResults.new(@@ml_http.send_xquery(xquery)) end |
.execute_finder(element, value, root = nil, element_namespace = nil, root_namespace = nil, options = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/ActiveDocument/finder.rb', line 52 def self.execute_finder(element, value, root = nil, element_namespace = nil, root_namespace = nil, = nil) xquery = @@xquery_builder.find_by_element(element, value, root, element_namespace, root_namespace, ) @@log.info("Finder.execute_finder at line #{__LINE__}: #{xquery}") SearchResults.new(@@ml_http.send_xquery(xquery)) end |
.method_missing(method_id, *arguments, &block) ⇒ Object
enables the dynamic finders
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ActiveDocument/finder.rb', line 36 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, = nil) start ||= 1 page_length ||= 10 search_text = @@xquery_builder.search(search_string, start, page_length, ) SearchResults.new(@@ml_http.send_xquery(search_text)) end |