org.exist.storage
Class NativeValueIndex

java.lang.Object
  extended by org.exist.storage.NativeValueIndex
All Implemented Interfaces:
ContentLoadingObserver

public class NativeValueIndex
extends Object
implements ContentLoadingObserver

Maintains an index on typed node values. TODO: Check correct types during validation. In the BTree single BFile, the keys are : (collectionId, indexType, indexData) and the values are : gid1, gid2-gid1, ...

Algorithm:

When a node is stored, an entry is added or updated in the pending map, with given String content and basic type as key. This way, the index entries are easily put in the persistent BFile storage by flush() .

Author:
wolf

Field Summary
static double DEFAULT_VALUE_CACHE_GROWTH
           
static double DEFAULT_VALUE_KEY_THRESHOLD
           
static double DEFAULT_VALUE_VALUE_THRESHOLD
           
static String FILE_KEY_IN_CONFIG
           
static String FILE_NAME
           
static byte IDX_GENERIC
           
static byte IDX_QNAME
           
static String INDEX_CASE_SENSITIVE_ATTRIBUTE
           
static int LENGTH_NODE_IDS
           
static int LENGTH_VALUE_TYPE
           
static int OFFSET_COLLECTION_ID
           
static int OFFSET_DATA
           
static int OFFSET_VALUE_TYPE
           
static String PROPERTY_INDEX_CASE_SENSITIVE
           
static int WITH_PATH
           
static int WITHOUT_PATH
           
 
Constructor Summary
NativeValueIndex(DBBroker broker, byte id, String dataDir, Configuration config)
           
 
Method Summary
 boolean close()
           
 void closeAndRemove()
           
 void dropIndex(Collection collection)
          Drop all index entries for the given collection.
 void dropIndex(DocumentImpl document)
          Drop all index entries for the given document.
 NodeSet find(int relation, DocumentSet docs, NodeSet contextSet, int axis, QName qname, Indexable value)
           
 NodeSet findAll(int relation, DocumentSet docs, NodeSet contextSet, int axis, Indexable value)
           
 void flush()
           
 String getConfigKeyForFile()
           
 String getFileName()
           
 NativeValueIndex getInstance()
           
 StoredNode getReindexRoot(StoredNode node, NodePath nodePath)
           
 NodeSet match(DocumentSet docs, NodeSet contextSet, int axis, String expr, QName qname, int type)
           
 NodeSet match(DocumentSet docs, NodeSet contextSet, int axis, String expr, QName qname, int type, int flags, boolean caseSensitiveQuery)
           
 NodeSet matchAll(DocumentSet docs, NodeSet contextSet, int axis, String expr, int type, int flags, boolean caseSensitiveQuery)
           
 NodeSet matchAll(DocumentSet docs, NodeSet contextSet, int axis, String expr, List qnames, int type, int flags, boolean caseSensitiveQuery, NodeSet result)
          Regular expression search
 void printStatistics()
           
 void reindex(StoredNode node)
           
 void remove()
          remove all pending modifications, for the current document.
 void removeNode(StoredNode node, NodePath currentPath, String content)
          The given node is being removed from the database.
 ValueOccurrences[] scanIndexKeys(DocumentSet docs, NodeSet contextSet, Indexable start)
           
 ValueOccurrences[] scanIndexKeys(DocumentSet docs, NodeSet contextSet, QName[] qnames, Indexable start)
          Scan all index keys indexed by the given QName.
 void setDocument(DocumentImpl document)
          set the current document; generally called before calling an operation
 void storeAttribute(AttrImpl node, NodePath currentPath, int indexingHint, RangeIndexSpec spec, boolean remove)
          Store the given attribute's value in the value index.
 void storeElement(ElementImpl node, String content, int xpathType, byte indexType, boolean remove)
          Store the given element's value in the value index.
 void storeText(TextImpl node, NodePath currentPath, int indexingHint)
          store and index given text node
 void sync()
          triggers a cache sync, i.e.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_NAME

