Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Issue #45 - adding support for path indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
paxtonhare committed Oct 1, 2012
1 parent b9d540e commit ccb4bd7
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 6 deletions.
113 changes: 108 additions & 5 deletions deploy/lib/xquery/setup.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,48 @@ declare function setup:configure-database($database-config as element(db:databas
return

try {
let $admin-config :=
admin:get-configuration()

let $database :=
xdmp:database($database-name)

let $restart-hosts :=
try
{
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
let $admin-config := admin:get-configuration()
let $remove-existing-indexes :=
for $index in admin:database-get-range-path-indexes($admin-config, $database)
return
xdmp:set($admin-config, admin:database-delete-range-path-index($admin-config, $database, $index))
return
admin:save-configuration-without-restart($admin-config)')
}
catch($ex)
{
fn:false()
}

(: remove any existing path namespaces :)
let $restart-hosts :=
try
{
xdmp:eval('
let $admin-config := admin:get-configuration()
let $remove-existing-indexes :=
for $index in admin:database-get-path-namespaces($admin-config, $database)
return
xdmp:set($admin-config, admin:database-delete-path-namespace($admin-config, $database, $index))
return
(admin:save-configuration-without-restart($admin-config) or $restart-hosts)')
}
catch($ex)
{
fn:false()
}

let $admin-config :=
admin:get-configuration()

let $admin-config :=
setup:add-word-lexicons($admin-config, $database, $database-config)

Expand Down Expand Up @@ -906,6 +942,9 @@ declare function setup:configure-database($database-config as element(db:databas

let $admin-config := setup:add-range-element-attribute-indexes($admin-config, $database, $database-config)

let $admin-config := setup:add-path-namespaces($admin-config, $database, $database-config)
let $admin-config := setup:add-range-path-indexes($admin-config, $database, $database-config)

(: remove any existing geospatial element attribute pair indexes :)
let $remove-existing-indexes :=
for $index in admin:database-get-geospatial-element-attribute-pair-indexes($admin-config, $database)
Expand Down Expand Up @@ -947,7 +986,7 @@ declare function setup:configure-database($database-config as element(db:databas
let $admin-config := setup:add-range-field-indexes($admin-config, $database, $database-config)

let $restart-hosts :=
admin:save-configuration-without-restart($admin-config)
(admin:save-configuration-without-restart($admin-config) or $restart-hosts)

return
fn:concat("Database ", $database-name, " configured succesfully..", if ($restart-hosts) then " (note: restart required)" else ())
Expand Down Expand Up @@ -1017,6 +1056,70 @@ declare function setup:add-range-element-attribute-indexes-R($admin-config as el
return setup:add-range-element-attribute-indexes-R($admin-config, $database, fn:subsequence($index-configs, 2))
};

declare function setup:add-path-namespaces($admin-config as element(configuration), $database as xs:unsignedLong, $database-config as element(db:database)) as element(configuration)
{
let $index-configs := $database-config/db:path-namespaces/db:path-namespace
return setup:add-path-namespaces-R($admin-config, $database, $index-configs)
};

declare function setup:add-path-namespaces-R($admin-config as element(configuration), $database as xs:unsignedLong, $index-configs as element(db:path-namespace)*) as element(configuration)
{
if (fn:empty($index-configs)) then
$admin-config
else
let $index-config := $index-configs[1]
let $admin-config :=
try {
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $admin-config external;
declare variable $database external;
declare variable $index-config external;
admin:database-add-path-namespace($admin-config, $database, $index-config)',
(
xs:QName("admin-config"), $admin-config,
xs:QName("database"), $database,
xs:QName("index-config"), $index-config
))
} catch ($e) {
xdmp:log(fn:concat("Failed to create path namespace ", xdmp:quote($index-config), "; ", $e/error:code), "error"),
$admin-config
}
return setup:add-path-namespaces-R($admin-config, $database, fn:subsequence($index-configs, 2))
};

declare function setup:add-range-path-indexes($admin-config as element(configuration), $database as xs:unsignedLong, $database-config as element(db:database)) as element(configuration)
{
let $index-configs := $database-config/db:range-path-indexes/db:range-path-index
return setup:add-range-path-indexes-R($admin-config, $database, $index-configs)
};

declare function setup:add-range-path-indexes-R($admin-config as element(configuration), $database as xs:unsignedLong, $index-configs as element(db:range-path-index)*) as element(configuration)
{
if (fn:empty($index-configs)) then
$admin-config
else
let $index-config := $index-configs[1]
let $admin-config :=
try {
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $admin-config external;
declare variable $database external;
declare variable $index-config external;
admin:database-add-range-path-index($admin-config, $database, $index-config)',
(
xs:QName("admin-config"), $admin-config,
xs:QName("database"), $database,
xs:QName("index-config"), $index-config
))
} catch ($e) {
xdmp:log(fn:concat("Failed to create path index ", xdmp:quote($index-config), "; ", $e/error:code), "error"),
$admin-config
}
return setup:add-range-path-indexes-R($admin-config, $database, fn:subsequence($index-configs, 2))
};

declare function setup:add-range-field-indexes($admin-config as element(configuration), $database as xs:unsignedLong, $database-config as element(db:database)) as element(configuration)
{
let $index-configs := $database-config/db:range-field-indexes/db:range-field-index
Expand Down Expand Up @@ -3198,4 +3301,4 @@ declare function display:export-ui()
</div>,
display:left-links()
)
};
};
24 changes: 23 additions & 1 deletion deploy/sample/ml-config.sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@
</range-field-index>
-->
</range-field-indexes>

<path-namespaces>
<!--
<path-namespace>
<prefix>sample</prefix>
<namespace-uri>http://marklogic.com/ns/sample</namespace-uri>
</path-namespace>
-->
</path-namespaces>

<range-path-indexes>
<!--
<range-path-index>
<scalar-type>string</scalar-type>
<collation>http://marklogic.com/collation/codepoint</collation>
<path-expression>/sample:root/sample:child</path-expression>
<range-value-positions>false</range-value-positions>
<invalid-values>reject</invalid-values>
</range-path-index>
-->
</range-path-indexes>

<geospatial-element-attribute-pair-indexes>
<!--
Sample for:
Expand Down Expand Up @@ -308,4 +330,4 @@
</privilege>
-->
</privileges>
</configuration>
</configuration>

0 comments on commit ccb4bd7

Please sign in to comment.