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

BooleanScorer.h
Go to the documentation of this file.
1 // 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 BOOLEANSCORER_H
8 #define BOOLEANSCORER_H
9
10 #include "Scorer.h"
11 #include "Collector.h"
12
13 namespace Lucene {
14
30 class BooleanScorer : public Scorer {
31 public:
32 BooleanScorer(const SimilarityPtr& similarity, int32_t minNrShouldMatch, Collection<ScorerPtr> optionalScorers, Collection<ScorerPtr> prohibitedScorers);
33 virtual ~BooleanScorer();
34
35 LUCENE_CLASS(BooleanScorer);
36
37 protected:
38 SubScorerPtr scorers;
39 BucketTablePtr bucketTable;
40 int32_t maxCoord;
41 Collection<double> coordFactors;
42 int32_t requiredMask;
43 int32_t prohibitedMask;
44 int32_t nextMask;
45 int32_t minNrShouldMatch;
46 int32_t end;
47 BucketPtr current;
48 int32_t doc;
49
50 protected:
51 // firstDocID is ignored since nextDoc() initializes 'current'
52 virtual bool score(const CollectorPtr& collector, int32_t max, int32_t firstDocID);
53
54 public:
55 virtual int32_t advance(int32_t target);
56 virtual int32_t docID();
57 virtual int32_t nextDoc();
58 virtual double score();
59 virtual void score(const CollectorPtr& collector);
60 virtual String toString();
61 };
62
63 class BooleanScorerCollector : public Collector {
64 public:
65 BooleanScorerCollector(int32_t mask, const BucketTablePtr& bucketTable);
66 virtual ~BooleanScorerCollector();
67
68 LUCENE_CLASS(BooleanScorerCollector);
69
70 protected:
71 BucketTableWeakPtr _bucketTable;
72 int32_t mask;
73 ScorerWeakPtr _scorer;
74
75 public:
76 virtual void collect(int32_t doc);
77 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
78 virtual void setScorer(const ScorerPtr& scorer);
79 virtual bool acceptsDocsOutOfOrder();
80 };
81
82 // An internal class which is used in score(Collector, int32_t) for setting the current score. This is required
83 // since Collector exposes a setScorer method and implementations that need the score will call scorer->score().
84 // Therefore the only methods that are implemented are score() and doc().
85 class BucketScorer : public Scorer {
86 public:
87 BucketScorer();
88 virtual ~BucketScorer();
89
90 LUCENE_CLASS(BucketScorer);
91
92 public:
93 double _score;
94 int32_t doc;
95
96 public:
97 virtual int32_t advance(int32_t target);
98 virtual int32_t docID();
99 virtual int32_t nextDoc();
100 virtual double score();
101 };
102
103 class Bucket : public LuceneObject {
104 public:
105 Bucket();
106 virtual ~Bucket();
107
108 LUCENE_CLASS(Bucket);
109
110 public:
111 int32_t doc; // tells if bucket is valid
112 double score; // incremental score
113 int32_t bits; // used for bool constraints
114 int32_t coord; // count of terms in score
115 BucketWeakPtr _next; // next valid bucket
116 };
117
119 class BucketTable : public LuceneObject {
120 public:
121 BucketTable();
122 virtual ~BucketTable();
123
124 LUCENE_CLASS(BucketTable);
125
126 public:
127 static const int32_t SIZE;
128 static const int32_t MASK;
129
130 Collection<BucketPtr> buckets;
131 BucketPtr first; // head of valid list
132
133 public:
134 CollectorPtr newCollector(int32_t mask);
135 int32_t size();
136 };
137
138 class SubScorer : public LuceneObject {
139 public:
140 SubScorer(const ScorerPtr& scorer, bool required, bool prohibited, const CollectorPtr& collector, const SubScorerPtr& next);
141 virtual ~SubScorer();
142
143 LUCENE_CLASS(SubScorer);
144
145 public:
146 ScorerPtr scorer;
147 bool required;
148 bool prohibited;
149 CollectorPtr collector;
150 SubScorerPtr next;
151 };
152
153 }
154
155 #endif
Lucene::BooleanScorer::~BooleanScorer
virtual ~BooleanScorer()
Lucene::SubScorer::~SubScorer
virtual ~SubScorer()
Scorer.h
Lucene::BucketScorer::docID
virtual int32_t docID()
Returns the following:
Lucene::SubScorer::scorer
ScorerPtr scorer
Definition: BooleanScorer.h:143
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition: LuceneObject.h:24
Lucene::BooleanScorer::scorers
SubScorerPtr scorers
Definition: BooleanScorer.h:35
Lucene::BooleanScorer::advance
virtual int32_t advance(int32_t target)
Advances to the first beyond the current whose document number is greater than or equal to target....
Lucene::BucketScorer::~BucketScorer
virtual ~BucketScorer()
Lucene::BooleanScorer::coordFactors
Collection< double > coordFactors
Definition: BooleanScorer.h:41
Lucene::Collection< ScorerPtr >
Lucene::Bucket
Definition: BooleanScorer.h:103
Lucene::BucketScorer::nextDoc
virtual int32_t nextDoc()
Advances to the next document in the set and returns the doc it is currently on, or NO_MORE_DOCS if t...
Lucene::ScorerWeakPtr
boost::weak_ptr< Scorer > ScorerWeakPtr
Definition: LuceneTypes.h:429
Lucene::BucketWeakPtr
boost::weak_ptr< Bucket > BucketWeakPtr
Definition: LuceneTypes.h:284
Lucene::BooleanScorer::doc
int32_t doc
Definition: BooleanScorer.h:48
Lucene::BucketScorer::_score
double _score
Definition: BooleanScorer.h:90
Lucene::BooleanScorer::nextDoc
virtual int32_t nextDoc()
Advances to the next document in the set and returns the doc it is currently on, or NO_MORE_DOCS if t...
Lucene::BooleanScorer::current
BucketPtr current
Definition: BooleanScorer.h:47
Lucene::Bucket::~Bucket
virtual ~Bucket()
Lucene::BucketScorer::score
virtual double score()
Returns the score of the current document matching the query. Initially invalid, until {} or #advanc...
Lucene::Bucket::coord
int32_t coord
Definition: BooleanScorer.h:114
Lucene::BucketScorer::BucketScorer
BucketScorer()
Lucene::BooleanScorer
BooleanScorer uses a ~16k array to score windows of docs. So it scores docs 0-16k first,...
Definition: BooleanScorer.h:30
Lucene::BucketTable::SIZE
static const int32_t SIZE
Definition: BooleanScorer.h:124
Lucene::BucketPtr
boost::shared_ptr< Bucket > BucketPtr
Definition: LuceneTypes.h:284
Lucene::BooleanScorerCollector::~BooleanScorerCollector
virtual ~BooleanScorerCollector()
Lucene::SubScorer::required
bool required
Definition: BooleanScorer.h:147
Lucene::BucketTableWeakPtr
boost::weak_ptr< BucketTable > BucketTableWeakPtr
Definition: LuceneTypes.h:286
Lucene::BooleanScorerCollector::acceptsDocsOutOfOrder
virtual bool acceptsDocsOutOfOrder()
Return true if this collector does not require the matching docIDs to be delivered in int sort order ...
Lucene::BucketTable::size
int32_t size()
Lucene
Definition: AbstractAllTermDocs.h:12
Lucene::BooleanScorer::score
virtual double score()
Returns the score of the current document matching the query. Initially invalid, until {} or #advanc...
Lucene::BooleanScorer::docID
virtual int32_t docID()
Returns the following:
Lucene::BooleanScorer::toString
virtual String toString()
Returns a string representation of the object.
Lucene::SubScorer::SubScorer
SubScorer(const ScorerPtr &scorer, bool required, bool prohibited, const CollectorPtr &collector, const SubScorerPtr &next)
Lucene::LuceneObject
Base class for all Lucene classes.
Definition: LuceneObject.h:31
Lucene::BucketScorer
Definition: BooleanScorer.h:85
Lucene::Bucket::Bucket
Bucket()
Lucene::SubScorer
Definition: BooleanScorer.h:138
Lucene::BucketTable::~BucketTable
virtual ~BucketTable()
Lucene::SubScorerPtr
boost::shared_ptr< SubScorer > SubScorerPtr
Definition: LuceneTypes.h:462
Lucene::IndexReaderPtr
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition: LuceneTypes.h:157
Lucene::BooleanScorerCollector::collect
virtual void collect(int32_t doc)
Called once for every document matching a query, with the unbased document number.
Lucene::BucketTable::first
BucketPtr first
Definition: BooleanScorer.h:131
Lucene::BucketTable::newCollector
CollectorPtr newCollector(int32_t mask)
Lucene::Scorer
Common scoring functionality for different types of queries.
Definition: Scorer.h:22
Lucene::SubScorer::next
SubScorerPtr next
Definition: BooleanScorer.h:150
Lucene::CollectorPtr
boost::shared_ptr< Collector > CollectorPtr
Definition: LuceneTypes.h:295
Lucene::Bucket::doc
int32_t doc
Definition: BooleanScorer.h:108
Lucene::ScorerPtr
boost::shared_ptr< Scorer > ScorerPtr
Definition: LuceneTypes.h:429
Lucene::Bucket::bits
int32_t bits
Definition: BooleanScorer.h:113
Lucene::BooleanScorer::requiredMask
int32_t requiredMask
Definition: BooleanScorer.h:42
Lucene::BucketScorer::doc
int32_t doc
Definition: BooleanScorer.h:94
Lucene::Scorer::similarity
SimilarityPtr similarity
Definition: Scorer.h:29
Lucene::Bucket::_next
BucketWeakPtr _next
Definition: BooleanScorer.h:115
Lucene::BucketScorer::advance
virtual int32_t advance(int32_t target)
Advances to the first beyond the current whose document number is greater than or equal to target....
Collector.h
Lucene::BooleanScorer::bucketTable
BucketTablePtr bucketTable
Definition: BooleanScorer.h:39
Lucene::SubScorer::prohibited
bool prohibited
Definition: BooleanScorer.h:148
Lucene::BooleanScorerCollector::mask
int32_t mask
Definition: BooleanScorer.h:72
Lucene::SubScorer::collector
CollectorPtr collector
Definition: BooleanScorer.h:149
Lucene::BooleanScorerCollector::BooleanScorerCollector
BooleanScorerCollector(int32_t mask, const BucketTablePtr &bucketTable)
Lucene::BooleanScorer::BooleanScorer
BooleanScorer(const SimilarityPtr &similarity, int32_t minNrShouldMatch, Collection< ScorerPtr > optionalScorers, Collection< ScorerPtr > prohibitedScorers)
Lucene::BucketTable::MASK
static const int32_t MASK
Definition: BooleanScorer.h:128
Lucene::BooleanScorerCollector::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Called before collecting from each IndexReader. All doc ids in collect(int32_t) will correspond to re...
Lucene::BooleanScorer::nextMask
int32_t nextMask
Definition: BooleanScorer.h:44
Lucene::SimilarityPtr
boost::shared_ptr< Similarity > SimilarityPtr
Definition: LuceneTypes.h:435
Lucene::BooleanScorer::prohibitedMask
int32_t prohibitedMask
Definition: BooleanScorer.h:43
Lucene::BooleanScorerCollector
Definition: BooleanScorer.h:63
Lucene::BooleanScorer::minNrShouldMatch
int32_t minNrShouldMatch
Definition: BooleanScorer.h:45
Lucene::Bucket::score
double score
Definition: BooleanScorer.h:112
Lucene::BucketTable::buckets
Collection< BucketPtr > buckets
Definition: BooleanScorer.h:130
Lucene::BooleanScorer::maxCoord
int32_t maxCoord
Definition: BooleanScorer.h:40
Lucene::BucketTable::BucketTable
BucketTable()
Lucene::BucketTable
A simple hash table of document scores within a range.
Definition: BooleanScorer.h:119
Lucene::BooleanScorerCollector::_bucketTable
BucketTableWeakPtr _bucketTable
Definition: BooleanScorer.h:68
Lucene::BooleanScorerCollector::setScorer
virtual void setScorer(const ScorerPtr &scorer)
Called before successive calls to collect(int32_t). Implementations that need the score of the curren...
Lucene::BucketTablePtr
boost::shared_ptr< BucketTable > BucketTablePtr
Definition: LuceneTypes.h:286
Lucene::BooleanScorer::end
int32_t end
Definition: BooleanScorer.h:46
Lucene::BooleanScorerCollector::_scorer
ScorerWeakPtr _scorer
Definition: BooleanScorer.h:73
Lucene::Collector
Collectors are primarily meant to be used to gather raw results from a search, and implement sorting ...
Definition: Collector.h:100

clucene.sourceforge.net