Class: ActiveDocument::MarkLogicQueryBuilder

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

Overview

todo create new unit tests for this class - the old ones were no good

Instance Method Summary collapse

Instance Method Details

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



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 84

def co_occurrence(element1, element1_namespace, element2, element2_namespace, query)
  <<-GENERATED
    declare namespace one = "#{element1_namespace}";
    declare namespace two = "#{element2_namespace}";
    import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
    let $pairs := cts:element-value-co-occurrences(xs:QName('one:#{element1}'), xs:QName('two:#{element2}'), ('frequency-order', 'fragment-frequency','ordered'), cts:query(search:parse('#{query}')))
    return
    for $pair in $pairs
    return
      ($pair/cts:value[1]/text(),"|",$pair/cts:value[2]/text(),"|",cts:frequency($pair),"*")
  GENERATED
end

#delete(uri) ⇒ Object



23
24
25
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 23

def delete(uri)
  "xdmp:document-delete('#{uri}')"
end

#find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, options = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 60

def find_by_attribute(element, attribute, value, root, element_namespace, attribute_namespace, root_namespace, options = nil)
  xquery = <<-GENERATED
    import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
    search:search("attribute:#{value}",
  GENERATED
  search_options = setup_options(options, root, root_namespace)
  attribute_constraint = ActiveDocument::MarkLogicSearchOptions::AttributeConstraint.new(attribute_namespace, attribute, element_namespace, element)
  search_options.attribute_constraints["attribute"] = attribute_constraint
  xquery << search_options.to_s
  xquery << ')'
end

#find_by_element(element, value, root, element_namespace, root_namespace, options = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 48

def find_by_element(element, value, root, element_namespace, root_namespace, options = nil)
  xquery = <<-GENERATED
    import module namespace search = "http://marklogic.com/appservices/search"at "/MarkLogic/appservices/search/search.xqy";
    search:search('find_by_element:\"#{value}\"',
  GENERATED
  search_options = setup_options(options, root, root_namespace)
  search_options.word_constraints["find_by_element"] = {"namespace" => element_namespace, "element" => element}
  xquery << search_options.to_s
  xquery << ')'
end

#find_by_word(word, root, root_namespace, options = nil) ⇒ Object

This method does a full text search



38
39
40
41
42
43
44
45
46
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 38

def find_by_word(word, root, root_namespace, options = nil)
  xquery = <<-GENERATED
    import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
    search:search("#{word}",
  GENERATED
 search_options = setup_options(options, root, root_namespace)
  xquery << search_options.to_s
  xquery << ')'
end

#load(uri) ⇒ Object



19
20
21
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 19

def load(uri)
  "fn:doc('#{uri}')"
end

#save(document, uri) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/ActiveDocument/mark_logic_query_builder.rb', line 27

def save(document, uri)
  xquery = <<-GENERATED
     xdmp:document-insert(
       "#{uri}",
         #{document.to_s}  ,
       xdmp:default-permissions(),
       xdmp:default-collections())
  GENERATED
end

#search(search_text, start, page_length, options) ⇒ Object



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

def search(search_text, start, page_length, options)
  if options.nil?
    option = '()'
  else
    option = options.to_s
  end
  <<-GENERATED
  import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
  search:search('#{search_text}', #{option}, #{start}, #{page_length})
  GENERATED
end