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_BooleanQuery_ 00008 #define _lucene_search_BooleanQuery_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "ConjunctionScorer.h" 00015 #include "CLucene/index/IndexReader.h" 00016 #include "CLucene/util/StringBuffer.h" 00017 #include "SearchHeader.h" 00018 #include "BooleanClause.h" 00019 #include "BooleanScorer.h" 00020 #include "Scorer.h" 00021 00022 CL_NS_DEF(search) 00023 00024 00025 // A Query that matches documents matching boolean combinations of other 00026 // queries, typically {@link TermQuery}s or {@link PhraseQuery}s. 00027 class BooleanQuery:public Query { 00028 public: 00029 typedef CL_NS(util)::CLVector<BooleanClause*,CL_NS(util)::Deletor::Object<BooleanClause> > ClausesType; 00030 private: 00031 BooleanQuery::ClausesType clauses; 00032 static size_t maxClauseCount; 00033 00034 class BooleanWeight: public Weight { 00035 private: 00036 Searcher* searcher; 00037 CL_NS(util)::CLVector<Weight*,CL_NS(util)::Deletor::Object<Weight> > weights; 00038 ClausesType* clauses; 00039 BooleanQuery* parentQuery; 00040 public: 00041 BooleanWeight(Searcher* searcher, 00042 CL_NS(util)::CLVector<BooleanClause*,CL_NS(util)::Deletor::Object<BooleanClause> >* clauses, 00043 BooleanQuery* parentQuery); 00044 ~BooleanWeight(); 00045 Query* getQuery(); 00046 float_t getValue(); 00047 float_t sumOfSquaredWeights(); 00048 void normalize(float_t norm); 00049 Scorer* scorer(CL_NS(index)::IndexReader* reader); 00050 void explain(CL_NS(index)::IndexReader* reader, int32_t doc, Explanation* ret); 00051 };//booleanweight 00052 00053 protected: 00054 Weight* _createWeight(Searcher* searcher) { 00055 return _CLNEW BooleanWeight(searcher,&clauses,this); 00056 } 00057 BooleanQuery(const BooleanQuery& clone); 00058 public: 00060 BooleanQuery(); 00061 00062 ~BooleanQuery(); 00063 00064 const TCHAR* getQueryName() const; 00065 static const TCHAR* getClassName(); 00066 00070 static size_t getMaxClauseCount(); 00071 00073 static void setMaxClauseCount(size_t maxClauseCount); 00074 00090 void add(Query* query, const bool required, const bool prohibited){ 00091 add(query,false,required,prohibited); 00092 } 00093 void add(Query* query, const bool deleteQuery, const bool required, const bool prohibited); 00094 00099 void getClauses(BooleanClause** clauses) const; 00100 00102 _CL_DEPRECATED( getClauses(clauses) ) BooleanClause** getClauses() const; 00103 00108 size_t getClauseCount() const; 00109 00113 void add(BooleanClause* clause); 00114 00115 Query* rewrite(CL_NS(index)::IndexReader* reader); 00116 Query* clone() const; 00117 bool equals(Query* o) const; 00118 00120 TCHAR* toString(const TCHAR* field) const; 00122 size_t hashCode() const; 00123 }; 00124 00125 CL_NS_END 00126 #endif