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_PhraseQuery_ 00008 #define _lucene_search_PhraseQuery_ 00009 00010 00011 //#include "SearchHeader.h" 00012 //#include "Scorer.h" 00013 //#include "BooleanQuery.h" 00014 //#include "TermQuery.h" 00015 #include "Query.h" 00016 CL_CLASS_DEF(index,Term) 00017 CL_CLASS_DEF(search,Scorer) 00018 //#include "CLucene/index/Terms.h" 00019 //#include "CLucene/index/IndexReader.h" 00020 CL_CLASS_DEF(util,StringBuffer) 00021 //#include "CLucene/util/VoidList.h" 00022 #include "CLucene/util/VoidMapSetDefinitions.h" 00023 #include "CLucene/util/Array.h" 00024 //#include "ExactPhraseScorer.h" 00025 //#include "SloppyPhraseScorer.h" 00026 00027 CL_NS_DEF(search) 00028 // A Query that matches documents containing a particular sequence of terms. 00029 // This may be combined with other terms with a {@link BooleanQuery}. 00030 class CLUCENE_EXPORT PhraseQuery: public Query { 00031 private: 00032 CL_NS(util)::CLVector<int32_t,CL_NS(util)::Deletor::DummyInt32>* positions; 00033 int32_t slop; 00034 00035 const TCHAR* field; 00036 CL_NS(util)::CLVector<CL_NS(index)::Term*>* terms; 00037 00038 friend class PhraseWeight; 00039 protected: 00040 Weight* _createWeight(Searcher* searcher); 00041 PhraseQuery(const PhraseQuery& clone); 00042 public: 00043 //Constructor 00044 PhraseQuery(); 00045 00046 //Destructor 00047 ~PhraseQuery(); 00048 00049 //Returns the string "PhraseQuery" 00050 const TCHAR* getQueryName() const; 00051 static const TCHAR* getClassName(); 00052 00053 //Sets the number of other words permitted between words in query phrase. 00054 //If zero, then this is an exact phrase search. For larger values this works 00055 //like a WITHIN or NEAR operator. 00056 // 00057 //The slop is in fact an edit-distance, where the units correspond to 00058 //moves of terms in the query phrase out of position. For example, to switch 00059 //the order of two words requires two moves (the first move places the words 00060 //atop one another), so to permit re-orderings of phrases, the slop must be 00061 //at least two. 00062 // 00063 //More exact matches are scored higher than sloppier matches, thus search 00064 //results are sorted by exactness. 00065 // 00066 //The slop is zero by default, requiring exact matches. 00067 void setSlop(const int32_t s) { slop = s; } 00068 00069 //Returns the slop. See setSlop(). 00070 int32_t getSlop() const { return slop; } 00071 00072 //Adds a term to the end of the query phrase. 00073 void add(CL_NS(index)::Term* term); 00074 void add(CL_NS(index)::Term* term, int32_t position); 00075 00076 00077 00078 //Returns the sum of squared weights 00079 float_t sumOfSquaredWeights(Searcher* searcher); 00080 00081 //Normalizes the Weight 00082 void normalize(const float_t norm); 00083 00084 Scorer* scorer(CL_NS(index)::IndexReader* reader); 00085 00086 //added by search highlighter 00087 CL_NS(index)::Term** getTerms() const; 00088 _CL_DEPRECATED( deleteDocuments ) int32_t* getPositions() const; 00089 void getPositions(CL_NS(util)::Array<int32_t>& result) const; 00090 const TCHAR* getFieldName() const{ return field; } 00091 00092 //Prints a user-readable version of this query. 00093 TCHAR* toString(const TCHAR* f) const; 00094 00095 Query* clone() const; 00096 bool equals(CL_NS(search)::Query *) const; 00097 00098 size_t hashCode() const; 00099 }; 00100 CL_NS_END 00101 #endif