FirteX-高性能全文索引和检索平台

API Documentation


首页 | 名字空间列表 | 类继承关系 | 组合类型列表 | $(BL\录(B | 文件列表 | 名字空间成员 | 组合类型成员 | 文件成员

NormsReader.h

浏览该文件的文档。
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
00012 // Created      : 2006/1/4
00013 //
00014 #ifndef _NORMSREADER_H
00015 #define _NORMSREADER_H
00016 #include "../utility/StdHeader.h"
00017 #include "../store/IndexInput.h"
00018 #include "../store/Directory.h"
00019 #include "../document/Field.h"
00020 #include "FieldsInfo.h"
00021 #include "NormBytes.h"
00022 #include <sstream>
00023 using namespace firtex::document;
00024 using namespace firtex::store;
00025 #include <map>
00026 using namespace std;
00027 
00028 namespace firtex
00029 {
00030         namespace index
00031         {
00032                 
00033                 class CNormsReader
00034                 {
00035                         
00036                         class CNorm
00037                         {
00038                         public:
00039                                 CNorm()
00040                                 {
00041                                         m_pNormStream = NULL;                                   
00042                                 }
00043                                 ~CNorm()
00044                                 {
00045                                         if(m_pNormStream)
00046                                         {
00047                                                 m_pNormStream->close();
00048                                                 delete m_pNormStream;
00049                                                 m_pNormStream = NULL;
00050                                         }                                                                               
00051                                 }
00052                         public:
00053                                 bool    read()
00054                                 {
00055                                         m_normBytes.len = (size_t)m_pNormStream->length();
00056                                         if(m_normBytes.len <= 0)
00057                                                 return false;
00058                                         m_normBytes.bytes = new byte[m_normBytes.len];
00059                                         m_pNormStream->readBytes(m_normBytes.bytes,0,m_normBytes.len);
00060                                         return true;
00061                                 }
00062                         public:
00063                                 CIndexInput*    m_pNormStream;
00064                                 CNormBytes              m_normBytes;
00065                         };
00066                 public:
00067                         CNormsReader(CDirectory* pDirectory);
00068                         virtual ~CNormsReader(void);
00069                 public:
00070                         void                            open(const tchar* barrelName,CFieldsInfo* pFieldsInfo);
00071                         inline CNormBytes*      getNorms(const tchar* fieldname);
00072                         inline CNormBytes*      getNorms(fieldid_t fid);
00073                         void                            close();
00074                 protected:
00075                         CDirectory*                             m_pDirectory;
00076                         CFieldsInfo*                    m_pFieldsInfo;
00077                         string                                  m_barrelName;
00078 
00079                         map<fieldid_t,CNorm*>   m_normsByID;
00080                         map<string,CNorm*>              m_normsByName;
00081                 };
00083                 //Inline Functions
00084                 CNormBytes* CNormsReader::getNorms(const tchar* fieldname)
00085                 {
00086                         map<string,CNorm*>::iterator iter = m_normsByName.find(fieldname);
00087                         if(iter !=m_normsByName.end())
00088                         {
00089                                 return &(iter->second->m_normBytes);
00090                         }
00091                         return NULL;
00092                 }
00093                 CNormBytes* CNormsReader::getNorms(fieldid_t fid)
00094                 {
00095                         map<fieldid_t,CNorm*>::iterator iter = m_normsByID.find(fid);
00096                         if(iter !=m_normsByID.end())
00097                         {
00098                                 return &(iter->second->m_normBytes);
00099                         }
00100                         return NULL;
00101                 }
00102         }
00103 }
00104 
00105 
00106 #endif

http://www.firtex.org http://www.sourceforge.net/projects/firtex