001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.search;
020
021import java.io.IOException;
022
023import lucee.commons.io.log.LogAndSource;
024import lucee.commons.io.res.Resource;
025import lucee.runtime.config.Config;
026import lucee.runtime.type.Query;
027
028import org.w3c.dom.Element;
029import org.xml.sax.SAXException;
030
031/**
032 * interface for a Search Engine
033 */
034public interface SearchEngine {
035
036    /**
037     * overwrite allowed
038     */
039    public static final boolean ALLOW_OVERWRITE = true;
040
041    /**
042     * overwrite denied
043     */
044    public static final boolean DENY_OVERWRITE = false;
045
046    /**
047     * constructor of the class
048     * @param config 
049     * @param searchDir directory where the lucee xml file is
050     * @param log 
051     * @throws IOException
052     * @throws SAXException
053     * @throws SearchException
054     */
055    public abstract void init(Config config, Resource searchDir, LogAndSource log) // FUTURE remove argument LogAndSource
056            throws SAXException, IOException, SearchException;
057
058    /**
059     * returns a collection by name
060     * @param name name of the desired collection (case insensitive)
061     * @return returns lucene collection object matching name
062     * @throws SearchException if no matching Collection exist 
063     */
064    public abstract SearchCollection getCollectionByName(String name)
065            throws SearchException;
066
067    /**
068     * @return returns all collections as a query object
069     */
070    public abstract Query getCollectionsAsQuery();
071
072    /**
073     * Creates a new Collection and Store it (creating always a spellindex)
074     * @param name The Name of the Collection
075     * @param path the path to store
076     * @param language The language of the collection
077     * @param allowOverwrite
078     * @return New SearchCollection
079     * @throws SearchException
080     */
081    public abstract SearchCollection createCollection(String name, Resource path,
082            String language, boolean allowOverwrite) throws SearchException;
083
084
085    /**
086     * @return returns the directory of the search storage
087     */
088    public abstract Resource getDirectory();
089
090    /**
091     * @return returns the logfile of the search storage
092     */
093    public abstract LogAndSource getLogger(); // FUTURE deprecated
094
095    /**
096     * return XML Element Matching index id
097     * @param collElement XML Collection Element
098     * @param id
099     * @return XML Element
100     */
101    public abstract Element getIndexElement(Element collElement, String id);
102
103    /**
104     * @return returns the Name of the search engine to display in admin
105     */
106    public abstract String getDisplayName();
107
108}