public static final String FILE_NAME
See Also:
Constant Field Values

FILE_KEY_IN_CONFIG

public static final String FILE_KEY_IN_CONFIG
See Also:
Constant Field Values

WITH_PATH

public static final int WITH_PATH
See Also:
Constant Field Values

WITHOUT_PATH

public static final int WITHOUT_PATH
See Also:
Constant Field Values

DEFAULT_VALUE_CACHE_GROWTH

public static final double DEFAULT_VALUE_CACHE_GROWTH
See Also:
Constant Field Values

DEFAULT_VALUE_KEY_THRESHOLD

public static final double DEFAULT_VALUE_KEY_THRESHOLD
See Also:
Constant Field Values

DEFAULT_VALUE_VALUE_THRESHOLD

public static final double DEFAULT_VALUE_VALUE_THRESHOLD
See Also:
Constant Field Values

LENGTH_VALUE_TYPE

public static final int LENGTH_VALUE_TYPE
See Also:
Constant Field Values

LENGTH_NODE_IDS

public static final int LENGTH_NODE_IDS
See Also:
Constant Field Values

OFFSET_COLLECTION_ID

public static final int OFFSET_COLLECTION_ID
See Also:
Constant Field Values

OFFSET_VALUE_TYPE

public static final int OFFSET_VALUE_TYPE

OFFSET_DATA

public static final int OFFSET_DATA

IDX_GENERIC

public static final byte IDX_GENERIC
See Also:
Constant Field Values

IDX_QNAME

public static final byte IDX_QNAME
See Also:
Constant Field Values

INDEX_CASE_SENSITIVE_ATTRIBUTE

public static final String INDEX_CASE_SENSITIVE_ATTRIBUTE
See Also:
Constant Field Values

PROPERTY_INDEX_CASE_SENSITIVE

public static final String PROPERTY_INDEX_CASE_SENSITIVE
See Also:
Constant Field Values
Constructor Detail

NativeValueIndex

public NativeValueIndex(DBBroker broker,
                        byte id,
                        String dataDir,
                        Configuration config)
                 throws DBException
Throws:
DBException
Method Detail

getFileName

public String getFileName()

getConfigKeyForFile

public String getConfigKeyForFile()

getInstance

public NativeValueIndex getInstance()

setDocument

public void setDocument(DocumentImpl document)
Description copied from interface: ContentLoadingObserver
set the current document; generally called before calling an operation

Specified by:
setDocument in interface ContentLoadingObserver

storeElement

public void storeElement(ElementImpl node,
                         String content,
                         int xpathType,
                         byte indexType,
                         boolean remove)
Store the given element's value in the value index.

Parameters:
xpathType - The value type
node - The element
content - The string representation of the value

storeAttribute

public void storeAttribute(AttrImpl node,
                           NodePath currentPath,
                           int indexingHint,
                           RangeIndexSpec spec,
                           boolean remove)
Store the given attribute's value in the value index.

Specified by:
storeAttribute in interface ContentLoadingObserver
Parameters:
spec - The index specification
node - The attribute

getReindexRoot

public StoredNode getReindexRoot(StoredNode node,
                                 NodePath nodePath)

reindex

public void reindex(StoredNode node)

storeText

public void storeText(TextImpl node,
                      NodePath currentPath,
                      int indexingHint)
Description copied from interface: ContentLoadingObserver
store and index given text node

Specified by:
storeText in interface ContentLoadingObserver

removeNode

public void removeNode(StoredNode node,
                       NodePath currentPath,
                       String content)
Description copied from interface: ContentLoadingObserver
The given node is being removed from the database.

Specified by:
removeNode in interface ContentLoadingObserver

sync

public void sync()
Description copied from interface: ContentLoadingObserver
triggers a cache sync, i.e. forces to write out all cached pages. sync() is called from time to time by the background sync daemon.

