Changes

Jump to navigation Jump to search
960 bytes added ,  21:30, 2 February 2016
Updates in BaseX are generally very fast, because the index structures will be invalidated by updates. As a result, subsequent queries may be executed more slowly than before the update. There are different alternatives to cope with this:
* After the execution of one or more update operations, the <code>[[Commands#OPTIMIZE{{Command|OPTIMIZE]]</code> }} command or the [[Database Module#db:optimize|db:optimize]] function can be called to rebuild the index structures.* The <code>[[Options#UPDINDEX{{Option|UPDINDEX]]</code> }} 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 <code>[[Commands#INFO DB{{Command|INFO DB]]</code> }} or [[Database_Module#db:info|db:info]], will be set to {{Code|false}} until the database will be optimized again.* The <code>[[Options#AUTOOPTIMIZE{{Option|AUTOOPTIMIZE]]</code> }} 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]/idreturn 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,550

edits

Navigation menu