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

API Documentation


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

NormsWriter.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 _NORMSWRITER_H
00015 #define _NORMSWRITER_H
00016 
00017 #include "../utility/StdHeader.h"
00018 #include "../document/Field.h"
00019 #include "../store/IndexOutput.h"
00020 #include "../store/Directory.h"
00021 #include "../search/Similarity.h"
00022 #include <sstream>
00023 using namespace firtex::document;
00024 using namespace firtex::search;
00025 using namespace firtex::store;
00026 using namespace std;
00027 
00028 namespace firtex
00029 {
00030         namespace index
00031         {
00032 #define NORMS_CACHE_FIELD       2       
00033 
00034                 class CNormsWriter
00035                 {                       
00036                 public:
00037                         CNormsWriter(CDirectory* pDirectory);
00038                         CNormsWriter(CDirectory* pDirectory,const string& barrelName);
00039                         ~CNormsWriter(void);
00040                 public:
00041                         void            open(const string& barrelName);                 
00042                         inline void     addField(docid_t docID,CField* pField);
00043                         void            close();
00044                 protected:
00045                         CDirectory*             m_pDirectory;
00046                         tstring                 m_barrelName;
00047                         CIndexOutput**  m_ppNormsStream;
00048                         int                             m_nFieldNum;                            
00049                 };
00051                 //Inline Functions
00052                 void CNormsWriter::addField(docid_t docID,CField* pField)
00053                 {
00054                         fieldid_t fid = pField->getID();
00055                         if(fid >= m_nFieldNum)
00056                         {
00057                                 CIndexOutput** ppStream = new CIndexOutput*[fid + 1];
00058                                 memset(ppStream,0,(fid + 1)*sizeof(CIndexOutput*));
00059                                 if(m_ppNormsStream)
00060                                 {
00061                                         memcpy(ppStream,m_ppNormsStream,m_nFieldNum*sizeof(CIndexOutput*));
00062                                         delete[] m_ppNormsStream;
00063                                 }
00064                                 m_nFieldNum = fid + 1;                          
00065                                 m_ppNormsStream = ppStream;
00066                         }
00067                         if(m_ppNormsStream[fid] == NULL)
00068                         {
00069                                 stringstream ss;
00070                                 ss << m_barrelName << ".n" << fid;
00071                                 m_ppNormsStream[fid] = m_pDirectory->createOutput(ss.str());                                    
00072                         }
00073                         float norm = pField->getBoost()*CSimilarity::getDefault()->lengthNorm(pField->tokensValue()?pField->tokensValue()->getTokenNum():1);
00074                         int skip = (int)docID - (int)m_ppNormsStream[fid]->getFilePointer();
00075                         if(skip < 0)
00076                                 throw CIllegalArgumentException("CNormsWriter::addField():docID is out of order.");
00077                         while (skip>0)
00078                         {
00079                                 m_ppNormsStream[fid]->writeByte(0);
00080                                 skip--;
00081                         }                       
00082 
00083                         m_ppNormsStream[fid]->writeByte(CSimilarity::encodeNorm(norm));
00084                 }
00085         }
00086 }
00087 
00088 
00089 #endif

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