package org.dbxml.core.indexer;

/*
 * dbXML License, Version 1.0
 *
 *
 * Copyright (c) 1999-2001 The dbXML Group, L.L.C.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        The dbXML Group (http://www.dbxml.com/)."
 *    Alternately, this acknowledgment may appear in the software
 *    itself, if and wherever such third-party acknowledgments normally
 *    appear.
 *
 * 4. The names "dbXML" and "The dbXML Group" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    info@dbxml.com.
 *
 * 5. Products derived from this software may not be called "dbXML",
 *    nor may "dbXML" appear in their name, without prior written
 *    permission of The dbXML Group.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE DBXML GROUP OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: Indexer.java,v 1.13 2001/08/06 03:10:01 tom Exp $
 */

import org.dbxml.server.*;
import org.dbxml.core.*;
import org.dbxml.core.data.*;
import org.w3c.dom.*;

/**
 * Indexer is the abstract indexing interface for dbXML.  An Indexer
 * object is implemented in order to retrieve and manage indexes.
 * <br><br>
 * Any number of Indexer instances may be associated with a single
 * Collection.  The type of Indexer utilized by a query depends on
 * the 'Style' of Indexer and the type of QueryResolver that is being
 * used to performt he query.  Currently, dbXML only internally
 * supports one kind of Indexer: 'XPath'.
 */

public interface Indexer extends Named, DBObject, Configurable {
   static final String STYLE_NODENAME = "Node:Name";
   static final String STYLE_NODEVALUE = "Node:Value";
   static final String STYLE_FULLTEXT = "Node:FullText";

   /**
    * setCollection tells the Indexer who its parent is.
    *
    * @param collection The owner Collection
    */
   void setCollection(Collection collection);
   
   /**
    * getIndexStyle returns 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.
    *
    * @return The index style
    */
   String getIndexStyle();
   
   /**
    * getPattern returns 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:
    * <pre>
    *    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
    * </pre>
    * 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.
    *
    * @return The Pattern used
    */
   String getPattern();
   
   /**
    * remove removes all references to the specified Key from the Indexer.
    *
    * @param value The value to remove
    * @param key The Object ID
    * @param pos The offset into the stream the Element occurs at
    * @param len The length of the substream for the Element
    * @param elemID The Element ID of the value
    * @param attrID The Attribute ID of the value (if any, else -1)
    */
   void remove(String value, Key key, int pos, int len, short elemID, short attrID) throws DBException;

   /**
    * add adds a Document to the Indexer.
    *
    * @param value The value to remove
    * @param key The Object ID
    * @param pos The offset into the stream the Element occurs at
    * @param len The length of the substream for the Element
    * @param elemID The Element ID of the value
    * @param attrID The Attribute ID of the value (if any, else -1)
    */
   void add(String value, Key key, int pos, int len, short elemID, short attrID) throws DBException;
      
   /**
    * queryMatches retrieves a set of MatchEntry instances that match
    * the supplied 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.
    *
    * @param query The IndexQuery to use
    * @return The resulting matches
    */
   IndexMatch[] queryMatches(IndexQuery query) throws DBException;
}

