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_BooleanScorer_ 00008 #define _lucene_search_BooleanScorer_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "Scorer.h" 00015 00016 CL_NS_DEF(search) 00017 00018 class BooleanScorer: public Scorer { 00019 private: 00020 00021 class Bucket: LUCENE_BASE { 00022 public: 00023 int32_t doc; // tells if bucket is valid 00024 float_t score; // incremental score 00025 int32_t bits; // used for bool constraints 00026 int32_t coord; // count of terms in score 00027 Bucket* next; // next valid bucket 00028 00029 Bucket(); 00030 ~Bucket(); 00031 }; 00032 00033 class SubScorer: LUCENE_BASE { 00034 public: 00035 bool done; 00036 Scorer* scorer; 00037 bool required; 00038 bool prohibited; 00039 HitCollector* collector; 00040 SubScorer* next; 00041 SubScorer(Scorer* scr, const bool r, const bool p, HitCollector* c, SubScorer* nxt); 00042 ~SubScorer(); 00043 }; 00044 00045 class BucketTable:LUCENE_BASE { 00046 private: 00047 BooleanScorer* scorer; 00048 public: 00049 Bucket* buckets; 00050 Bucket* first; // head of valid list 00051 00052 BucketTable(BooleanScorer* scr); 00053 int32_t size() const; 00054 HitCollector* newCollector(const int32_t mask); 00055 void clear(); 00056 ~BucketTable(); 00057 00058 }; 00059 00060 class Collector: public HitCollector { 00061 private: 00062 BucketTable* bucketTable; 00063 int32_t mask; 00064 public: 00065 Collector(const int32_t mask, BucketTable* bucketTable); 00066 00067 void collect(const int32_t doc, const float_t score); 00068 }; 00069 00070 SubScorer* scorers; 00071 BucketTable* bucketTable; 00072 00073 int32_t maxCoord; 00074 int32_t nextMask; 00075 00076 int32_t end; 00077 Bucket* current; 00078 public: 00079 LUCENE_STATIC_CONSTANT(int32_t,BucketTable_SIZE=1024); 00080 int32_t requiredMask; 00081 int32_t prohibitedMask; 00082 float_t* coordFactors; 00083 00084 BooleanScorer(Similarity* similarity); 00085 ~BooleanScorer(); 00086 void add(Scorer* scorer, const bool required, const bool prohibited); 00087 int32_t doc() const { return current->doc; } 00088 bool next(); 00089 float_t score(); 00090 bool skipTo(int32_t target); 00091 void explain(int32_t doc, Explanation* ret); 00092 TCHAR* toString(); 00093 void computeCoordFactors(); 00094 }; 00095 00096 00097 00098 00099 00100 00101 00102 CL_NS_END 00103 #endif