marklogic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +10 -0
  3. data/.gitignore +15 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +17 -0
  8. data/Guardfile +45 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +31 -0
  11. data/Rakefile +6 -0
  12. data/lib/marklogic.rb +21 -0
  13. data/lib/marklogic/app_server.rb +60 -0
  14. data/lib/marklogic/application.rb +244 -0
  15. data/lib/marklogic/collection.rb +265 -0
  16. data/lib/marklogic/connection.rb +308 -0
  17. data/lib/marklogic/consts.rb +35 -0
  18. data/lib/marklogic/cursor.rb +238 -0
  19. data/lib/marklogic/database.rb +205 -0
  20. data/lib/marklogic/database_settings.rb +13 -0
  21. data/lib/marklogic/database_settings/element_word_lexicon.rb +28 -0
  22. data/lib/marklogic/database_settings/geospatial_element_child_index.rb +41 -0
  23. data/lib/marklogic/database_settings/geospatial_element_index.rb +38 -0
  24. data/lib/marklogic/database_settings/geospatial_element_pair_index.rb +42 -0
  25. data/lib/marklogic/database_settings/geospatial_path_index.rb +37 -0
  26. data/lib/marklogic/database_settings/index.rb +27 -0
  27. data/lib/marklogic/database_settings/range_element_index.rb +77 -0
  28. data/lib/marklogic/database_settings/range_field_index.rb +37 -0
  29. data/lib/marklogic/database_settings/range_path_index.rb +37 -0
  30. data/lib/marklogic/exceptions.rb +5 -0
  31. data/lib/marklogic/forest.rb +47 -0
  32. data/lib/marklogic/loggable.rb +46 -0
  33. data/lib/marklogic/object_id.rb +46 -0
  34. data/lib/marklogic/persistence.rb +29 -0
  35. data/lib/marklogic/queries.rb +18 -0
  36. data/lib/marklogic/queries/and_not_query.rb +14 -0
  37. data/lib/marklogic/queries/and_query.rb +14 -0
  38. data/lib/marklogic/queries/base_query.rb +40 -0
  39. data/lib/marklogic/queries/boost_query.rb +14 -0
  40. data/lib/marklogic/queries/collection_query.rb +14 -0
  41. data/lib/marklogic/queries/container_query.rb +15 -0
  42. data/lib/marklogic/queries/directory_query.rb +20 -0
  43. data/lib/marklogic/queries/document_fragment_query.rb +13 -0
  44. data/lib/marklogic/queries/document_query.rb +14 -0
  45. data/lib/marklogic/queries/geospatial_query.rb +44 -0
  46. data/lib/marklogic/queries/locks_fragment_query.rb +13 -0
  47. data/lib/marklogic/queries/near_query.rb +31 -0
  48. data/lib/marklogic/queries/not_in_query.rb +14 -0
  49. data/lib/marklogic/queries/not_query.rb +13 -0
  50. data/lib/marklogic/queries/or_query.rb +24 -0
  51. data/lib/marklogic/queries/properties_fragment_query.rb +13 -0
  52. data/lib/marklogic/queries/range_query.rb +67 -0
  53. data/lib/marklogic/queries/value_query.rb +44 -0
  54. data/lib/marklogic/queries/word_query.rb +38 -0
  55. data/lib/marklogic/version.rb +3 -0
  56. data/marklogic.gemspec +23 -0
  57. data/spec/marklogic/app_server_spec.rb +21 -0
  58. data/spec/marklogic/application_spec.rb +105 -0
  59. data/spec/marklogic/collection_spec.rb +154 -0
  60. data/spec/marklogic/connection_spec.rb +128 -0
  61. data/spec/marklogic/cursor_spec.rb +219 -0
  62. data/spec/marklogic/database_settings/element_word_lexicon_spec.rb +21 -0
  63. data/spec/marklogic/database_settings/geospatial_element_child_index_spec.rb +26 -0
  64. data/spec/marklogic/database_settings/geospatial_element_index_spec.rb +24 -0
  65. data/spec/marklogic/database_settings/geospatial_element_pair_index_spec.rb +27 -0
  66. data/spec/marklogic/database_settings/geospatial_path_index_spec.rb +23 -0
  67. data/spec/marklogic/database_settings/range_element_index_spec.rb +34 -0
  68. data/spec/marklogic/database_settings/range_field_index_spec.rb +23 -0
  69. data/spec/marklogic/database_settings/range_path_index_spec.rb +23 -0
  70. data/spec/marklogic/database_spec.rb +108 -0
  71. data/spec/marklogic/forest_spec.rb +30 -0
  72. data/spec/marklogic/queries/and_not_query_spec.rb +13 -0
  73. data/spec/marklogic/queries/and_query_spec.rb +31 -0
  74. data/spec/marklogic/queries/boost_query_spec.rb +13 -0
  75. data/spec/marklogic/queries/collection_query_spec.rb +16 -0
  76. data/spec/marklogic/queries/container_query_spec.rb +11 -0
  77. data/spec/marklogic/queries/directory_query_spec.rb +21 -0
  78. data/spec/marklogic/queries/document_fragment_query_spec.rb +11 -0
  79. data/spec/marklogic/queries/document_query_spec.rb +16 -0
  80. data/spec/marklogic/queries/locks_fragement_query_spec.rb +11 -0
  81. data/spec/marklogic/queries/near_query_spec.rb +62 -0
  82. data/spec/marklogic/queries/not_in_query_spec.rb +13 -0
  83. data/spec/marklogic/queries/not_query_spec.rb +11 -0
  84. data/spec/marklogic/queries/or_query_spec.rb +32 -0
  85. data/spec/marklogic/queries/properties_fragment_query_spec.rb +11 -0
  86. data/spec/marklogic/queries/range_query_spec.rb +71 -0
  87. data/spec/marklogic/queries/value_query_spec.rb +68 -0
  88. data/spec/marklogic/queries/word_query_spec.rb +53 -0
  89. data/spec/spec_helper.rb +68 -0
  90. metadata +186 -0
