marklogic 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +10 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +17 -0
- data/Guardfile +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/lib/marklogic.rb +21 -0
- data/lib/marklogic/app_server.rb +60 -0
- data/lib/marklogic/application.rb +244 -0
- data/lib/marklogic/collection.rb +265 -0
- data/lib/marklogic/connection.rb +308 -0
- data/lib/marklogic/consts.rb +35 -0
- data/lib/marklogic/cursor.rb +238 -0
- data/lib/marklogic/database.rb +205 -0
- data/lib/marklogic/database_settings.rb +13 -0
- data/lib/marklogic/database_settings/element_word_lexicon.rb +28 -0
- data/lib/marklogic/database_settings/geospatial_element_child_index.rb +41 -0
- data/lib/marklogic/database_settings/geospatial_element_index.rb +38 -0
- data/lib/marklogic/database_settings/geospatial_element_pair_index.rb +42 -0
- data/lib/marklogic/database_settings/geospatial_path_index.rb +37 -0
- data/lib/marklogic/database_settings/index.rb +27 -0
- data/lib/marklogic/database_settings/range_element_index.rb +77 -0
- data/lib/marklogic/database_settings/range_field_index.rb +37 -0
- data/lib/marklogic/database_settings/range_path_index.rb +37 -0
- data/lib/marklogic/exceptions.rb +5 -0
- data/lib/marklogic/forest.rb +47 -0
- data/lib/marklogic/loggable.rb +46 -0
- data/lib/marklogic/object_id.rb +46 -0
- data/lib/marklogic/persistence.rb +29 -0
- data/lib/marklogic/queries.rb +18 -0
- data/lib/marklogic/queries/and_not_query.rb +14 -0
- data/lib/marklogic/queries/and_query.rb +14 -0
- data/lib/marklogic/queries/base_query.rb +40 -0
- data/lib/marklogic/queries/boost_query.rb +14 -0
- data/lib/marklogic/queries/collection_query.rb +14 -0
- data/lib/marklogic/queries/container_query.rb +15 -0
- data/lib/marklogic/queries/directory_query.rb +20 -0
- data/lib/marklogic/queries/document_fragment_query.rb +13 -0
- data/lib/marklogic/queries/document_query.rb +14 -0
- data/lib/marklogic/queries/geospatial_query.rb +44 -0
- data/lib/marklogic/queries/locks_fragment_query.rb +13 -0
- data/lib/marklogic/queries/near_query.rb +31 -0
- data/lib/marklogic/queries/not_in_query.rb +14 -0
- data/lib/marklogic/queries/not_query.rb +13 -0
- data/lib/marklogic/queries/or_query.rb +24 -0
- data/lib/marklogic/queries/properties_fragment_query.rb +13 -0
- data/lib/marklogic/queries/range_query.rb +67 -0
- data/lib/marklogic/queries/value_query.rb +44 -0
- data/lib/marklogic/queries/word_query.rb +38 -0
- data/lib/marklogic/version.rb +3 -0
- data/marklogic.gemspec +23 -0
- data/spec/marklogic/app_server_spec.rb +21 -0
- data/spec/marklogic/application_spec.rb +105 -0
- data/spec/marklogic/collection_spec.rb +154 -0
- data/spec/marklogic/connection_spec.rb +128 -0
- data/spec/marklogic/cursor_spec.rb +219 -0
- data/spec/marklogic/database_settings/element_word_lexicon_spec.rb +21 -0
- data/spec/marklogic/database_settings/geospatial_element_child_index_spec.rb +26 -0
- data/spec/marklogic/database_settings/geospatial_element_index_spec.rb +24 -0
- data/spec/marklogic/database_settings/geospatial_element_pair_index_spec.rb +27 -0
- data/spec/marklogic/database_settings/geospatial_path_index_spec.rb +23 -0
- data/spec/marklogic/database_settings/range_element_index_spec.rb +34 -0
- data/spec/marklogic/database_settings/range_field_index_spec.rb +23 -0
- data/spec/marklogic/database_settings/range_path_index_spec.rb +23 -0
- data/spec/marklogic/database_spec.rb +108 -0
- data/spec/marklogic/forest_spec.rb +30 -0
- data/spec/marklogic/queries/and_not_query_spec.rb +13 -0
- data/spec/marklogic/queries/and_query_spec.rb +31 -0
- data/spec/marklogic/queries/boost_query_spec.rb +13 -0
- data/spec/marklogic/queries/collection_query_spec.rb +16 -0
- data/spec/marklogic/queries/container_query_spec.rb +11 -0
- data/spec/marklogic/queries/directory_query_spec.rb +21 -0
- data/spec/marklogic/queries/document_fragment_query_spec.rb +11 -0
- data/spec/marklogic/queries/document_query_spec.rb +16 -0
- data/spec/marklogic/queries/locks_fragement_query_spec.rb +11 -0
- data/spec/marklogic/queries/near_query_spec.rb +62 -0
- data/spec/marklogic/queries/not_in_query_spec.rb +13 -0
- data/spec/marklogic/queries/not_query_spec.rb +11 -0
- data/spec/marklogic/queries/or_query_spec.rb +32 -0
- data/spec/marklogic/queries/properties_fragment_query_spec.rb +11 -0
- data/spec/marklogic/queries/range_query_spec.rb +71 -0
- data/spec/marklogic/queries/value_query_spec.rb +68 -0
- data/spec/marklogic/queries/word_query_spec.rb +53 -0
- data/spec/spec_helper.rb +68 -0
- metadata +186 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Loggable
|
3
|
+
def logger
|
4
|
+
@logger ||= (rails_logger || default_logger)
|
5
|
+
end
|
6
|
+
|
7
|
+
# Get the rails logger.
|
8
|
+
#
|
9
|
+
# @example Get the rails logger.
|
10
|
+
# Logging.rails_logger
|
11
|
+
#
|
12
|
+
# @return [ Logger ] The Rails logger.
|
13
|
+
#
|
14
|
+
# @since 1.0.0
|
15
|
+
def rails_logger
|
16
|
+
Rails.logger if defined?(Rails) && Rails.respond_to?(:logger)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the default logger.
|
20
|
+
#
|
21
|
+
# @example Get the default logger.
|
22
|
+
# Logging.default_logger
|
23
|
+
#
|
24
|
+
# @return [ Logger ] The default logger.
|
25
|
+
#
|
26
|
+
# @since 1.0.0
|
27
|
+
def default_logger
|
28
|
+
logger = Logger.new(STDOUT)
|
29
|
+
logger.level = Logger::DEBUG
|
30
|
+
logger
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set the logger.
|
34
|
+
#
|
35
|
+
# @example Set the logger.
|
36
|
+
# Logging.logger = logger
|
37
|
+
#
|
38
|
+
# @return [ Logger ] The logger.
|
39
|
+
#
|
40
|
+
# @since 1.0.0
|
41
|
+
def logger=(logger)
|
42
|
+
@logger = logger
|
43
|
+
end
|
44
|
+
end
|
45
|
+
extend Loggable
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module MarkLogic
|
6
|
+
class ObjectId
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@id = SecureRandom.hex
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@id
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def from_string(str)
|
18
|
+
object_id = allocate
|
19
|
+
object_id.instance_variable_set(:@id, str)
|
20
|
+
object_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def legal?(string)
|
24
|
+
string.to_s =~ /^[0-9a-f]{32}$/i ? true : false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
to_s == other.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def as_json(options=nil)
|
33
|
+
to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_json(options = nil)
|
37
|
+
as_json.to_json
|
38
|
+
end
|
39
|
+
|
40
|
+
def hash
|
41
|
+
to_s.hash
|
42
|
+
end
|
43
|
+
|
44
|
+
alias to_str to_s
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Persistence
|
3
|
+
include MarkLogic::Loggable
|
4
|
+
|
5
|
+
def connection=(conn)
|
6
|
+
@connection = conn if conn
|
7
|
+
end
|
8
|
+
|
9
|
+
def connection
|
10
|
+
@connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def manage_connection=(manage_conn)
|
14
|
+
@manage_connection = manage_conn if manage_conn
|
15
|
+
end
|
16
|
+
|
17
|
+
def manage_connection
|
18
|
+
@manage_connection ||= MarkLogic::Connection.manage_connection
|
19
|
+
end
|
20
|
+
|
21
|
+
def admin_connection=(admin_conn)
|
22
|
+
@admin_connection = admin_conn if admin_conn
|
23
|
+
end
|
24
|
+
|
25
|
+
def admin_connection
|
26
|
+
@admin_connection ||= MarkLogic::Connection.admin_connection
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'marklogic/queries/base_query'
|
2
|
+
require 'marklogic/queries/and_not_query'
|
3
|
+
require 'marklogic/queries/and_query'
|
4
|
+
require 'marklogic/queries/boost_query'
|
5
|
+
require 'marklogic/queries/collection_query'
|
6
|
+
require 'marklogic/queries/container_query'
|
7
|
+
require 'marklogic/queries/directory_query'
|
8
|
+
require 'marklogic/queries/document_fragment_query'
|
9
|
+
require 'marklogic/queries/document_query'
|
10
|
+
require 'marklogic/queries/locks_fragment_query'
|
11
|
+
require 'marklogic/queries/near_query'
|
12
|
+
require 'marklogic/queries/not_in_query'
|
13
|
+
require 'marklogic/queries/not_query'
|
14
|
+
require 'marklogic/queries/or_query'
|
15
|
+
require 'marklogic/queries/properties_fragment_query'
|
16
|
+
require 'marklogic/queries/range_query'
|
17
|
+
require 'marklogic/queries/value_query'
|
18
|
+
require 'marklogic/queries/word_query'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class AndNotQuery < BaseQuery
|
4
|
+
def initialize(positive_query, negative_query)
|
5
|
+
@positive_query = positive_query
|
6
|
+
@negative_query = negative_query
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xqy
|
10
|
+
%Q{cts:and-not-query(#{@positive_query.to_xqy},#{@negative_query.to_xqy})}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class AndQuery < BaseQuery
|
4
|
+
def initialize(*args)
|
5
|
+
@queries = args.flat_map{ |i| i }
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_xqy
|
9
|
+
sub_queries = @queries.map { |q| q.to_xqy }.join(',')
|
10
|
+
%Q{cts:and-query((#{sub_queries}))}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class BaseQuery
|
4
|
+
|
5
|
+
# Helper function to add a sub query into a parent query
|
6
|
+
#
|
7
|
+
# @param [ BaseQuery ] parent The parent query
|
8
|
+
# @param [ BaseQuery ] query The sub-query to add
|
9
|
+
#
|
10
|
+
# @since 1.0.0
|
11
|
+
def add_sub_query(parent, query)
|
12
|
+
query_json = query.to_json
|
13
|
+
query_key = query_json.keys[0]
|
14
|
+
parent[query_key] = query_json[query_key]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the value of the query appropriately formatted
|
18
|
+
#
|
19
|
+
# @param [ Any ] original_value The value to format
|
20
|
+
# @param [ String ] type The data type
|
21
|
+
#
|
22
|
+
# @since 1.0.0
|
23
|
+
def query_value(original_value, type = nil)
|
24
|
+
if original_value.kind_of?(Array)
|
25
|
+
value = original_value.map { |v| query_value(v) }.join(',')
|
26
|
+
elsif original_value.kind_of?(TrueClass)
|
27
|
+
value = 'fn:true()'
|
28
|
+
elsif original_value.kind_of?(FalseClass)
|
29
|
+
value = 'fn:false()'
|
30
|
+
elsif original_value.kind_of?(ObjectId)
|
31
|
+
value = %Q{"#{original_value.to_s}"}
|
32
|
+
elsif original_value.kind_of?(String) || type == "string"
|
33
|
+
value = %Q{"#{original_value}"}
|
34
|
+
else
|
35
|
+
value = original_value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class BoostQuery< BaseQuery
|
4
|
+
def initialize(matching_query, boosting_query)
|
5
|
+
@matching_query = matching_query
|
6
|
+
@boosting_query = boosting_query
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xqy
|
10
|
+
%Q{cts:boost-query(#{@matching_query.to_xqy},#{@boosting_query.to_xqy})}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class CollectionQuery < BaseQuery
|
4
|
+
def initialize(collection_uris)
|
5
|
+
@collection_uris = collection_uris
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_xqy
|
9
|
+
uris = query_value(@collection_uris)
|
10
|
+
%Q{cts:collection-query((#{uris}))}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class ContainerQuery< BaseQuery
|
4
|
+
def initialize(name, query, options = {})
|
5
|
+
@name = name
|
6
|
+
@query = query
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_xqy
|
11
|
+
%Q{cts:json-property-scope-query("#{@name}",#{@query.to_xqy})}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class DirectoryQuery< BaseQuery
|
4
|
+
def initialize(uris, depth = nil)
|
5
|
+
@directory_uris = uris
|
6
|
+
@depth = depth
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xqy
|
10
|
+
uris = query_value(@directory_uris)
|
11
|
+
|
12
|
+
if @depth.nil?
|
13
|
+
%Q{cts:directory-query((#{uris}))}
|
14
|
+
else
|
15
|
+
%Q{cts:directory-query((#{uris}),"#{@depth}")}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class GeospatialQuery < BaseQuery
|
4
|
+
def initialize(name, regions, options = {})
|
5
|
+
@name = name
|
6
|
+
@regions = regions
|
7
|
+
@options = options || {}
|
8
|
+
@weight = @options.delete(:weight) || 1.0
|
9
|
+
end
|
10
|
+
|
11
|
+
def options=(opts)
|
12
|
+
@options = opts
|
13
|
+
end
|
14
|
+
|
15
|
+
def options
|
16
|
+
opts = []
|
17
|
+
@options.each do |k, v|
|
18
|
+
dashed_key = k.to_s.gsub(/_/, '-')
|
19
|
+
case k.to_s
|
20
|
+
when "coordinate_system", "units", "type", "score_function", "slope_factor"
|
21
|
+
opts << %Q{"#{dashed_key}=#{v}"}
|
22
|
+
when /(boundaries)_included/
|
23
|
+
opts << (v == true ? %Q{"#{$1}-included"} : %Q{"#{$1}-excluded"})
|
24
|
+
when /([a-z\-]+_excluded)/
|
25
|
+
opts << %Q{"#{dashed_key}"}
|
26
|
+
when "cached"
|
27
|
+
opts << (v == true ? %Q{"cached"} : %Q{"uncached"})
|
28
|
+
when "zero", "synonym"
|
29
|
+
opts << %Q{"#{dashed_key}"}
|
30
|
+
# else
|
31
|
+
# opts << %Q{"#{v}"}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
opts
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_xqy
|
39
|
+
regions = query_value(@regions)
|
40
|
+
%Q{cts:json-property-geospatial-query("#{@name}",(#{regions}),(#{options.join(',')}),#{@weight})}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class NearQuery< BaseQuery
|
4
|
+
def initialize(queries, distance = 10, distance_weight = 1.0, options = {})
|
5
|
+
@queries = queries
|
6
|
+
@distance = distance
|
7
|
+
@distance_weight = distance_weight
|
8
|
+
@ordered = options.delete(:ordered)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json
|
12
|
+
json = {
|
13
|
+
"near-query" => {
|
14
|
+
"queries" => @queries.map { |q| q.to_json }
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
json["near-query"]["queries"].push({ "distance" => @distance }) if @distance
|
19
|
+
json["near-query"]["queries"].push({ "distance-weight" => @distance_weight }) if @distance_weight
|
20
|
+
json["near-query"]["queries"].push({ "ordered" => @ordered })
|
21
|
+
json
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_xqy
|
25
|
+
queries = @queries.map { |q| q.to_xqy }.join(',')
|
26
|
+
ordered = (@ordered == true ? %Q{"ordered"} : %Q{"unordered"}) if !@ordered.nil?
|
27
|
+
%Q{cts:near-query((#{queries}),#{@distance},(#{ordered}),#{@distance_weight})}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MarkLogic
|
2
|
+
module Queries
|
3
|
+
class NotInQuery< BaseQuery
|
4
|
+
def initialize(positive_query, negative_query)
|
5
|
+
@positive_query = positive_query
|
6
|
+
@negative_query = negative_query
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xqy
|
10
|
+
%Q{cts:not-in-query(#{@positive_query.to_xqy},#{@negative_query.to_xqy})}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|