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_Sort_ 00008 #define _lucene_search_Sort_ 00009 00010 00011 //#include "CLucene/index/IndexReader.h" 00012 //#include "SearchHeader.h" 00013 //#include "CLucene/util/Equator.h" 00014 CL_CLASS_DEF(index,IndexReader) 00015 CL_CLASS_DEF(util,Comparable) 00016 00017 CL_NS_DEF(search) 00018 00019 class SortField; //predefine 00020 class Sort; 00021 00026 class CLUCENE_EXPORT ScoreDocComparator:LUCENE_BASE { 00027 protected: 00028 ScoreDocComparator(){} 00029 public: 00030 virtual ~ScoreDocComparator(); 00031 // CL_NS(util)::Comparable** cachedValues; 00032 // ScoreDocComparator(CL_NS(util)::Comparable** cachedValues); 00033 00042 virtual int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j) = 0; 00043 00052 virtual CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i) = 0; 00053 00054 00062 virtual int32_t sortType() = 0; 00063 00065 static ScoreDocComparator* RELEVANCE; 00066 00068 static ScoreDocComparator* INDEXORDER; 00069 }; 00070 00075 class CLUCENE_EXPORT SortComparatorSource:LUCENE_BASE { 00076 public: 00077 virtual ~SortComparatorSource(){ 00078 } 00079 00084 virtual TCHAR* getName() = 0; 00085 00086 virtual size_t hashCode() = 0; 00087 00095 virtual ScoreDocComparator* newComparator (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname) = 0; 00096 }; 00097 00098 00112 class CLUCENE_EXPORT SortComparator: public SortComparatorSource { 00113 public: 00114 virtual ScoreDocComparator* newComparator (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname); 00115 00116 SortComparator(); 00117 virtual ~SortComparator(); 00118 00133 virtual CL_NS(util)::Comparable* getComparable (const TCHAR* termtext) = 0; 00134 00135 }; 00136 00137 00143 class CLUCENE_EXPORT SortField:LUCENE_BASE { 00144 private: 00145 const TCHAR* field; 00146 int32_t type; // defaults to determining type dynamically 00147 //Locale* locale; // defaults to "natural order" (no Locale) 00148 bool reverse; // defaults to natural order 00149 SortComparatorSource* factory; 00150 00151 protected: 00152 SortField (const SortField& clone); 00153 public: 00154 virtual ~SortField(); 00155 00161 LUCENE_STATIC_CONSTANT(int32_t, DOCSCORE=0); 00162 00165 LUCENE_STATIC_CONSTANT(int32_t, DOC=1); 00166 00171 LUCENE_STATIC_CONSTANT(int32_t, AUTO=2); 00172 00175 LUCENE_STATIC_CONSTANT(int32_t, STRING=3); 00176 00179 LUCENE_STATIC_CONSTANT(int32_t, INT=4); 00180 00183 LUCENE_STATIC_CONSTANT(int32_t, FLOAT=5); 00184 00187 LUCENE_STATIC_CONSTANT(int32_t, CUSTOM=9); 00188 00189 // IMPLEMENTATION NOTE: the FieldCache.STRING_INDEX is in the same "namespace" 00190 // as the above static int values. Any new values must not have the same value 00191 // as FieldCache.STRING_INDEX. 00192 00194 static SortField* FIELD_SCORE; 00195 00197 static SortField* FIELD_DOC; 00198 00203 SortField (const TCHAR* field); 00204 //SortField (const TCHAR* field, bool reverse); 00205 //todo: we cannot make reverse use default field of =false. 00206 //because bool and int are the same type in c, overloading is not possible 00207 00215 SortField (const TCHAR* field, int32_t type, bool reverse); 00216 00217 /* 00218 SortField (TCHAR* field, Locale* locale) { 00219 SortField (TCHAR* field, Locale* locale, bool reverse);*/ 00220 00226 SortField (const TCHAR* field, SortComparatorSource* comparator, bool reverse=false); 00227 00232 const TCHAR* getField() const { return field; } 00233 00234 SortField* clone() const; 00235 00239 int32_t getType() const { return type; } 00240 00245 /*Locale getLocale() { 00246 return locale; 00247 }*/ 00248 00252 bool getReverse() const { return reverse; } 00253 00254 SortComparatorSource* getFactory() const { return factory; } 00255 00256 TCHAR* toString() const; 00257 }; 00258 00259 00260 00334 class CLUCENE_EXPORT Sort:LUCENE_BASE { 00335 // internal representation of the sort criteria 00336 SortField** fields; 00337 void clear(); 00338 public: 00339 ~Sort(); 00340 00344 static Sort* RELEVANCE; 00345 00347 static Sort* INDEXORDER; 00348 00349 00353 Sort(); 00354 00360 Sort (const TCHAR* field, bool reverse=false); 00361 00367 Sort (const TCHAR** fields); 00368 00370 Sort (SortField* field); 00371 00373 Sort (SortField** fields); 00374 00377 void setSort (const TCHAR* field, bool reverse=false); 00378 00380 void setSort (const TCHAR** fieldnames); 00381 00383 void setSort (SortField* field); 00384 00386 void setSort (SortField** fields); 00387 00388 TCHAR* toString() const; 00389 00394 SortField** getSort() const{ return fields; } 00395 }; 00396 00397 00398 00399 00400 00401 CL_NS_END 00402 #endif