@@ -0,0 +1,13 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ autoload :Index, 'marklogic/database_settings/index'
4
+ autoload :ElementWordLexicon, 'marklogic/database_settings/element_word_lexicon'
5
+ autoload :GeospatialElementChildIndex, 'marklogic/database_settings/geospatial_element_child_index'
6
+ autoload :GeospatialElementIndex, 'marklogic/database_settings/geospatial_element_index'
7
+ autoload :GeospatialElementPairIndex, 'marklogic/database_settings/geospatial_element_pair_index'
8
+ autoload :GeospatialPathIndex, 'marklogic/database_settings/geospatial_path_index'
9
+ autoload :RangeElementIndex, 'marklogic/database_settings/range_element_index'
10
+ autoload :RangeFieldIndex, 'marklogic/database_settings/range_field_index'
11
+ autoload :RangePathIndex, 'marklogic/database_settings/range_path_index'
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class ElementWordLexicon
4
+ def initialize(localname, collation = DEFAULT_COLLATION)
5
+ @localname = localname
6
+ @collation = collation
7
+ end
8
+
9
+ def append_to_db(database)
10
+ database.add_index("element-word-lexicon", self)
11
+ end
12
+
13
+ def key
14
+ %Q{#{self.class.to_s}-#{@localname}}
15
+ end
16
+
17
+ def to_json(options = nil)
18
+ {
19
+ "element-word-lexicon" => {
20
+ "namespace-uri" => "",
21
+ "localname" => @localname,
22
+ "collation" => @collation
23
+ }
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class GeospatialElementChildIndex
4
+
5
+ attr_accessor :parent_localname, :localname, :facet
6
+
7
+ def initialize(parent_localname, child_localname, options = {})
8
+ @parent_localname = parent_localname
9
+ @localname = child_localname
10
+ @coordinate_system = options[:coordinate_system] || MarkLogic::GEO_WGS84
11
+ @point_format = options[:point_format] || MarkLogic::POINT
12
+ @range_value_positions = options[:range_value_positions] || false
13
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
14
+ @facet = options[:facet] || false
15
+ end
16
+
17
+ def key
18
+ %Q{#{self.class.to_s}-#{@localname}}
19
+ end
20
+
21
+ def append_to_db(database)
22
+ database.add_index("geospatial-element-child-index", self)
23
+ end
24
+
25
+ def to_json(options = nil)
26
+ {
27
+ "geospatial-element-child-index" => {
28
+ "parent-namespace-uri" => "",
29
+ "parent-localname" => @parent_localname,
30
+ "namespace-uri" => "",
31
+ "localname" => @localname,
32
+ "coordinate-system" => @coordinate_system,
33
+ "point-format" => @point_format,
34
+ "range-value-positions" => @range_value_positions,
35
+ "invalid-values" => @invalid_values
36
+ }
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,38 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class GeospatialElementIndex
4
+
5
+ attr_accessor :localname, :facet
6
+
7
+ def initialize(element_name, options = {})
8
+ @localname = element_name
9
+ @coordinate_system = options[:coordinate_system] || MarkLogic::GEO_WGS84
10
+ @point_format = options[:point_format] || MarkLogic::POINT
11
+ @range_value_positions = options[:range_value_positions] || false
12
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
13
+ @facet = options[:facet] || false
14
+ end
15
+
16
+ def key
17
+ %Q{#{self.class.to_s}-#{@localname}}
18
+ end
19
+
20
+ def append_to_db(database)
21
+ database.add_index("geospatial-element-index", self)
22
+ end
23
+
24
+ def to_json(options = nil)
25
+ {
26
+ "geospatial-element-index" => {
27
+ "namespace-uri" => "",
28
+ "localname" => @localname,
29
+ "coordinate-system" => @coordinate_system,
30
+ "point-format" => @point_format,
31
+ "range-value-positions" => @range_value_positions,
32
+ "invalid-values" => @invalid_values
33
+ }
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class GeospatialElementPairIndex
4
+
5
+ attr_accessor :parent_localname, :latitude_localname, :longitude_localname, :facet
6
+
7
+ def initialize(element_name, latitude_localname, longitude_localname, options = {})
8
+ @parent_localname = element_name
9
+ @latitude_localname = latitude_localname
10
+ @longitude_localname = longitude_localname
11
+ @coordinate_system = options[:coordinate_system] || MarkLogic::GEO_WGS84
12
+ @range_value_positions = options[:range_value_positions] || false
13
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
14
+ @facet = options[:facet] || false
15
+ end
16
+
17
+ def key
18
+ %Q{#{self.class.to_s}-#{@localname}}
19
+ end
20
+
21
+ def append_to_db(database)
22
+ database.add_index("geospatial-element-pair-index", self)
23
+ end
24
+
25
+ def to_json(options = nil)
26
+ {
27
+ "geospatial-element-pair-index" => {
28
+ "parent-namespace-uri" => "",
29
+ "parent-localname" => @parent_localname,
30
+ "latitude-namespace-uri" => "",
31
+ "latitude-localname" => @latitude_localname,
32
+ "longitude-namespace-uri" => "",
33
+ "longitude-localname" => @longitude_localname,
34
+ "coordinate-system" => @coordinate_system,
35
+ "range-value-positions" => @range_value_positions,
36
+ "invalid-values" => @invalid_values
37
+ }
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class GeospatialPathIndex
4
+
5
+ attr_accessor :path_expression, :facet
6
+
7
+ def initialize(path_expression, options = {})
8
+ @path_expression = path_expression
9
+ @coordinate_system = options[:coordinate_system] || MarkLogic::GEO_WGS84
10
+ @point_format = options[:point_format] || MarkLogic::POINT
11
+ @range_value_positions = options[:range_value_positions] || false
12
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
13
+ @facet = options[:facet] || false
14
+ end
15
+
16
+ def key
17
+ %Q{#{self.class.to_s}-#{@localname}}
18
+ end
19
+
20
+ def append_to_db(database)
21
+ database.add_index("geospatial-path-index", self)
22
+ end
23
+
24
+ def to_json(options = nil)
25
+ {
26
+ "geospatial-path-index" => {
27
+ "path-expression" => @path_expression,
28
+ "coordinate-system" => @coordinate_system,
29
+ "point-format" => @point_format,
30
+ "range-value-positions" => @range_value_positions,
31
+ "invalid-values" => @invalid_values
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class Index
4
+
5
+ def self.from_json(type, json)
6
+ case type
7
+ when 'range-element-index'
8
+ RangeElementIndex.from_json(json)
9
+ when 'element-word-lexicon'
10
+ ElementWordLexicon.from_json(json)
11
+ when 'range-path-index'
12
+ RangepathIndex.from_json(json)
13
+ when 'range-field-index'
14
+ RangeFieldIndex.from_json(json)
15
+ when 'geospatial-element-index'
16
+ GeospatialElementIndex.from_json(json)
17
+ when 'geospatial-element-child-index'
18
+ GeospatialElementChildIndex.from_json(json)
19
+ when 'geospatial-element-pair-index'
20
+ GeospatialElementPairIndex.from_json(json)
21
+ when 'geospatial-path-index'
22
+ GeospatialPathIndex.from_json(json)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,77 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class RangeElementIndex
4
+
5
+ attr_accessor :scalar_type, :localname, :namespace_uri, :collation, :range_value_positions, :invalid_values, :facet
6
+
7
+ def initialize(name, options = {})
8
+ @scalar_type = options[:type] || 'string'
9
+ @localname = name.to_s
10
+ @namespace_uri = options[:namespace] || ""
11
+ @collation = options[:collation] || (@scalar_type == 'string' ? MarkLogic::DEFAULT_COLLATION : "")
12
+ @range_value_positions = options[:range_value_positions] || false
13
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
14
+ @facet = options[:facet] || false
15
+ end
16
+
17
+ def key
18
+ %Q{#{self.class.to_s}-#{@localname}}
19
+ end
20
+
21
+ def <=>(other)
22
+ localname <=> other.localname
23
+ end
24
+
25
+ def ==(other)
26
+ self.class == other.class and
27
+ scalar_type == other.scalar_type and
28
+ localname = other.localname and
29
+ namespace_uri = other.namespace_uri and
30
+ collation == other.collation and
31
+ range_value_positions == other.range_value_positions and
32
+ invalid_values == other.invalid_values
33
+ end
34
+
35
+ def type
36
+ "range-element-index"
37
+ end
38
+
39
+ def append_to_db(database)
40
+ database.add_index("range-element-index", self)
41
+ end
42
+
43
+ def to_json(options = nil)
44
+ {
45
+ "scalar-type" => @scalar_type,
46
+ "namespace-uri" => @namespace_uri,
47
+ "localname" => @localname,
48
+ "collation" => @collation,
49
+ "range-value-positions" => @range_value_positions,
50
+ "invalid-values" => @invalid_values
51
+ }
52
+ end
53
+
54
+ def to_ref
55
+ options = [%Q{"type=#{@scalar_type}"}]
56
+ options << %Q{"collation=#{@collation}"} if @scalar_type == "string"
57
+ %Q{cts:json-property-reference("#{@localname}", (#{options.join(',')}))}
58
+ end
59
+
60
+ def self.from_json(json)
61
+ index = allocate
62
+ index.from_json(json)
63
+ index
64
+ end
65
+
66
+ def from_json(json)
67
+ @scalar_type = json['scalar-type']
68
+ @namespace_uri = json['namespace-uri']
69
+ @localname = json['localname']
70
+ @collation = json['collation']
71
+ @range_value_positions = json['range-value-positions']
72
+ @invalid_values = json['invalid-values']
73
+ @facet = false
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,37 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class RangeFieldIndex
4
+
5
+ attr_accessor :scalar_type, :field_name, :collation, :facet
6
+
7
+ def initialize(field_name, options = {})
8
+ @scalar_type = options[:type] || MarkLogic::STRING
9
+ @field_name = field_name
10
+ @collation = options[:collation] || DEFAULT_COLLATION
11
+ @range_value_positions = options[:range_value_positions] || false
12
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
13
+ @facet = options[:facet] || false
14
+ end
15
+
16
+ def key
17
+ %Q{#{self.class.to_s}-#{@localname}}
18
+ end
19
+
20
+ def append_to_db(database)
21
+ database.add_index("range-field-index", self)
22
+ end
23
+
24
+ def to_json(options = nil)
25
+ {
26
+ "range-field-index" => {
27
+ "scalar-type" => @scalar_type,
28
+ "field-name" => @field_name,
29
+ "collation" => @collation,
30
+ "range-value-positions" => @range_value_positions,
31
+ "invalid-values" => @invalid_values
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module MarkLogic
2
+ module DatabaseSettings
3
+ class RangePathIndex
4
+
5
+ attr_accessor :scalar_type, :collation, :path_expression, :facet
6
+
7
+ def initialize(path_expression, options = {})
8
+ @scalar_type = options[:type] || MarkLogic::STRING
9
+ @collation = options[:collation] || DEFAULT_COLLATION
10
+ @path_expression = path_expression
11
+ @range_value_positions = options[:range_value_positions] || false
12
+ @invalid_values = options[:invalid_values] || MarkLogic::REJECT
13
+ @facet = options[:facet] || false
14
+ end
15
+
16
+ def key
17
+ %Q{#{self.class.to_s}-#{@localname}}
18
+ end
19
+
20
+ def append_to_db(database)
21
+ database.add_index("range-path-index", self)
22
+ end
23
+
24
+ def to_json(options = nil)
25
+ {
26
+ "range-path-index" => {
27
+ "scalar-type" => @scalar_type,
28
+ "collation" => @collation,
29
+ "path-expression" => @path_expression,
30
+ "range-value-positions" => @range_value_positions,
31
+ "invalid-values" => @invalid_values
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ module MarkLogic
3
+ class MissingIndexError < StandardError; end
4
+ class SearchError < StandardError; end
5
+ end
@@ -0,0 +1,47 @@
1
+ module MarkLogic
2
+ class Forest
3
+ include MarkLogic::Persistence
4
+
5
+ attr_accessor :forest_name
6
+ def initialize(forest_name, host_name = nil, conn = nil)
7
+ self.connection = conn
8
+ @forest_name = forest_name
9
+ @host_name = host_name || self.manage_connection.host
10
+ @options = {
11
+ "forest-name" => @forest_name,
12
+ "host" => @host_name
13
+ }
14
+ end
15
+
16
+ def []=(key, value)
17
+ @options[key] = value
18
+ end
19
+
20
+ def [](key)
21
+ @options[key]
22
+ end
23
+
24
+ def has_key?(key)
25
+ @options.has_key?(key)
26
+ end
27
+
28
+ def database=(db)
29
+ @database = db
30
+ @options['database'] = db.database_name
31
+ end
32
+
33
+ def create
34
+ r = manage_connection.post_json(
35
+ %Q{/manage/v2/forests?format=json},
36
+ @options)
37
+ end
38
+
39
+ def exists?
40
+ manage_connection.head(%Q{/manage/v2/forests/#{forest_name}}).code.to_i == 200
41
+ end
42
+
43
+ def drop
44
+ r = manage_connection.delete(%Q{/manage/v2/forests/#{forest_name}?level=full&format=json})
45
+ end
46
+ end
47
+ end