From ccb4bd7e8bfb0c774a48ffdec244410fbf7dfc00 Mon Sep 17 00:00:00 2001 From: Paxton Hare Date: Mon, 1 Oct 2012 13:57:21 -0400 Subject: [PATCH] Issue #45 - adding support for path indexes --- deploy/lib/xquery/setup.xqy | 113 +++++++++++++++++++++++++++-- deploy/sample/ml-config.sample.xml | 24 +++++- 2 files changed, 131 insertions(+), 6 deletions(-) diff --git a/deploy/lib/xquery/setup.xqy b/deploy/lib/xquery/setup.xqy index e40c72f1..660a6ef4 100644 --- a/deploy/lib/xquery/setup.xqy +++ b/deploy/lib/xquery/setup.xqy @@ -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) @@ -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) @@ -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 ()) @@ -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 @@ -3198,4 +3301,4 @@ declare function display:export-ui() , display:left-links() ) -}; +}; \ No newline at end of file diff --git a/deploy/sample/ml-config.sample.xml b/deploy/sample/ml-config.sample.xml index 55bebe10..a370b547 100644 --- a/deploy/sample/ml-config.sample.xml +++ b/deploy/sample/ml-config.sample.xml @@ -128,6 +128,28 @@ --> + + + + + + + + + - + \ No newline at end of file