Class: ActiveDocument::CoronaInterface
- Inherits:
-
Object
- Object
- ActiveDocument::CoronaInterface
- Defined in:
- lib/ActiveDocument/corona_interface.rb
Overview
CoronaInterface methods always return a hash. This hash will always contain at least a uri key with associated value
Class Method Summary collapse
- .co_occurrence(element1, element1_namespace, element2, element2_namespace, query) ⇒ Object
- .declare_namespace(prefix, uri) ⇒ Object
-
.delete(uri) ⇒ Object
uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb.
- .delete_all_namespaces ⇒ Object
- .find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, options = nil) ⇒ Object
- .find_by_element(element, value, root, element_namespace, root_namespace, options = nil) ⇒ Object
-
.find_by_word(word, root, root_namespace, options = nil) ⇒ Object
This method does a full text search uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb post_parameters: a hash of all post parameters to be submitted.
- .load(uri) ⇒ Object
- .lookup_namespace(uri) ⇒ An array where the first item is the string uri for the request and the second item is the http verb
-
.save(uri) ⇒ Object
uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb.
- .search(search_text, start, page_length, options) ⇒ Object
Class Method Details
.co_occurrence(element1, element1_namespace, element2, element2_namespace, query) ⇒ Object
153 154 155 |
# File 'lib/ActiveDocument/corona_interface.rb', line 153 def self.co_occurrence(element1, element1_namespace, element2, element2_namespace, query) # Not supported by Corona at this time end |
.declare_namespace(prefix, uri) ⇒ Object
157 158 159 |
# File 'lib/ActiveDocument/corona_interface.rb', line 157 def self.declare_namespace(prefix, uri) ["/manage/namespace/#{prefix}?uri=#{uri}", :post] end |
.delete(uri) ⇒ Object
uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb
31 32 33 |
# File 'lib/ActiveDocument/corona_interface.rb', line 31 def self.delete(uri) {:uri => ["/store?uri=#{uri}", :delete]} end |
.delete_all_namespaces ⇒ Object
167 168 169 |
# File 'lib/ActiveDocument/corona_interface.rb', line 167 def self.delete_all_namespaces ["/manage/namespaces/", :delete] end |
.find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, options = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ActiveDocument/corona_interface.rb', line 108 def self.find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, = nil) response = Hash.new post_parameters = Hash.new = self.(, root, root_namespace) unless root.nil? if root_namespace.nil? root_expression = root else root_expression = .searchable_expression[root_namespace] + ":" + root unless root_namespace.nil? end end element_qname = element element_qname.insert(0, element_namespace + ":") unless element_namespace.nil? attribute_qname = attribute.to_s attribute_qname.insert(0, attribute_namespace + ":") unless attribute_namespace.nil? # todo this query is the more permissive contains. Deal with more restrictive equals as well structured_query = "{\"element\":\"#{element_qname}\",\"attribute\":\"#{attribute_qname}\", \"contains\":\"#{value}\"}" response[:uri] = ["/search", :post] post_parameters[:structuredQuery] = structured_query post_parameters[:outputFormat] = "xml" post_parameters[:include] = "snippet" post_parameters[:include] = "confidence" if .directory_constraint if .directory_depth == 1 post_parameters[:inDirectory] = .directory_constraint else post_parameters[:underDirectory] = .directory_constraint end end response[:post_parameters] = post_parameters response end |
.find_by_element(element, value, root, element_namespace, root_namespace, options = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ActiveDocument/corona_interface.rb', line 77 def self.find_by_element(element, value, root, element_namespace, root_namespace, = nil) response = Hash.new post_parameters = Hash.new = self.(, root, root_namespace) unless root.nil? if root_namespace.nil? root_expression = root else root_expression = .searchable_expression[root_namespace] + ":" + root unless root_namespace.nil? end end element_qname = element.to_s element_qname.insert(0, element_namespace + ":") unless element_namespace.nil? # todo this query is the more permissive contains. Deal with more restrictive equals as well structured_query = "{\"element\":\"#{element_qname}\", \"contains\":\"#{value}\"}" response[:uri] = ["/search", :post] post_parameters[:structuredQuery] = structured_query post_parameters[:outputFormat] = "xml" post_parameters[:include] = "snippet" post_parameters[:include] = "confidence" if .directory_constraint if .directory_depth == 1 post_parameters[:inDirectory] = .directory_constraint else post_parameters[:underDirectory] = .directory_constraint end end response[:post_parameters] = post_parameters response end |
.find_by_word(word, root, root_namespace, options = nil) ⇒ Object
This method does a full text search uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb post_parameters: a hash of all post parameters to be submitted
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ActiveDocument/corona_interface.rb', line 48 def self.find_by_word(word, root, root_namespace, = nil) #todo deal with paging response = Hash.new post_parameters = Hash.new = self.(, root, root_namespace) unless root.nil? if root_namespace.nil? root_expression = root else root_expression = .searchable_expression[root_namespace] + ":" + root unless root_namespace.nil? end end structured_query = "{\"underElement\":\"#{root_expression}\",\"query\":{\"wordAnywhere\":\"#{word}\"}}" response[:uri] = ["/search", :post] post_parameters[:structuredQuery] = structured_query post_parameters[:outputFormat] = "xml" post_parameters[:include] = "snippet" post_parameters[:include] = "confidence" if .directory_constraint if .directory_depth == 1 post_parameters[:inDirectory] = .directory_constraint else post_parameters[:underDirectory] = .directory_constraint end end response[:post_parameters] = post_parameters response end |
.load(uri) ⇒ Object
23 24 25 |
# File 'lib/ActiveDocument/corona_interface.rb', line 23 def self.load(uri) {:uri => ["/store?uri=#{uri}", :get]} end |
.lookup_namespace(uri) ⇒ An array where the first item is the string uri for the request and the second item is the http verb
163 164 165 |
# File 'lib/ActiveDocument/corona_interface.rb', line 163 def self.lookup_namespace(uri) ["/manage/namespace/#{uri}", :get] end |
.save(uri) ⇒ Object
uri: an array where the first element is the uri to be used for the REST call and the second element is the http verb
39 40 41 |
# File 'lib/ActiveDocument/corona_interface.rb', line 39 def self.save(uri) {:uri => ["/store?uri=#{uri}", :put]} end |
.search(search_text, start, page_length, options) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ActiveDocument/corona_interface.rb', line 141 def self.search(search_text, start, page_length, ) if && .directory_constraint directory_string = nil if .directory_depth == 1 directory_string = "&inDirectory=" + .directory_constraint else directory_string = "&underDirectory=" +.directory_constraint end end ["/search?stringQuery=#{search_text}&start=#{start}&end=#{start + page_length -1}&outputFormat=xml&include=snippet&include=confidence#{directory_string}", :get] end |