==Resource Index==
The resource index contains references to the {{Code|pre}} values of all XML document nodes. It speeds up the access to specific documents in a database, and it will automatically be automatically updated when updates are performed.
The following query will be sped up by the resource index:
</pre>
Text nodes can directly be directly accessed retrieved from the index via the XQuery function [[Database Module#db:text-range|db:text-range]].
Please note that the current index structures do not support queries for numbers and dates.
</pre>
Matching text Attribute nodes can directly be directly requested retrieved from the index with the XQuery functions [[Database Module#db:attribute|db:attribute]] and [[Database Module#db:attribute-range|db:attribute-range]]. The index contents can be accessed with [[Index Module#index:attributes|index:attributes]]. ==Token Index== {{Mark|Introduced with Version 8.4:}} In many XML dialects, such as HTML or DITA, multiple tokens are stored in attribute values. The token index can be used to access these entries. Following queries such as the following ones will (soon) be rewritten for index access: <pre class="brush:xquery"> (: 1st example :)//div[contains-token(@class, 'row')],(: 2nd example :)//p[tokenize(@class) = 'row'],(: 3rd example :)doc('graph.xml')/idref('edge8')</pre> Attributes with tokens can be directly retrieved from the index with the XQuery function [[Database Module#db:token|db:token]]. The index contents can be accessed with [[Index Module#index:tokens|index:tokens]].
==Full-Text Index==
The [[Full-Text]] index speeds up queries using the {{Code|contains text}} expression. Internally, two index structures are provided: the default index sorts all keys alphabetically by their character length. It is particularly fast if provides special support for wildcard and fuzzy searches are performed. The second index is a compressed trie structure, which needs slightly more memory, but is specialized on wildcard searches. Both index structures will be merged in a future version of BaseXsearch operations. If the full-text index exists, the following queries will all be rewritten for index access:
<pre class="brush:xquery">
</pre>
Matching text Text nodes can be directly requested from the index via the XQuery function [[Full-Text Module#ft:search|ft:search]]. The index contents can be accessed with [[Full-Text Module#ft:tokens|ft:tokens]].
==Selective Indexing==
{{Mark|Updated with Version 8.4:}} {{Code|TOKENINCLUDE}} option added Value indexing can be restricted to specific elements and attributes. The nodes to be indexed can be restricted via the [[Options#TEXTINCLUDE|TEXTINCLUDE]], [[Options#ATTRINCLUDE|ATTRINCLUDE]], [[Options#TOKENINCLUDE|TOKENINCLUDE]] and [[Options#FTINCLUDE|FTINCLUDE]] options. The options take a list of name patterns, which are separated by commas. The following name patterns are supported:
* <code>*</code>: all names
=Updates=
By defaultUpdates in BaseX are very fast, because the index structures are discarded after an update operationwill be invalidated by updates.As a result, subsequent queries will may be executed more slowlythan before the update. There aredifferent alternatives to cope with this:
* After the execution of one or more update operations, call the [[Commands#OPTIMIZE|OPTIMIZE]] command or the [[Database Module#db:optimize|db:optimize]] function can be called to rebuild the index structures. Multiple update operations will be performed faster, as the database meta data is only updated and regenerated when requested by the database users.* Enable the The [[Options#UPDINDEX|UPDINDEX]] option can be activated before creating or optimizing the database. As a result, the text and attribute index structures will be incrementally updated after each database update. Please note that incremental updates are not available for the token index, full-text index , and database statistics. This is also the reason explains why the internal up-to-date flag of a database (, which can is e.g. be displayed via [[Commands#INFO DB|INFO DB]] or [[Database_Module#db:info|db:info]]) , will be set to {{Code|false}} until the next optimize call is triggereddatabase will be optimized again.* Enable the The [[Options#AUTOOPTIMIZE|AUTOOPTIMIZE]] option can be enabled before creating or optimizing the database. As a result, all All outdated index structures and statistics will then be recreated after each database update. Enable this This option should only be used for small or and medium-sized databases.
=Changelog=
;Version 8.4
* Added: [[#Token Index|Token Index]]
;Version 8.3
* Added: [[#Selective Indexing|Selective Indexing]]
;Version 8.0