FirteX-高性能全文索引和检索平台API Documentation |
00001 // 00002 // Copyright(C) 2005--2006 Institute of Computing Tech, Chinese Academy of Sciences. 00003 // All rights reserved. 00004 // This file is part of FirteX (www.firtex.org) 00005 // 00006 // Use of the FirteX is subject to the terms of the software license set forth in 00007 // the LICENSE file included with this software, and also available at 00008 // http://www.firtex.org/license.html 00009 // 00010 // Author : 郭瑞杰(GuoRuijie) 00011 // Email : ruijieguo@software.ict.ac.cn,ruijieguo@gmail.com 00012 // Created : 2006/6/27 00013 // 00014 #ifndef _DOCUMENTSCHEMA_H 00015 #define _DOCUMENTSCHEMA_H 00016 00017 #if _MSC_VER > 1000 00018 #pragma once 00019 #endif // _MSC_VER > 1000 00020 00021 #include "Field.h" 00022 #include "../utility/FXString.h" 00023 #include <vector> 00024 #include "../utility/XML.h" 00025 00026 using namespace std; 00027 using namespace firtex::utility; 00028 00029 00030 namespace firtex 00031 { 00032 namespace document 00033 { 00034 class CSchemaItem 00035 { 00036 public: 00037 CSchemaItem(); 00038 CSchemaItem(fieldid_t id,const tchar* name,FieldType ft,Store_ store,Index_ index,TermVector_ tv,float fBoost = 1.0); 00039 CSchemaItem(const CSchemaItem& src); 00040 ~CSchemaItem(); 00041 00042 public: 00043 fieldid_t getId(){return m_id;} 00044 const tchar* getName(){return m_name;} 00045 FieldType getFieldType(){return m_fieldType;} 00046 Store_ getStore(){return m_store;} 00047 Index_ getIndex(){return m_index;} 00048 TermVector_ getTermVector(){return m_termVector;} 00049 float getBoost(){return m_fBoost;} 00050 public: 00065 bool load(CXMLElement* pXML); 00066 00071 void save(CXMLElement* pXML); 00072 public: 00078 bool operator==(const CSchemaItem& right) const; 00079 bool operator!=(const CSchemaItem& right) const; 00080 protected: 00081 fieldid_t m_id; //编号 00082 CFXString m_name; //名称 00083 FieldType m_fieldType; //类型,见FieldType定义 00084 Store_ m_store; //存储方式 00085 Index_ m_index; //索引方式 00086 TermVector_ m_termVector; //词向量方式 00087 float m_fBoost; //boost值 00088 00089 friend class CDocumentSchema; 00090 }; 00091 00092 class CDocumentSchema 00093 { 00094 public: 00095 CDocumentSchema(void); 00096 CDocumentSchema(const CDocumentSchema& src); 00097 virtual ~CDocumentSchema(void); 00098 public: 00099 fieldid_t addKeywordItem(const tchar* name,FieldType ft); 00100 fieldid_t addUnIndexedItem(const tchar* name); 00101 fieldid_t addTextItem(const tchar* name, FieldType ft,Store_ store=Store::NO,TermVector_ termVector=TermVector::NO); 00102 fieldid_t addUnStoredItem(const tchar* name,FieldType ft,TermVector_ termVector=TermVector::NO); 00103 fieldid_t addBinaryItem(const tchar* name,bool bCompress); 00104 00105 fieldid_t addItem(const CSchemaItem& item); 00106 00107 bool deleteItem(const tchar* name); 00108 00109 void addSchema(const CDocumentSchema& src); 00110 public: 00111 int getCount()const{return (int)m_items.size();} 00112 00113 void startIterator(){m_iterator = m_items.begin();} 00114 bool hasNext(){return (m_iterator != m_items.end());} 00115 CSchemaItem* next(){return *m_iterator++;} 00116 00117 CSchemaItem* operator[](fieldid_t id); 00118 CSchemaItem* operator[](const tchar* name); 00119 00120 CDocumentSchema& operator= (const CDocumentSchema& right); 00121 CDocumentSchema& operator+= (const CDocumentSchema& right); 00122 00123 public: 00139 void loadSchema(const tchar* schemaFile); 00140 00145 void saveSchema(const tchar* schemaFile); 00146 00150 void clear(); 00151 private: 00152 vector<CSchemaItem*> m_items; 00153 vector<CSchemaItem*>::iterator m_iterator; 00154 tstring m_schemaFile; 00155 }; 00156 00158 //CSchemaItem's inline function 00159 inline bool CSchemaItem::operator==(const CSchemaItem& right) const 00160 { 00161 return ( (m_name == right.m_name) && (m_fieldType == right.m_fieldType) && 00162 (m_store == right.m_store) && (m_index == right.m_index) && 00163 (m_termVector == right.m_termVector) && (m_fBoost == right.m_fBoost) ); 00164 } 00165 inline bool CSchemaItem::operator!=(const CSchemaItem& right) const 00166 { 00167 return !(*this == right); 00168 } 00169 00171 //CDocumentSchema's inline function 00172 inline CSchemaItem* CDocumentSchema::operator[](fieldid_t id) 00173 { 00174 return m_items[id]; 00175 } 00176 inline CSchemaItem* CDocumentSchema::operator[](const tchar* name) 00177 { 00178 vector<CSchemaItem*>::iterator iter = m_items.begin(); 00179 while (iter!=m_items.end()) 00180 { 00181 if((*iter)->m_name == name) 00182 return (*iter); 00183 iter++; 00184 } 00185 } 00186 inline CDocumentSchema& CDocumentSchema::operator+= (const CDocumentSchema& right) 00187 { 00188 addSchema(right); 00189 return *this; 00190 } 00191 inline CDocumentSchema& CDocumentSchema::operator= (const CDocumentSchema& right) 00192 { 00193 clear(); 00194 vector<CSchemaItem*>::const_iterator iter = right.m_items.begin(); 00195 while (iter != right.m_items.end()) 00196 { 00197 m_items.push_back(new CSchemaItem(*(*iter))); 00198 iter++; 00199 } 00200 return *this; 00201 } 00202 } 00203 } 00204 00205 00206 #endif
http://www.firtex.org http://www.sourceforge.net/projects/firtex