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_FuzzyQuery_ 00008 #define _lucene_search_FuzzyQuery_ 00009 00010 00011 //#include "CLucene/index/IndexReader.h" 00012 CL_CLASS_DEF(index,Term) 00013 //#include "MultiTermQuery.h" 00014 #include "MultiTermQuery.h" 00015 #include "FilteredTermEnum.h" 00016 00017 00018 CL_NS_DEF(search) 00019 00020 // class FuzzyQuery implements the fuzzy search query 00021 class CLUCENE_EXPORT FuzzyQuery: public MultiTermQuery { 00022 private: 00023 float_t minimumSimilarity; 00024 size_t prefixLength; 00025 protected: 00026 FuzzyQuery(const FuzzyQuery& clone); 00027 public: 00028 static float_t defaultMinSimilarity; 00029 static int32_t defaultPrefixLength; 00030 00047 FuzzyQuery(CL_NS(index)::Term* term, float_t minimumSimilarity=defaultMinSimilarity, size_t prefixLength=0); 00048 //Destructor 00049 ~FuzzyQuery(); 00050 00051 TCHAR* toString(const TCHAR* field) const; 00052 00053 //Returns the name "FuzzyQuery" 00054 static const TCHAR* getClassName(); 00055 const TCHAR* getQueryName() const; 00056 00057 Query* clone() const; 00058 bool equals(Query * other) const; 00059 size_t hashCode() const; 00060 00065 float_t getMinSimilarity() const; 00066 00072 size_t getPrefixLength() const; 00073 00074 protected: 00075 FilteredTermEnum* getEnum(CL_NS(index)::IndexReader* reader); 00076 }; 00077 00084 class FuzzyTermEnum: public FilteredTermEnum { 00085 private: 00086 float_t distance; 00087 bool _endEnum; 00088 00089 CL_NS(index)::Term* searchTerm; 00090 TCHAR* text; 00091 size_t textLen; 00092 TCHAR* prefix; 00093 size_t prefixLength; 00094 float_t minimumSimilarity; 00095 double scale_factor; 00096 00097 00102 int32_t* e; 00103 int32_t eWidth; 00104 int32_t eHeight; 00105 00106 /****************************** 00107 * Compute Levenshtein distance 00108 ******************************/ 00109 00119 int32_t editDistance(const TCHAR* s, const TCHAR* t, const int32_t n, const int32_t m) ; 00120 00121 protected: 00126 bool termCompare(CL_NS(index)::Term* term) ; 00127 00129 bool endEnum(); 00130 public: 00131 00140 FuzzyTermEnum(const CL_NS(index)::IndexReader* reader, CL_NS(index)::Term* term, float_t minSimilarity=FuzzyQuery::defaultMinSimilarity, size_t prefixLength=0); 00142 ~FuzzyTermEnum(); 00144 void close(); 00145 00149 float_t difference(); 00150 00151 00152 const char* getObjectName(){ return FuzzyTermEnum::getClassName(); } 00153 static const char* getClassName(){ return "FuzzyTermEnum"; } 00154 }; 00155 CL_NS_END 00156 #endif