Changes

Jump to navigation Jump to search
12 bytes added ,  21:31, 2 February 2016
no edit summary
With <code>[[Commands#CREATE INDEX|CREATE INDEX]]</code> and [[Database Module#db:optimize|db:optimize]], new selective indexing options will ba applied to an existing database.
 
=Custom Index Structures=
 
With XQuery, it is very easy to create your own, custom index structures. The following query demonstrate how you can create a {{Code|factbook-index}} database, which contains all texts of the original database in lower case:
 
<pre class="brush:xquery">
let $db := 'factbook'
 
let $index := <index>{
for $nodes in db:open($db)//text()
group by $text := lower-case($nodes)
return <text string='{ $text }'>{
for $node in $nodes
return <id>{ db:node-id($node ) }</id>
}</text>
}</index>
 
return db:create($db || '-index', $index, $db || '-index.xml')
</pre>
 
In the following query, a text string is searched, and the text nodes of the original database are retrieved:
 
<pre class="brush:xquery">
let $db := 'factbook'
let $text := 'italian'
for $id in db:open($db || '-index')//*[@string = $text]/id
return db:open-id($db, $id)/..
</pre>
 
With some extra effort, if {{Option|UPDINDEX}} is set for both your original and your index database (see below), your index database will support updates as well (try it, it’s fun!).
=Performance=
* The {{Option|UPDINDEX}} option can be activated before creating or optimizing the database. As a result, the text, attribute and token indexes will be incrementally updated after each database update. Please note that incremental updates are not available for the full-text index and database statistics. This is also explains why the up-to-date flag, which is e.g. displayed via {{Command|INFO DB}} or [[Database_Module#db:info|db:info]], will be set to {{Code|false}} until the database will be optimized again.
* The {{Option|AUTOOPTIMIZE}} option can be enabled before creating or optimizing the database. All outdated index structures and statistics will then be recreated after each database update. This option should only be used for small and medium-sized databases.
 
=Custom Index Structures=
 
With XQuery, it is very easy to create your own, custom index structures. The following query demonstrate how you can create a {{Code|factbook-index}} database, which contains all texts of the original database in lower case:
 
<pre class="brush:xquery">
let $db := 'factbook'
 
let $index := <index>{
for $nodes in db:open($db)//text()
group by $text := lower-case($nodes)
return <text string='{ $text }'>{
for $node in $nodes
return <id>{ db:node-id($node ) }</id>
}</text>
}</index>
 
return db:create($db || '-index', $index, $db || '-index.xml')
</pre>
 
In the following query, a text string is searched, and the text nodes of the original database are retrieved:
 
<pre class="brush:xquery">
let $db := 'factbook'
let $text := 'italian'
for $id in db:open($db || '-index')//*[@string = $text]/id
return db:open-id($db, $id)/..
</pre>
 
With some extra effort, if {{Option|UPDINDEX}} is set for both your original and your index database, your index database will support updates as well (try it, it’s fun!).
=Changelog=
Bureaucrats, editor, reviewer, Administrators
13,551

edits

Navigation menu