CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_search_FieldSortedHitQueue_ 00008 #define _lucene_search_FieldSortedHitQueue_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "FieldCache.h" 00015 #include "Sort.h" 00016 #include "FieldDocSortedHitQueue.h" 00017 #include "SearchHeader.h" 00018 #include "FieldCacheImpl.h" 00019 #include "CLucene/util/PriorityQueue.h" 00020 00021 CL_NS_DEF(search) 00022 00023 00024 00031 class FieldSortedHitQueue: public CL_NS(util)::PriorityQueue<FieldDoc*, 00032 CL_NS(util)::Deletor::Object<FieldDoc> > { 00033 00036 class hitqueueCacheReaderType: public CL_NS(util)::CLHashMap<FieldCacheImpl::FileEntry*, 00037 ScoreDocComparator*, 00038 FieldCacheImpl::FileEntry::Compare, 00039 FieldCacheImpl::FileEntry::Equals, 00040 CL_NS(util)::Deletor::Object<FieldCacheImpl::FileEntry>, 00041 CL_NS(util)::Deletor::Object<ScoreDocComparator> >{ 00042 00043 public: 00044 hitqueueCacheReaderType(bool deleteValue){ 00045 setDeleteKey(true); 00046 setDeleteValue(deleteValue); 00047 } 00048 ~hitqueueCacheReaderType(){ 00049 clear(); 00050 } 00051 00052 }; 00053 00054 public: //todo: remove this and below after close callback is implemented 00055 //note: typename gets too long if using cacheReaderType as a typename 00056 typedef CL_NS(util)::CLHashMap<CL_NS(index)::IndexReader*, 00057 hitqueueCacheReaderType*, 00058 CL_NS(util)::Compare::Void<CL_NS(index)::IndexReader>, 00059 CL_NS(util)::Equals::Void<CL_NS(index)::IndexReader>, 00060 CL_NS(util)::Deletor::Object<CL_NS(index)::IndexReader>, 00061 CL_NS(util)::Deletor::Object<hitqueueCacheReaderType> > hitqueueCacheType; 00062 00066 static hitqueueCacheType Comparators; 00067 private: 00068 00070 static ScoreDocComparator* lookup (CL_NS(index)::IndexReader* reader, const TCHAR* field, int32_t type, SortComparatorSource* factory); 00071 00075 static void store (CL_NS(index)::IndexReader* reader, const TCHAR* field, int32_t type, SortComparatorSource* factory, ScoreDocComparator* value); 00076 00077 00078 //todo: Locale locale, not implemented yet 00079 static ScoreDocComparator* getCachedComparator (CL_NS(index)::IndexReader* reader, 00080 const TCHAR* fieldname, int32_t type, SortComparatorSource* factory); 00081 00082 00090 static ScoreDocComparator* comparatorInt (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname); 00091 00099 static ScoreDocComparator* comparatorFloat (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname); 00100 00108 static ScoreDocComparator* comparatorString (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname); 00109 00110 00111 //todo: 00149 static ScoreDocComparator* comparatorAuto (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname); 00150 00151 00152 protected: 00154 ScoreDocComparator** comparators; 00155 int32_t comparatorsLen; 00156 00158 SortField** fields; 00159 int32_t fieldsLen; 00160 00164 float_t maxscore; 00165 00172 bool lessThan (FieldDoc* docA, FieldDoc* docB); 00173 public: 00174 00182 FieldSortedHitQueue (CL_NS(index)::IndexReader* reader, SortField** fields, int32_t size); 00183 00184 ~FieldSortedHitQueue(); 00185 00190 static void closeCallback(CL_NS(index)::IndexReader* reader, void* param); 00191 00202 FieldDoc* fillFields (FieldDoc* doc) const; 00203 00204 void setFields (SortField** fields){ 00205 this->fields = fields; 00206 } 00207 00209 SortField** getFields() { 00210 return fields; 00211 } 00212 }; 00213 00214 00215 CL_NS_END 00216 #endif