1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
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_PhraseQuery_
8
#define _lucene_search_PhraseQuery_
11
CL_CLASS_DEF(index,Term)
12
CL_CLASS_DEF(search,Scorer)
13
#include "CLucene/util/Array.h"
14
#include "CLucene/util/VoidList.h"
17
/** A Query that matches documents containing a particular sequence of terms.
18
* A PhraseQuery is built by QueryParser for input like <code>"new york"</code>.
20
* <p>This query may be combined with other terms or queries with a {@link BooleanQuery}.
22
class CLUCENE_EXPORT PhraseQuery: public Query {
25
CL_NS(util)::CLVector<CL_NS(index)::Term*>* terms;
26
CL_NS(util)::CLVector<int32_t,CL_NS(util)::Deletor::DummyInt32>* positions;
29
friend class PhraseWeight;
31
Weight* _createWeight(Searcher* searcher);
32
PhraseQuery(const PhraseQuery& clone);
34
/** Constructs an empty phrase query. */
36
virtual ~PhraseQuery();
38
/** Sets the number of other words permitted between words in query phrase.
39
If zero, then this is an exact phrase search. For larger values this works
40
like a <code>WITHIN</code> or <code>NEAR</code> operator.
42
<p>The slop is in fact an edit-distance, where the units correspond to
43
moves of terms in the query phrase out of position. For example, to switch
44
the order of two words requires two moves (the first move places the words
45
atop one another), so to permit re-orderings of phrases, the slop must be
48
<p>More exact matches are scored higher than sloppier matches, thus search
49
results are sorted by exactness.
51
<p>The slop is zero by default, requiring exact matches.*/
52
void setSlop(const int32_t s);
54
/** Returns the slop. See setSlop(). */
55
int32_t getSlop() const;
58
* Adds a term to the end of the query phrase.
59
* The relative position of the term is the one immediately after the last term added.
61
void add(CL_NS(index)::Term* term);
64
* Adds a term to the end of the query phrase.
65
* The relative position of the term within the phrase is specified explicitly.
66
* This allows e.g. phrases with more than one term at the same position
67
* or phrases with gaps (e.g. in connection with stopwords).
72
void add(CL_NS(index)::Term* term, int32_t position);
74
/** Returns the set of terms in this phrase. */
75
CL_NS(index)::Term** getTerms() const;
78
* Returns the relative positions of terms in this phrase.
80
void getPositions(CL_NS(util)::ValueArray<int32_t>& result) const;
82
//Returns the sum of squared weights
83
float_t sumOfSquaredWeights(Searcher* searcher);
85
//Normalizes the Weight
86
void normalize(const float_t norm);
88
Scorer* scorer(CL_NS(index)::IndexReader* reader);
90
const TCHAR* getFieldName() const;
92
/** Prints a user-readable version of this query. */
93
TCHAR* toString(const TCHAR* f) const;
96
bool equals(Query *) const;
98
size_t hashCode() const;
100
const char* getObjectName() const;
101
static const char* getClassName();
103
/** Expert: adds all terms occurring in this query to the terms set. */
104
void extractTerms( TermSet * termset ) const;