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_BooleanClause_ 00008 #define _lucene_search_BooleanClause_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 #include "SearchHeader.h" 00014 00015 CL_NS_DEF(search) 00016 // A clause in a BooleanQuery. 00017 class BooleanClause:LUCENE_BASE { 00018 public: 00019 class Compare:public CL_NS_STD(binary_function)<const BooleanClause*,const BooleanClause*,bool> 00020 { 00021 public: 00022 bool operator()( const BooleanClause* val1, const BooleanClause* val2 ) const{ 00023 return val1->equals(val2); 00024 } 00025 }; 00026 00027 // The query whose matching documents are combined by the boolean query. 00028 Query* query; 00029 00030 int32_t getClauseCount(); 00031 00032 // If true, documents documents which <i>do not</i> 00033 // match this sub-query will <i>not</i> match the boolean query. 00034 bool required; 00035 00036 // If true, documents documents which <i>do</i> 00037 // match this sub-query will <i>not</i> match the boolean query. 00038 bool prohibited; 00039 00040 bool deleteQuery; 00041 00042 // Constructs a BooleanClause with query <code>q</code>, required 00043 // <code>r</code> and prohibited <code>p</code>. 00044 BooleanClause(Query* q, const bool DeleteQuery,const bool req, const bool p): 00045 query(q), 00046 required(req), 00047 prohibited(p), 00048 deleteQuery(DeleteQuery) 00049 { 00050 } 00051 00052 BooleanClause(const BooleanClause& clone): 00053 #if defined(LUCENE_ENABLE_MEMLEAKTRACKING) 00054 #elif defined(LUCENE_ENABLE_REFCOUNT) 00055 #else 00056 LuceneVoidBase(), 00057 #endif 00058 query(clone.query->clone()), 00059 required(clone.required), 00060 prohibited(clone.prohibited), 00061 deleteQuery(true) 00062 { 00063 } 00064 00065 BooleanClause* clone() const{ 00066 BooleanClause* ret = _CLNEW BooleanClause(*this); 00067 return ret; 00068 } 00069 00070 ~BooleanClause(){ 00071 if ( deleteQuery ) 00072 _CLDELETE( query ); 00073 } 00074 00076 bool equals(const BooleanClause* other) const { 00077 return this->query->equals(other->query) 00078 && (this->required == other->required) 00079 && (this->prohibited == other->prohibited); 00080 } 00081 00082 size_t hashCode() const{ 00083 return query->hashCode() ^ (this->required?1:0) ^ (this->prohibited?2:0); 00084 } 00085 }; 00086 00087 00088 CL_NS_END 00089 #endif 00090