00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef INDRI_FIELDDATA_HPP
00020 #define INDRI_FIELDDATA_HPP
00021
00022 #define INDRI_FIELD_BUFFERSIZE (1024*1024)
00023
00024 #include "indri/FieldListDiskBuilder.hpp"
00025 #include "indri/FieldStatistics.hpp"
00026
00027 namespace indri {
00028 namespace index {
00029 struct FieldData {
00030 FieldStatistics statistics;
00031 FieldListDiskBuilder* list;
00032 File* listFile;
00033
00034 FieldData( const std::string& fieldName, bool isNumeric ) : statistics(fieldName, isNumeric) {
00035 listFile = 0;
00036 list = 0;
00037 }
00038
00039 ~FieldData() {
00040 close();
00041 }
00042
00043 void create( const std::string& name ) {
00044 close();
00045
00046 listFile = new File();
00047 listFile->open( name, std::fstream::out | std::fstream::binary | std::fstream::trunc );
00048 list = new FieldListDiskBuilder( *listFile, INDRI_FIELD_BUFFERSIZE, statistics.isNumeric );
00049 }
00050
00051 void open( const std::string& name ) {
00052 close();
00053
00054 listFile = new File();
00055 listFile->open( name, std::fstream::in | std::fstream::out | std::fstream::binary );
00056 listFile->seekp( 0, std::fstream::end );
00057 list = new FieldListDiskBuilder( *listFile, INDRI_FIELD_BUFFERSIZE, statistics.isNumeric );
00058 }
00059
00060 void openRead( const std::string& name ) {
00061 close();
00062
00063 listFile = new File();
00064 listFile->open( name, std::fstream::in | std::fstream::binary );
00065 listFile->seekp( 0, std::fstream::end );
00066 list = new FieldListDiskBuilder( *listFile, INDRI_FIELD_BUFFERSIZE, statistics.isNumeric );
00067 }
00068
00069 void close() {
00070 if( list )
00071 list->close();
00072 delete list;
00073 list = 0;
00074
00075 if( listFile )
00076 listFile->close();
00077 delete listFile;
00078 listFile = 0;
00079 }
00080 };
00081 }
00082 }
00083
00084 #endif // INDRI_FIELDDATA_HPP