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


Loading...
Searching...
No Matches
CustomScoreQuery.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 CUSTOMSCOREQUERY_H
8#define CUSTOMSCOREQUERY_H
9
10#include "Query.h"
11
12namespace Lucene {
13
21class LPPAPI CustomScoreQuery : public Query {
22public:
25 CustomScoreQuery(const QueryPtr& subQuery);
26
32 CustomScoreQuery(const QueryPtr& subQuery, const ValueSourceQueryPtr& valSrcQuery);
33
40
42
44
45protected:
47 Collection<ValueSourceQueryPtr> valSrcQueries; // never null (empty array if there are no valSrcQueries).
48 bool strict; // if true, valueSource part of query does not take part in weights normalization.
49
50public:
51 using Query::toString;
52
53 virtual QueryPtr rewrite(const IndexReaderPtr& reader);
54 virtual void extractTerms(SetTerm terms);
56 virtual String toString(const String& field);
57 virtual bool equals(const LuceneObjectPtr& other);
58 virtual int32_t hashCode();
59
68 virtual double customScore(int32_t doc, double subQueryScore, Collection<double> valSrcScores);
69
78 virtual double customScore(int32_t doc, double subQueryScore, double valSrcScore);
79
88 virtual ExplanationPtr customExplain(int32_t doc, const ExplanationPtr& subQueryExpl, Collection<ExplanationPtr> valSrcExpls);
89
98 virtual ExplanationPtr customExplain(int32_t doc, const ExplanationPtr& subQueryExpl, const ExplanationPtr& valSrcExpl);
99
100 virtual WeightPtr createWeight(const SearcherPtr& searcher);
101
108 virtual bool isStrict();
109
113 virtual void setStrict(bool strict);
114
116 virtual String name();
117
118protected:
119 void ConstructQuery(const QueryPtr& subQuery, Collection<ValueSourceQueryPtr> valSrcQueries);
120
125
126 friend class CustomWeight;
127 friend class CustomScorer;
128};
129
130}
131
132#endif
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
Query that sets document score as a programmatic function of several (sub) scores:
Definition CustomScoreQuery.h:21
virtual bool isStrict()
Checks if this is strict custom scoring. In strict custom scoring, the ValueSource part does not part...
CustomScoreQuery(const QueryPtr &subQuery, const ValueSourceQueryPtr &valSrcQuery)
Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.
virtual ExplanationPtr customExplain(int32_t doc, const ExplanationPtr &subQueryExpl, Collection< ExplanationPtr > valSrcExpls)
Explain the custom score.
virtual QueryPtr rewrite(const IndexReaderPtr &reader)
Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into ...
void ConstructQuery(const QueryPtr &subQuery, Collection< ValueSourceQueryPtr > valSrcQueries)
virtual String name()
A short name of this query, used in toString(String).
virtual bool equals(const LuceneObjectPtr &other)
Return whether two objects are equal.
virtual ExplanationPtr customExplain(int32_t doc, const ExplanationPtr &subQueryExpl, const ExplanationPtr &valSrcExpl)
Explain the custom score.
virtual void setStrict(bool strict)
Set the strict mode of this query.
virtual void extractTerms(SetTerm terms)
Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten...
virtual String toString(const String &field)
Prints a query to a string, with field assumed to be the default field and omitted.
QueryPtr subQuery
Definition CustomScoreQuery.h:46
virtual double customScore(int32_t doc, double subQueryScore, double valSrcScore)
Compute a custom score by the subQuery score and the ValueSourceQuery score.
virtual WeightPtr createWeight(const SearcherPtr &searcher)
Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries...
bool strict
Definition CustomScoreQuery.h:48
Collection< ValueSourceQueryPtr > valSrcQueries
Definition CustomScoreQuery.h:47
virtual LuceneObjectPtr clone(const LuceneObjectPtr &other=LuceneObjectPtr())
Returns a clone of this query.
CustomScoreQuery(const QueryPtr &subQuery)
Create a CustomScoreQuery over input subQuery.
virtual double customScore(int32_t doc, double subQueryScore, Collection< double > valSrcScores)
Compute a custom score by the subQuery score and a number of ValueSourceQuery scores.
virtual int32_t hashCode()
Return hash code for this object.
CustomScoreQuery(const QueryPtr &subQuery, Collection< ValueSourceQueryPtr > valSrcQueries)
Create a CustomScoreQuery over input subQuery and a ValueSourceQuery.
virtual CustomScoreProviderPtr getCustomScoreProvider(const IndexReaderPtr &reader)
Returns a CustomScoreProvider that calculates the custom scores for the given IndexReader....
The abstract base class for queries.
Definition Query.h:31
Definition AbstractAllTermDocs.h:12
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition LuceneTypes.h:539
boost::shared_ptr< CustomScoreProvider > CustomScoreProviderPtr
Definition LuceneTypes.h:309
boost::shared_ptr< Query > QueryPtr
Definition LuceneTypes.h:420
boost::shared_ptr< ValueSourceQuery > ValueSourceQueryPtr
Definition LuceneTypes.h:477
boost::shared_ptr< Searcher > SearcherPtr
Definition LuceneTypes.h:434
boost::shared_ptr< Explanation > ExplanationPtr
Definition LuceneTypes.h:333
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157
boost::shared_ptr< Weight > WeightPtr
Definition LuceneTypes.h:480

clucene.sourceforge.net