From: <syn...@us...> - 2008-08-26 14:15:19
|
Revision: 2877 http://clucene.svn.sourceforge.net/clucene/?rev=2877&view=rev Author: synhershko Date: 2008-08-26 14:15:15 +0000 (Tue, 26 Aug 2008) Log Message: ----------- More several more updates, required for FieldsReader and TermInfosReader (upcoming) Modified Paths: -------------- branches/lucene2_3_2/src/core/CLucene/files_list.txt branches/lucene2_3_2/src/core/CLucene/index/FieldInfos.cpp branches/lucene2_3_2/src/core/CLucene/index/Terms.h branches/lucene2_3_2/src/core/CLucene/index/_FieldInfos.h branches/lucene2_3_2/src/shared/CLucene/debug/error.h Modified: branches/lucene2_3_2/src/core/CLucene/index/FieldInfos.cpp =================================================================== --- branches/lucene2_3_2/src/core/CLucene/index/FieldInfos.cpp 2008-08-26 11:52:28 UTC (rev 2876) +++ branches/lucene2_3_2/src/core/CLucene/index/FieldInfos.cpp 2008-08-26 14:15:15 UTC (rev 2877) @@ -44,6 +44,11 @@ CL_NS(util)::CLStringIntern::unintern(name); } +FieldInfo* FieldInfo::clone() { + return _CLNEW FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector, + storeOffsetWithTermVector, omitNorms, storePayloads); +} + FieldInfos::FieldInfos(): byName(false,false),byNumber(true) { } @@ -65,18 +70,52 @@ ); } +FieldInfos* FieldInfos::clone() +{ + FieldInfos* fis = _CLNEW FieldInfos(); + const size_t numField = byNumber.size(); + for(size_t i=0;i<numField;i++) { + FieldInfo* fi = byNumber[i]->clone(); + fis->byNumber.push_back(fi); + fis->byName.put( fi->name, fi); + } + return fis; +} + void FieldInfos::add(const Document* doc) { DocumentFieldEnumeration* fields = doc->getFields(); Field* field; while (fields->hasMoreElements()) { field = fields->nextElement(); - add(field->name(), field->isIndexed(), field->isTermVectorStored()); + add(field->name(), field->isIndexed(), field->isTermVectorStored(), field->isStorePositionWithTermVector(), + field->isStoreOffsetWithTermVector(), field->getOmitNorms()); } _CLDELETE(fields); } +void FieldInfos::addIndexed(const TCHAR** names, const bool storeTermVectors, const bool storePositionWithTermVector, + const bool storeOffsetWithTermVector) { + size_t i = 0; + while (names[i]) { + add(names[i], true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector); + ++i; + } +} + +void FieldInfos::add(const TCHAR** names,const bool isIndexed, const bool storeTermVectors, + const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads) +{ + size_t i=0; + while ( names[i] != NULL ){ + add(names[i], isIndexed, storeTermVectors, storePositionWithTermVector, + storeOffsetWithTermVector, omitNorms, storePayloads); + ++i; + } +} + FieldInfo* FieldInfos::add( const TCHAR* name, const bool isIndexed, const bool storeTermVector, - const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads) { + const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, + const bool storePayloads) { FieldInfo* fi = fieldInfo(name); if (fi == NULL) { return addInternal(name, isIndexed, storeTermVector, @@ -105,28 +144,28 @@ return fi; } -void FieldInfos::add(const TCHAR** names,const bool isIndexed, const bool storeTermVectors, - const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads) -{ - int32_t i=0; - while ( names[i] != NULL ){ - add(names[i], isIndexed, storeTermVectors, storePositionWithTermVector, - storeOffsetWithTermVector, omitNorms, storePayloads); - ++i; - } +FieldInfo* FieldInfos::addInternal( const TCHAR* name, const bool isIndexed, const bool storeTermVector, + const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, + const bool omitNorms, const bool storePayloads) { + + FieldInfo* fi = _CLNEW FieldInfo(name, isIndexed, byNumber.size(), storeTermVector, + storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads); + byNumber.push_back(fi); + byName.put( fi->name, fi); + return fi; } int32_t FieldInfos::fieldNumber(const TCHAR* fieldName)const { FieldInfo* fi = fieldInfo(fieldName); - return (fi!=NULL)?fi->number:-1; + return (fi!=NULL) ? fi->number : -1; } - FieldInfo* FieldInfos::fieldInfo(const TCHAR* fieldName) const { FieldInfo* ret = byName.get(fieldName); return ret; } -const TCHAR* FieldInfos::fieldName(const int32_t fieldNumber)const { + +const TCHAR* FieldInfos::fieldName(const int32_t fieldNumber) const { FieldInfo* fi = fieldInfo(fieldNumber); return (fi==NULL)?LUCENE_BLANK_STRING:fi->name; } @@ -137,10 +176,18 @@ return byNumber[fieldNumber]; } -int32_t FieldInfos::size()const { +size_t FieldInfos::size()const { return byNumber.size(); } +bool FieldInfos::hasVectors() const{ + for (size_t i = 0; i < size(); i++) { + if (fieldInfo(i)->storeTermVector) + return true; + } + return false; +} + void FieldInfos::write(Directory* d, const char* name) const{ IndexOutput* output = d->createOutput(name); try { @@ -152,10 +199,10 @@ } void FieldInfos::write(IndexOutput* output) const{ - output->writeVInt(size()); + output->writeVInt(static_cast<int32_t>(size())); FieldInfo* fi; uint8_t bits; - for (int32_t i = 0; i < size(); ++i) { + for (size_t i = 0; i < size(); ++i) { fi = fieldInfo(i); bits = 0x0; if (fi->isIndexed) bits |= IS_INDEXED; @@ -171,7 +218,7 @@ } void FieldInfos::read(IndexInput* input) { - int32_t size = input->readVInt(); + int32_t size = input->readVInt();//read in the size uint8_t bits; bool isIndexed,storeTermVector,storePositionsWithTermVector,storeOffsetWithTermVector,omitNorms,storePayloads; for (int32_t i = 0; i < size; ++i){ @@ -188,33 +235,5 @@ _CLDELETE_CARRAY(name); } } -FieldInfo* FieldInfos::addInternal( const TCHAR* name, const bool isIndexed, const bool storeTermVector, - const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads) { - FieldInfo* fi = _CLNEW FieldInfo(name, isIndexed, byNumber.size(), storeTermVector, - storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads); - byNumber.push_back(fi); - byName.put( fi->name, fi); - return fi; -} -bool FieldInfos::hasVectors() const{ - for (int32_t i = 0; i < size(); i++) { - if (fieldInfo(i)->storeTermVector) - return true; - } - return false; -} - -FieldInfos* FieldInfos::clone() -{ - FieldInfos* fis = _CLNEW FieldInfos(); - const size_t numField = byNumber.size(); - for(size_t i=0;i<numField;i++) { - FieldInfo* fi = byNumber[i]->clone(); - fis->byNumber.push_back(fi); - fis->byName.put( fi->name, fi); - } - return fis; -} - CL_NS_END Modified: branches/lucene2_3_2/src/core/CLucene/index/Terms.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/index/Terms.h 2008-08-26 11:52:28 UTC (rev 2876) +++ branches/lucene2_3_2/src/core/CLucene/index/Terms.h 2008-08-26 14:15:15 UTC (rev 2877) @@ -83,25 +83,26 @@ }; -// Abstract class for enumerating terms. -// -//<p>Term enumerations are always ordered by Term.compareTo(). Each term in -//the enumeration is greater than all that precede it. +/** Abstract class for enumerating terms. + + <p>Term enumerations are always ordered by Term.compareTo(). Each term in + the enumeration is greater than all that precede it. +*/ class CLUCENE_EXPORT TermEnum: LUCENE_BASE { public: - // Increments the enumeration to the next element. True if one exists. + /** Increments the enumeration to the next element. True if one exists.*/ virtual bool next()=0; // Returns a pointer to the current Term in the enumeration. virtual Term* term()=0; - - // Returns the current Term in the enumeration. + + /** Returns the current Term in the enumeration.*/ virtual Term* term(bool pointer); - // Returns the docFreq of the current Term in the enumeration. + /** Returns the docFreq of the current Term in the enumeration.*/ virtual int32_t docFreq() const=0; - // Closes the enumeration to further activity, freeing resources. + /** Closes the enumeration to further activity, freeing resources. */ virtual void close() =0; virtual ~TermEnum(); Modified: branches/lucene2_3_2/src/core/CLucene/index/_FieldInfos.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/index/_FieldInfos.h 2008-08-26 11:52:28 UTC (rev 2876) +++ branches/lucene2_3_2/src/core/CLucene/index/_FieldInfos.h 2008-08-26 14:15:15 UTC (rev 2877) @@ -61,10 +61,10 @@ //Post - The instance has been destroyed ~FieldInfo(); - FieldInfo* clone() { - return _CLNEW FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector, - storeOffsetWithTermVector, omitNorms, storePayloads); - } + /* Clones this + * @memory - caller is responsible for deleting the returned object + */ + FieldInfo* clone(); }; /** Access to the Fieldable Info file that describes document fields and whether or @@ -100,44 +100,40 @@ * @param d The directory to open the IndexInput from * @param name The name of the file to open the IndexInput from in the Directory * @throws IOException - * - * @see #read */ FieldInfos(CL_NS(store)::Directory* d, const char* name); - int32_t fieldNumber(const TCHAR* fieldName)const; - /** - * Return the fieldinfo object referenced by the fieldNumber. - * @param fieldNumber - * @return the FieldInfo object or null when the given fieldNumber - * doesn't exist. - */ - FieldInfo* fieldInfo(const TCHAR* fieldName) const; - + * Returns a deep clone of this FieldInfos instance. + * @memory caller is responisble for deleting returned object + */ + FieldInfos* clone(); + + /** Adds field info for a Document. */ + void add(const CL_NS(document)::Document* doc); + /** - * Return the fieldName identified by its number. + * Add fields that are indexed. Whether they have termvectors has to be specified. * - * @param fieldNumber - * @return the fieldName or an empty string when the field - * with the given number doesn't exist. - */ - const TCHAR* fieldName(const int32_t fieldNumber)const; + * @param names The names of the fields. An array of TCHARs, last item has to be NULL + * @param storeTermVectors Whether the fields store term vectors or not + * @param storePositionWithTermVector treu if positions should be stored. + * @param storeOffsetWithTermVector true if offsets should be stored + */ + void addIndexed(const TCHAR** names, const bool storeTermVectors, const bool storePositionWithTermVector, const bool storeOffsetWithTermVector); - FieldInfo* fieldInfo(const int32_t fieldNumber) const; - - int32_t size()const; - - bool hasVectors() const; - /** - * Returns a deep clone of this FieldInfos instance. + * Assumes the fields are not storing term vectors. + * + * @param names The names of the fields + * @param isIndexed Whether the fields are indexed or not + * + * @see #add(TCHAR*, bool) */ - FieldInfos* clone(); + void add(const TCHAR** names, const bool isIndexed, const bool storeTermVector=false, + const bool storePositionWithTermVector=false, const bool storeOffsetWithTermVector=false, + const bool omitNorms=false, const bool storePayloads=false); - // Adds field info for a Document. - void add(const CL_NS(document)::Document* doc); - // Merges in information from another FieldInfos. void add(FieldInfos* other); @@ -156,26 +152,47 @@ */ FieldInfo* add(const TCHAR* name, const bool isIndexed, const bool storeTermVector=false, const bool storePositionWithTermVector=false, const bool storeOffsetWithTermVector=false, const bool omitNorms=false, const bool storePayloads=false); + + // was void + FieldInfo* addInternal( const TCHAR* name,const bool isIndexed, const bool storeTermVector, + const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads); + + int32_t fieldNumber(const TCHAR* fieldName)const; /** - * Assumes the fields are not storing term vectors - * @param names The names of the fields - * @param isIndexed true if the field is indexed - * @param storeTermVector true if the term vector should be stored + * Return the fieldinfo object referenced by the fieldNumber. + * @param fieldNumber + * @return the FieldInfo object or null when the given fieldNumber + * doesn't exist. + */ + FieldInfo* fieldInfo(const TCHAR* fieldName) const; + + /** + * Return the fieldName identified by its number. * - * @see #add(String, boolean) - */ - void add(const TCHAR** names, const bool isIndexed, const bool storeTermVector=false, - const bool storePositionWithTermVector=false, const bool storeOffsetWithTermVector=false, const bool omitNorms=false, const bool storePayloads=false); + * @param fieldNumber + * @return the fieldName or an empty string when the field + * with the given number doesn't exist. + */ + const TCHAR* fieldName(const int32_t fieldNumber)const; + /** + * Return the fieldinfo object referenced by the fieldNumber. + * @param fieldNumber + * @return the FieldInfo object or null when the given fieldNumber + * doesn't exist. + */ + FieldInfo* fieldInfo(const int32_t fieldNumber) const; + + size_t size()const; + bool hasVectors() const; + + void write(CL_NS(store)::Directory* d, const char* name) const; void write(CL_NS(store)::IndexOutput* output) const; private: void read(CL_NS(store)::IndexInput* input); - // was void - FieldInfo* addInternal( const TCHAR* name,const bool isIndexed, const bool storeTermVector, - const bool storePositionWithTermVector, const bool storeOffsetWithTermVector, const bool omitNorms, const bool storePayloads); }; CL_NS_END Modified: branches/lucene2_3_2/src/shared/CLucene/debug/error.h =================================================================== --- branches/lucene2_3_2/src/shared/CLucene/debug/error.h 2008-08-26 11:52:28 UTC (rev 2876) +++ branches/lucene2_3_2/src/shared/CLucene/debug/error.h 2008-08-26 14:15:15 UTC (rev 2877) @@ -21,7 +21,7 @@ #define CL_ERR_TooManyClauses 10 #define CL_ERR_RAMTransaction 11 #define CL_ERR_InvalidCast 12 -#define CL_ERR_IllegalState 13 +#define CL_ERR_IllegalState 13 // Sub-error: AlreadyClosed #define CL_ERR_UnknownOperator 14 #define CL_ERR_ConcurrentModification 15 #define CL_ERR_CorruptIndex 16 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |