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_FieldCacheImpl_ 00008 #define _lucene_search_FieldCacheImpl_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/index/IndexReader.h" 00015 #include "FieldCache.h" 00016 #include "Sort.h" 00017 00018 00019 CL_NS_DEF(search) 00020 00021 00022 00026 class FieldCacheImpl: public FieldCache { 00027 public: 00028 DEFINE_MUTEX(THIS_LOCK) 00029 00030 00031 class FileEntry:LUCENE_BASE { 00032 const TCHAR* field; // which Field 00033 int32_t type; // which SortField type 00034 SortComparatorSource* custom; // which custom comparator 00035 size_t _hashCode; 00036 public: 00038 FileEntry (const TCHAR* field, int32_t type); 00039 00041 FileEntry (const TCHAR* field, SortComparatorSource* custom); 00042 ~FileEntry(); 00043 00044 int32_t getType() const{ return type; } 00045 00047 bool equals (FileEntry* other) const; 00048 00050 size_t hashCode(); 00051 00052 int32_t compareTo(const FileEntry* other) const; 00053 00054 class Compare:LUCENE_BASE, public CL_NS(util)::Compare::_base //<Term*> 00055 { 00056 public: 00057 bool operator()( FileEntry* f1, FileEntry* f2 ) const{ 00058 return ( f1->compareTo(f2) < 0 ); 00059 } 00060 size_t operator()( FileEntry* t ) const{ 00061 return t->hashCode(); 00062 } 00063 }; 00064 class Equals:LUCENE_BASE, public CL_NS(util)::Compare::_base //<Term*> 00065 { 00066 public: 00067 bool operator()( FileEntry* f1, FileEntry* f2 ) const{ 00068 return ( f1->compareTo(f2) == 0 ); 00069 } 00070 }; 00071 }; 00072 00073 FieldCacheImpl(); 00074 ~FieldCacheImpl(); 00075 private: 00076 00079 class fieldcacheCacheReaderType: public CL_NS(util)::CLHashMap<FileEntry*, 00080 FieldCacheAuto*, 00081 FileEntry::Compare, 00082 FileEntry::Equals, 00083 CL_NS(util)::Deletor::Object<FileEntry>, 00084 CL_NS(util)::Deletor::Object<FieldCacheAuto> >{ 00085 public: 00086 fieldcacheCacheReaderType(); 00087 ~fieldcacheCacheReaderType(); 00088 }; 00089 00090 //note: typename gets too long if using cacheReaderType as a typename 00091 typedef CL_NS(util)::CLHashMap<CL_NS(index)::IndexReader*, 00092 fieldcacheCacheReaderType*, 00093 CL_NS(util)::Compare::Void<CL_NS(index)::IndexReader>, 00094 CL_NS(util)::Equals::Void<CL_NS(index)::IndexReader>, 00095 CL_NS(util)::Deletor::Object<CL_NS(index)::IndexReader>, 00096 CL_NS(util)::Deletor::Object<fieldcacheCacheReaderType> > fieldcacheCacheType; 00097 00099 //todo: make indexreader remove itself from here when the reader is shut 00100 fieldcacheCacheType cache; 00101 00103 FieldCacheAuto* lookup (CL_NS(index)::IndexReader* reader, const TCHAR* field, int32_t type) ; 00104 00106 FieldCacheAuto* lookup (CL_NS(index)::IndexReader* reader, const TCHAR* field, SortComparatorSource* comparer); 00107 00109 void store (CL_NS(index)::IndexReader* reader, const TCHAR* field, int32_t type, FieldCacheAuto* value); 00110 00112 void store (CL_NS(index)::IndexReader* reader, const TCHAR* field, SortComparatorSource* comparer, FieldCacheAuto* value); 00113 00114 public: 00115 00116 // inherit javadocs 00117 FieldCacheAuto* getInts (CL_NS(index)::IndexReader* reader, const TCHAR* field); 00118 00119 // inherit javadocs 00120 FieldCacheAuto* getFloats (CL_NS(index)::IndexReader* reader, const TCHAR* field); 00121 00122 // inherit javadocs 00123 FieldCacheAuto* getStrings (CL_NS(index)::IndexReader* reader, const TCHAR* field); 00124 00125 // inherit javadocs 00126 FieldCacheAuto* getStringIndex (CL_NS(index)::IndexReader* reader, const TCHAR* field); 00127 00128 // inherit javadocs 00129 FieldCacheAuto* getAuto (CL_NS(index)::IndexReader* reader, const TCHAR* field); 00130 00131 // inherit javadocs 00132 FieldCacheAuto* getCustom (CL_NS(index)::IndexReader* reader, const TCHAR* field, SortComparator* comparator); 00133 00134 00139 static void closeCallback(CL_NS(index)::IndexReader* reader, void* fieldCacheImpl); 00140 }; 00141 00142 00143 CL_NS_END 00144 #endif