Lucene++ - a full-featured, c++ search engine
API Documentation

Loading...
Searching...
No Matches
MultiTermQuery.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef MULTITERMQUERY_H
8#define MULTITERMQUERY_H
9
10#include "Query.h"
11
12 namespace Lucene {
13
31 class LPPAPI MultiTermQuery : public Query {
32 public:
33 MultiTermQuery();
34 virtual ~MultiTermQuery();
35
36 LUCENE_CLASS(MultiTermQuery);
37
38 protected:
39 RewriteMethodPtr rewriteMethod;
40 int32_t numberOfTerms;
41
42 public:
50 static RewriteMethodPtr CONSTANT_SCORE_FILTER_REWRITE();
51
61 static RewriteMethodPtr SCORING_BOOLEAN_QUERY_REWRITE();
62
70 static RewriteMethodPtr CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE();
71
77 static RewriteMethodPtr CONSTANT_SCORE_AUTO_REWRITE_DEFAULT();
78
91 int32_t getTotalNumberOfTerms();
92
95 void clearTotalNumberOfTerms();
96
97 virtual QueryPtr rewrite(const IndexReaderPtr& reader);
98
100 virtual RewriteMethodPtr getRewriteMethod();
101
104 virtual void setRewriteMethod(const RewriteMethodPtr& method);
105
106 virtual LuceneObjectPtr clone(const LuceneObjectPtr& other = LuceneObjectPtr());
107 virtual int32_t hashCode();
108 virtual bool equals(const LuceneObjectPtr& other);
109
110 protected:
112 virtual FilteredTermEnumPtr getEnum(const IndexReaderPtr& reader) = 0;
113
114 void incTotalNumberOfTerms(int32_t inc);
115
116 friend class MultiTermQueryWrapperFilter;
117 friend class ScoringBooleanQueryRewrite;
118 friend class ConstantScoreAutoRewrite;
119};
120
122 class LPPAPI RewriteMethod : public LuceneObject {
123 public:
124 virtual ~RewriteMethod();
125 LUCENE_CLASS(RewriteMethod);
126
127 public:
128 virtual QueryPtr rewrite(const IndexReaderPtr& reader, const MultiTermQueryPtr& query) = 0;
129};
130
135 class LPPAPI ConstantScoreAutoRewrite : public RewriteMethod {
136 public:
137 ConstantScoreAutoRewrite();
138 virtual ~ConstantScoreAutoRewrite();
139
140 LUCENE_CLASS(ConstantScoreAutoRewrite);
141
142 public:
143 // Defaults derived from rough tests with a 20.0 million doc Wikipedia index. With more than 350 terms
144 // in the query, the filter method is fastest
145 static const int32_t DEFAULT_TERM_COUNT_CUTOFF;
146
147 // If the query will hit more than 1 in 1000 of the docs in the index (0.1%), the filter method is fastest
148 static const double DEFAULT_DOC_COUNT_PERCENT;
149
150 protected:
151 int32_t termCountCutoff;
152 double docCountPercent;
153
154 public:
157 virtual void setTermCountCutoff(int32_t count);
158
160 virtual int32_t getTermCountCutoff();
161
165 virtual void setDocCountPercent(double percent);
166
168 virtual double getDocCountPercent();
169
170 virtual QueryPtr rewrite(const IndexReaderPtr& reader, const MultiTermQueryPtr& query);
171
172 virtual int32_t hashCode();
173 virtual bool equals(const LuceneObjectPtr& other);
174};
175
176}
177
178#endif
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Query.h
Lucene::ConstantScoreAutoRewrite::DEFAULT_TERM_COUNT_CUTOFF
static const int32_t DEFAULT_TERM_COUNT_CUTOFF
Definition MultiTermQuery.h:145
Lucene::ConstantScoreAutoRewrite::~ConstantScoreAutoRewrite
virtual ~ConstantScoreAutoRewrite()
Lucene::ConstantScoreAutoRewrite::getDocCountPercent
virtual double getDocCountPercent()
Lucene::ConstantScoreAutoRewrite::docCountPercent
double docCountPercent
Definition MultiTermQuery.h:152
Lucene::ConstantScoreAutoRewrite::termCountCutoff
int32_t termCountCutoff
Definition MultiTermQuery.h:151
Lucene::ConstantScoreAutoRewrite::equals
virtual bool equals(const LuceneObjectPtr &other)
Return whether two objects are equal.
Lucene::ConstantScoreAutoRewrite::setTermCountCutoff
virtual void setTermCountCutoff(int32_t count)
If the number of terms in this query is equal to or larger than this setting then CONSTANT_SCORE_FILT...
Lucene::ConstantScoreAutoRewrite::rewrite
virtual QueryPtr rewrite(const IndexReaderPtr &reader, const MultiTermQueryPtr &query)
Lucene::ConstantScoreAutoRewrite::setDocCountPercent
virtual void setDocCountPercent(double percent)
If the number of documents to be visited in the postings exceeds this specified percentage of the max...
Lucene::ConstantScoreAutoRewrite::DEFAULT_DOC_COUNT_PERCENT
static const double DEFAULT_DOC_COUNT_PERCENT
Definition MultiTermQuery.h:148
Lucene::ConstantScoreAutoRewrite::ConstantScoreAutoRewrite
ConstantScoreAutoRewrite()
Lucene::ConstantScoreAutoRewrite::hashCode
virtual int32_t hashCode()
Return hash code for this object.
Lucene::ConstantScoreAutoRewrite::getTermCountCutoff
virtual int32_t getTermCountCutoff()
Lucene::LuceneObject::LuceneObject
LuceneObject()
Lucene::MultiTermQuery::clearTotalNumberOfTerms
void clearTotalNumberOfTerms()
Resets the counting of unique terms. Do this before executing the query/filter.
Lucene::MultiTermQuery::~MultiTermQuery
virtual ~MultiTermQuery()
Lucene::MultiTermQuery::CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
static RewriteMethodPtr CONSTANT_SCORE_AUTO_REWRITE_DEFAULT()
Read-only default instance of ConstantScoreAutoRewrite, with ConstantScoreAutoRewrite#setTermCountCut...
Lucene::MultiTermQuery::rewriteMethod
RewriteMethodPtr rewriteMethod
Definition MultiTermQuery.h:39
Lucene::MultiTermQuery::hashCode
virtual int32_t hashCode()
Return hash code for this object.
Lucene::MultiTermQuery::ScoringBooleanQueryRewrite
friend class ScoringBooleanQueryRewrite
Definition MultiTermQuery.h:117
Lucene::MultiTermQuery::numberOfTerms
int32_t numberOfTerms
Definition MultiTermQuery.h:40
Lucene::MultiTermQuery::CONSTANT_SCORE_FILTER_REWRITE
static RewriteMethodPtr CONSTANT_SCORE_FILTER_REWRITE()
A rewrite method that first creates a private Filter, by visiting each term in sequence and marking a...
Lucene::MultiTermQuery::rewrite
virtual QueryPtr rewrite(const IndexReaderPtr &reader)
Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into ...
Lucene::MultiTermQuery::clone
virtual LuceneObjectPtr clone(const LuceneObjectPtr &other=LuceneObjectPtr())
Returns a clone of this query.
Lucene::MultiTermQuery::equals
virtual bool equals(const LuceneObjectPtr &other)
Return whether two objects are equal.
Lucene::MultiTermQuery::SCORING_BOOLEAN_QUERY_REWRITE
static RewriteMethodPtr SCORING_BOOLEAN_QUERY_REWRITE()
A rewrite method that first translates each term into BooleanClause.Occur#SHOULD clause in a BooleanQ...
Lucene::MultiTermQuery::getTotalNumberOfTerms
int32_t getTotalNumberOfTerms()
Return the number of unique terms visited during execution of the query. If there are many of them,...
Lucene::MultiTermQuery::incTotalNumberOfTerms
void incTotalNumberOfTerms(int32_t inc)
Lucene::MultiTermQuery::CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE
static RewriteMethodPtr CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE()
Like SCORING_BOOLEAN_QUERY_REWRITE except scores are not computed. Instead, each matching document re...
Lucene::MultiTermQuery::ConstantScoreAutoRewrite
friend class ConstantScoreAutoRewrite
Definition MultiTermQuery.h:118
Lucene::MultiTermQuery::MultiTermQuery
MultiTermQuery()
Lucene::MultiTermQuery::getRewriteMethod
virtual RewriteMethodPtr getRewriteMethod()
Lucene::MultiTermQuery::getEnum
virtual FilteredTermEnumPtr getEnum(const IndexReaderPtr &reader)=0
Construct the enumeration to be used, expanding the pattern term.
Lucene::MultiTermQuery::MultiTermQueryWrapperFilter
friend class MultiTermQueryWrapperFilter
Definition MultiTermQuery.h:116
Lucene::MultiTermQuery::setRewriteMethod
virtual void setRewriteMethod(const RewriteMethodPtr &method)
Sets the rewrite method to be used when executing the query. You can use one of the four core methods...
Lucene::Query::Query
Query()
Lucene::RewriteMethod
Abstract class that defines how the query is rewritten.
Definition MultiTermQuery.h:122
Lucene::RewriteMethod::rewrite
virtual QueryPtr rewrite(const IndexReaderPtr &reader, const MultiTermQueryPtr &query)=0
Lucene::RewriteMethod::~RewriteMethod
virtual ~RewriteMethod()
Lucene
Definition AbstractAllTermDocs.h:12
Lucene::QueryPtr
boost::shared_ptr< Query > QueryPtr
Definition LuceneTypes.h:420
Lucene::MultiTermQueryPtr
boost::shared_ptr< MultiTermQuery > MultiTermQueryPtr
Definition LuceneTypes.h:389
Lucene::LuceneObjectPtr
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition LuceneTypes.h:539
Lucene::RewriteMethodPtr
boost::shared_ptr< RewriteMethod > RewriteMethodPtr
Definition LuceneTypes.h:425
Lucene::FilteredTermEnumPtr
boost::shared_ptr< FilteredTermEnum > FilteredTermEnumPtr
Definition LuceneTypes.h:365
Lucene::IndexReaderPtr
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157

clucene.sourceforge.net