Specified by:
sync in interface ContentLoadingObserver

flush

public void flush()
Specified by:
flush in interface ContentLoadingObserver

remove

public void remove()
Description copied from interface: ContentLoadingObserver
remove all pending modifications, for the current document.

Specified by:
remove in interface ContentLoadingObserver

dropIndex

public void dropIndex(Collection collection)
Description copied from interface: ContentLoadingObserver
Drop all index entries for the given collection.

Specified by:
dropIndex in interface ContentLoadingObserver

dropIndex

public void dropIndex(DocumentImpl document)
               throws ReadOnlyException
Description copied from interface: ContentLoadingObserver
Drop all index entries for the given document.

Specified by:
dropIndex in interface ContentLoadingObserver
Throws:
ReadOnlyException

find

public NodeSet find(int relation,
                    DocumentSet docs,
                    NodeSet contextSet,
                    int axis,
                    QName qname,
                    Indexable value)
             throws TerminatedException
Throws:
TerminatedException

findAll

public NodeSet findAll(int relation,
                       DocumentSet docs,
                       NodeSet contextSet,
                       int axis,
                       Indexable value)
                throws TerminatedException
Throws:
TerminatedException

match

public NodeSet match(DocumentSet docs,
                     NodeSet contextSet,
                     int axis,
                     String expr,
                     QName qname,
                     int type)
              throws TerminatedException,
                     EXistException
Throws:
TerminatedException
EXistException

match

public NodeSet match(DocumentSet docs,
                     NodeSet contextSet,
                     int axis,
                     String expr,
                     QName qname,
                     int type,
                     int flags,
                     boolean caseSensitiveQuery)
              throws TerminatedException,
                     EXistException
Throws:
TerminatedException
EXistException

matchAll

public NodeSet matchAll(DocumentSet docs,
                        NodeSet contextSet,
                        int axis,
                        String expr,
                        int type,
                        int flags,
                        boolean caseSensitiveQuery)
                 throws TerminatedException,
                        EXistException
Throws:
TerminatedException
EXistException

matchAll

public NodeSet matchAll(DocumentSet docs,
                        NodeSet contextSet,
                        int axis,
                        String expr,
                        List qnames,
                        int type,
                        int flags,
                        boolean caseSensitiveQuery,
                        NodeSet result)
                 throws TerminatedException,
                        EXistException
Regular expression search

Parameters:
type - like type argument for RegexMatcher constructor
flags - like flags argument for RegexMatcher constructor
Throws:
TerminatedException
EXistException

scanIndexKeys

public ValueOccurrences[] scanIndexKeys(DocumentSet docs,
                                        NodeSet contextSet,
                                        Indexable start)

scanIndexKeys

public ValueOccurrences[] scanIndexKeys(DocumentSet docs,
                                        NodeSet contextSet,
                                        QName[] qnames,
                                        Indexable start)
Scan all index keys indexed by the given QName. Return ValueOccurrences for those index entries pointing to descendants of the specified context set. The first argument specifies the set of documents to include in the scan. Nodes which are not in this document set will be ignored.

Parameters:
docs - set of documents to scan
contextSet - if != null, return only index entries pointing to nodes which are descendants of nodes in the context set
qnames - an array of QNames: defines the index entries to be scanned.
start - an optional start value: only index keys starting with or being greater than this start value (depends on the type of the index key) will be scanned
Returns:
a list of ValueOccurrences

closeAndRemove

public void closeAndRemove()
Specified by:
closeAndRemove in interface ContentLoadingObserver

close

public boolean close()
              throws DBException
Specified by:
close in interface ContentLoadingObserver
Throws:
DBException

printStatistics

public void printStatistics()
Specified by:
printStatistics in interface ContentLoadingObserver

toString

public String toString()
Overrides:
toString in class Object


Copyright (C) Wolfgang Meier. All rights reserved.