Xindice API
version 1.1

org.apache.xindice.core.indexer
Class MemValueIndexer

java.lang.Object
  |
  +--org.apache.xindice.core.indexer.MemValueIndexer
All Implemented Interfaces:
Configurable, DBObject, Indexer, Named

public class MemValueIndexer
extends Object
implements Indexer

Provides an in-memory implementation of Xindice Indexer based upon the Java TreeSet class. This implementation is not persistent. A MemValueIndexer is useful for indexing of temporary Collections (e.g. those based on MemFiler). It is also useful for temporary indexing of persistent Collections.

Version:
$Revision: 511426 $, $Date: 2007-02-24 22:25:02 -0500 (Sat, 24 Feb 2007) $
Author:
Terry Rosenbaum (terry@amicas.com)

Fields inherited from interface org.apache.xindice.core.indexer.Indexer
STYLE_FULLTEXT, STYLE_NODENAME, STYLE_NODEVALUE
 
Constructor Summary
MemValueIndexer()
           
 
Method Summary
 void add(String theValue, Key theKey, int thePosition, int theLength, short theElementID, short theAttributeID)
          Adds a value reference to the index.
 boolean close()
          Closes this index.
 boolean create()
          Creates a new MemValueIndexer.
 boolean drop()
          Removes this index from existence.
 boolean exists()
          Indicates whether or not this index exists.
 void flush()
          flush forcefully flushes any unwritten buffers to disk.
 Configuration getConfig()
          getConfig retrieves the configuration information for the Configurable object instance.
 String getIndexStyle()
          Provides the index style.
 String getName()
          Provides the name of this index.
 String getPattern()
          Provides the pattern recognized by this Indexer.
 boolean isOpened()
          Indicates whether or not this indexer is open.
 boolean open()
          Opens the index so it can be used.
 IndexMatch[] queryMatches(IndexQuery theQuery)
          Provides a set of MatchEntry instances that match the specified query.
 void remove(String theValue, Key theKey, int thePosition, int theLength, short theElementID, short theAttributeID)
          Removes the specified value reference from the index.
 void setCollection(Collection theCollection)
          Sets the parent Collection of this indexer.
 void setConfig(Configuration theConfig)
          setConfig sets the configuration information for the Configurable object instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemValueIndexer

public MemValueIndexer()
Method Detail

setCollection

public void setCollection(Collection theCollection)
Sets the parent Collection of this indexer.
Specified by:
setCollection in interface Indexer
Parameters:
theCollection - The owner Collection

getIndexStyle

public String getIndexStyle()
Provides the index style. Different query languages will need to draw from different indexing styles. For example, A query that is written in quilt will require XPath indexing.
Specified by:
getIndexStyle in interface Indexer
Returns:
the index style

getPattern

public String getPattern()
Provides the pattern recognized by this Indexer. Patterns must be in the form of (elem|*)[@(attr|*)] to tell the IndexManager which element types to send to it, so for example:
    contact@name  Indexes all contacts by name attribute
    memo          Indexes the text of all memo elements
    contact@*     Indexes all contact attributes
    *@name        Indexes the name attribute for all elements
    *             Indexes the text of all elements
    *@*           Indexes all attributes of all elements
 
These patterns are used by the IndexManager when handling SAX events. All events that match the specified pattern will result in an add or remove call to the Indexer.
Specified by:
getPattern in interface Indexer
Returns:
the pattern used by this index

remove

public void remove(String theValue,
                   Key theKey,
                   int thePosition,
                   int theLength,
                   short theElementID,
                   short theAttributeID)
            throws DBException
Removes the specified value reference from the index.
Specified by:
remove in interface Indexer
Parameters:
theValue - The value to remove
theKey - The Object ID
thePosition - The offset into the stream the Element occurs at
theLength - The length of the substream for the Element
theElementID - The Element ID of the value
theAttributeID - The Attribute ID of the value (if any, else -1)

add

public void add(String theValue,
                Key theKey,
                int thePosition,
                int theLength,
                short theElementID,
                short theAttributeID)
         throws DBException
Adds a value reference to the index.
Specified by:
add in interface Indexer
Parameters:
theValue - The value to add
theKey - The Object ID
thePosition - The offset into the stream the Element occurs at
theLength - The length of the substream for the Element
theElementID - The Element ID of the value
theAttributeID - The Attribute ID of the value (if any, else -1)

queryMatches

public IndexMatch[] queryMatches(IndexQuery theQuery)
                          throws DBException
Provides a set of MatchEntry instances that match the specified query. The matches are then used by the QueryEngine in co-sequential processing. If this indexer doesn't support the passed value, it should return 'null'. If no matches are found, it should return an empty set. queryMatches will typically be used in XPath processing.
Specified by:
queryMatches in interface Indexer
Parameters:
theQuery - The IndexQuery to use
Returns:
The resulting matches

flush

public void flush()
           throws DBException
flush forcefully flushes any unwritten buffers to disk.
Specified by:
flush in interface Indexer

setConfig

public void setConfig(Configuration theConfig)
setConfig sets the configuration information for the Configurable object instance.
Specified by:
setConfig in interface Configurable
Parameters:
theConfig - The configuration Node

getConfig

public Configuration getConfig()
getConfig retrieves the configuration information for the Configurable object instance.
Specified by:
getConfig in interface Configurable
Returns:
The configuration Node

create

public boolean create()
               throws DBException
Creates a new MemValueIndexer.
Specified by:
create in interface DBObject
Returns:
Whether or not the DBObject was created

open

public boolean open()
             throws DBException
Opens the index so it can be used. Since MemValueIndexer uses memory only as a backing store, it must always be created before it can be opened. If a call to open() has not been preceeded by a call to create(), the open() will return false. Also, this object must be configured via setConfig() before it can be opened.
Specified by:
open in interface DBObject
Returns:
true if index was opened successfully, false otherwise

isOpened

public boolean isOpened()
                 throws DBException
Indicates whether or not this indexer is open.
Specified by:
isOpened in interface DBObject
Returns:
true if open, false otherwise

exists

public boolean exists()
               throws DBException
Indicates whether or not this index exists. Since this is a memory-buffered index, it only exists after having been created.
Specified by:
exists in interface DBObject
Returns:
Whether or not the physical resource exists

drop

public boolean drop()
             throws DBException
Removes this index from existence. The indexes owner(s) is/are responsible for removing any references to the index in its own context.
Specified by:
drop in interface DBObject
Returns:
Whether or not the DBObject was dropped

close

public boolean close()
              throws DBException
Closes this index. Does nothing more than set the state returned to isOpened() to false.
Specified by:
close in interface DBObject
Returns:
Whether or not the index was closed

getName

public String getName()
Provides the name of this index.
Specified by:
getName in interface Named
Returns:
index's name

Xindice API
version 1.1

Copyright (c) 1999-2007 The Apache Software Foundation. All Rights Reserved.