1 /* 2 * Copyright 2005-2008 Fabrice Colin 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef _INDEX_INTERFACE_H 20 #define _INDEX_INTERFACE_H 21 22 #include <string> 23 #include <set> 24 #include <map> 25 26 #include "Document.h" 27 #include "Visibility.h" 28 29 /// Interface implemented by indexes. 30 class PINOT_EXPORT IndexInterface 31 { 32 public: IndexInterface(const IndexInterface & other)33 IndexInterface(const IndexInterface &other) {}; ~IndexInterface()34 virtual ~IndexInterface() {}; 35 36 typedef enum { BY_LABEL = 0, BY_DIRECTORY, BY_FILE, BY_CONTAINER_FILE } NameType; 37 38 /// Returns false if the index couldn't be opened. 39 virtual bool isGood(void) const = 0; 40 41 /// Gets metadata. 42 virtual std::string getMetadata(const std::string &name) const = 0; 43 44 /// Sets metadata. 45 virtual bool setMetadata(const std::string &name, const std::string &value) const = 0; 46 47 /// Gets the index location. 48 virtual std::string getLocation(void) const = 0; 49 50 /// Returns a document's properties. 51 virtual bool getDocumentInfo(unsigned int docId, DocumentInfo &docInfo) const = 0; 52 53 /// Returns a document's terms count. 54 virtual unsigned int getDocumentTermsCount(unsigned int docId) const = 0; 55 56 /// Returns a document's terms. 57 virtual bool getDocumentTerms(unsigned int docId, 58 std::map<unsigned int, std::string> &wordsBuffer) const = 0; 59 60 /// Sets the list of known labels. 61 virtual bool setLabels(const std::set<std::string> &labels, bool resetLabels) = 0; 62 63 /// Gets the list of known labels. 64 virtual bool getLabels(std::set<std::string> &labels) const = 0; 65 66 /// Adds a label. 67 virtual bool addLabel(const std::string &name) = 0; 68 69 /// Deletes all references to a label. 70 virtual bool deleteLabel(const std::string &name) = 0; 71 72 /// Determines whether a document has a label. 73 virtual bool hasLabel(unsigned int docId, const std::string &name) const = 0; 74 75 /// Returns a document's labels. 76 virtual bool getDocumentLabels(unsigned int docId, std::set<std::string> &labels) const = 0; 77 78 /// Sets a document's labels. 79 virtual bool setDocumentLabels(unsigned int docId, const std::set<std::string> &labels, 80 bool resetLabels = true) = 0; 81 82 /// Sets documents' labels. 83 virtual bool setDocumentsLabels(const std::set<unsigned int> &docIds, 84 const std::set<std::string> &labels, bool resetLabels = true) = 0; 85 86 /// Checks whether the given URL is in the index. 87 virtual unsigned int hasDocument(const std::string &url) const = 0; 88 89 /// Gets terms with the same root. 90 virtual unsigned int getCloseTerms(const std::string &term, std::set<std::string> &suggestions) = 0; 91 92 /// Returns the ID of the last document. 93 virtual unsigned int getLastDocumentID(void) const = 0; 94 95 /// Returns the number of documents. 96 virtual unsigned int getDocumentsCount(const std::string &labelName = "") const = 0; 97 98 /// Lists documents. 99 virtual unsigned int listDocuments(std::set<unsigned int> &docIDList, 100 unsigned int maxDocsCount = 0, unsigned int startDoc = 0) const = 0; 101 102 /// Lists documents. 103 virtual bool listDocuments(const std::string &name, std::set<unsigned int> &docIds, 104 NameType type, unsigned int maxDocsCount = 0, unsigned int startDoc = 0) const = 0; 105 106 /// Indexes the given data. 107 virtual bool indexDocument(const Document &doc, const std::set<std::string> &labels, 108 unsigned int &docId) = 0; 109 110 /// Updates the given document. 111 virtual bool updateDocument(unsigned int docId, const Document &doc) = 0; 112 113 /// Updates a document's properties. 114 virtual bool updateDocumentInfo(unsigned int docId, const DocumentInfo &docInfo) = 0; 115 116 /// Unindexes the given document. 117 virtual bool unindexDocument(unsigned int docId) = 0; 118 119 /// Unindexes the given document. 120 virtual bool unindexDocument(const std::string &location) = 0; 121 122 /// Unindexes documents. 123 virtual bool unindexDocuments(const std::string &name, NameType type) = 0; 124 125 /// Unindexes all documents. 126 virtual bool unindexAllDocuments(void) = 0; 127 128 /// Flushes recent changes to the disk. 129 virtual bool flush(void) = 0; 130 131 /// Reopens the index. 132 virtual bool reopen(void) const = 0; 133 134 /// Resets the index. 135 virtual bool reset(void) = 0; 136 137 protected: IndexInterface()138 IndexInterface() { }; 139 140 }; 141 142 #endif // _INDEX_INTERFACE_H 143