1 | /*------------------------------------------------------------------------------ |
2 | * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team |
3 | * |
4 | * Distributable under the terms of either the Apache License (Version 2.0) or |
5 | * the GNU Lesser General Public License, as specified in the COPYING file. |
6 | ------------------------------------------------------------------------------*/ |
7 | #ifndef _lucene_search_PrefixQuery |
8 | #define _lucene_search_PrefixQuery |
9 | |
10 | CL_CLASS_DEF(index,Term) |
11 | //#include "CLucene/index/Terms.h" |
12 | //#include "CLucene/index/IndexReader.h" |
13 | //#include "SearchHeader.h" |
14 | //#include "BooleanQuery.h" |
15 | //#include "TermQuery.h" |
16 | #include "Query.h" |
17 | #include "Filter.h" |
18 | CL_CLASS_DEF(util,StringBuffer) |
19 | |
20 | CL_NS_DEF(search) |
21 | /** A Query that matches documents containing terms with a specified prefix. A PrefixQuery |
22 | * is built by QueryParser for input like <code>app*</code>. */ |
23 | class CLUCENE_EXPORT PrefixQuery: public Query { |
24 | private: |
25 | CL_NS(index)::Term* prefix; |
26 | protected: |
27 | PrefixQuery(const PrefixQuery& clone); |
28 | public: |
29 | |
30 | //Constructor. Constructs a query for terms starting with prefix |
31 | PrefixQuery(CL_NS(index)::Term* Prefix); |
32 | |
33 | //Destructor |
34 | ~PrefixQuery(); |
35 | |
36 | //Returns the name "PrefixQuery" |
37 | const char* getObjectName() const; |
38 | static const char* getClassName(); |
39 | |
40 | /** Returns the prefix of this query. */ |
41 | CL_NS(index)::Term* getPrefix(bool pointer=true); |
42 | |
43 | Query* combine(CL_NS(util)::ArrayBase<Query*>* queries); |
44 | Query* rewrite(CL_NS(index)::IndexReader* reader); |
45 | Query* clone() const; |
46 | bool equals(Query * other) const; |
47 | |
48 | //Creates a user-readable version of this query and returns it as as string |
49 | TCHAR* toString(const TCHAR* field) const; |
50 | |
51 | size_t hashCode() const; |
52 | }; |
53 | |
54 | |
55 | class CLUCENE_EXPORT PrefixFilter: public Filter |
56 | { |
57 | private: |
58 | CL_NS(index)::Term* prefix; |
59 | protected: |
60 | PrefixFilter( const PrefixFilter& copy ); |
61 | public: |
62 | class PrefixGenerator; |
63 | |
64 | PrefixFilter(CL_NS(index)::Term* prefix); |
65 | ~PrefixFilter(); |
66 | |
67 | /** Returns a BitSet with true for documents which should be permitted in |
68 | search results, and false for those that should not. */ |
69 | CL_NS(util)::BitSet* bits( CL_NS(index)::IndexReader* reader ); |
70 | |
71 | Filter* clone() const; |
72 | |
73 | /** Prints a user-readable version of this query. */ |
74 | TCHAR* toString(); |
75 | |
76 | // Returns a reference of internal prefix |
77 | CL_NS(index)::Term* getPrefix() const; |
78 | }; |
79 | CL_NS_END |
80 | #endif |
81 | |