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_ChainedFilter_ 00008 #define _lucene_search_ChainedFilter_ 00009 00010 //#include "CLucene/index/IndexReader.h" 00011 //#include "CLucene/util/BitSet.h" 00012 #include "Filter.h" 00013 00014 CL_NS_DEF(search) 00015 00016 /* 00017 Discussion - brian@unixpoet.com 00018 00019 From ChainedFilter.java: 00020 00021 ... 00022 00023 // First AND operation takes place against a completely false 00024 // bitset and will always return zero results. Thanks to 00025 // Daniel Armbrust for pointing this out and suggesting workaround. 00026 00027 if (logic[0] == AND) 00028 { 00029 result = (BitSet) chain[i].bits(reader).clone(); 00030 ++i; 00031 } 00032 00033 ... 00034 00035 The observation is correct and it was buggy. The problem is that the same 00036 issue remains for the ANDNOT logic op but with the inverse result: all bits 00037 set to 1. The result of the other ops, i.e. OR, AND, XOR for the first filter 00038 ends up just copying the bitset of the first filter (explicitly in the case of the AND). 00039 00040 Why not do the same for the NAND? This will have the side effect of rendering the first op 00041 in the logic array superflous - not a big problem. 00042 00043 The only "problem" is that we will return different results then the Java 00044 Lucene code - though I prefer CLucene to be a correct implementation and only maintain 00045 API compat rather than full 100% compat with Lucene. 00046 */ 00047 class CLUCENE_EXPORT ChainedFilter: public Filter 00048 { 00049 public: 00050 LUCENE_STATIC_CONSTANT(int, OR = 0); //set current bit if the chain is set OR if the filter bit is set 00051 LUCENE_STATIC_CONSTANT(int, AND = 1); //set current bit if the chain is set AND the filter bit is set 00052 LUCENE_STATIC_CONSTANT(int, ANDNOT = 2); //set current bit if the chain is not set AND the filter bit is not set 00053 LUCENE_STATIC_CONSTANT(int, XOR = 3); //set current bit if the chain is set OR the filter bit is set BUT not both is set 00054 00055 LUCENE_STATIC_CONSTANT(int, USER = 5); //add this value to user defined value, then override doUserChain 00056 00057 LUCENE_STATIC_CONSTANT(int, DEFAULT = OR); 00058 00059 protected: 00060 Filter **filters; 00061 int *logicArray; 00062 int logic; 00063 00064 ChainedFilter( const ChainedFilter& copy ); 00065 CL_NS(util)::BitSet* bits( CL_NS(index)::IndexReader* reader, int logic ); 00066 CL_NS(util)::BitSet* bits( CL_NS(index)::IndexReader* reader, int* logicArray ); 00067 CL_NS(util)::BitSet* doChain( CL_NS(util)::BitSet* result, CL_NS(index)::IndexReader* reader, int logic, Filter* filter ); 00068 00069 virtual void doUserChain( CL_NS(util)::BitSet* chain, CL_NS(util)::BitSet* filter, int logic ); 00070 virtual const TCHAR* getLogicString(int logic); 00071 public: 00072 ChainedFilter( Filter** filters, int op = DEFAULT ); 00073 ChainedFilter( Filter** filters, int* _array ); 00074 virtual ~ChainedFilter(); 00075 00078 CL_NS(util)::BitSet* bits( CL_NS(index)::IndexReader* reader ); 00079 00080 virtual Filter* clone() const; 00081 00082 TCHAR* toString(); 00083 }; 00084 00085 CL_NS_END 00086 #endif