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

Loading...
Searching...
No Matches
BooleanScorer.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 BOOLEANSCORER_H
8#define BOOLEANSCORER_H
9
10#include "Scorer.h"
11#include "Collector.h"
12
13 namespace Lucene {
14
30 class LPPAPI 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
38 protected:
39 SubScorerPtr scorers;
40 BucketTablePtr bucketTable;
41 int32_t maxCoord;
42 Collection<double> coordFactors;
43 int32_t requiredMask;
44 int32_t prohibitedMask;
45 int32_t nextMask;
46 int32_t minNrShouldMatch;
47 int32_t end;
48 BucketPtr current;
49 Bucket* __current = nullptr;
50 int32_t doc;
51
52 protected:
53 // firstDocID is ignored since nextDoc() initializes 'current'
54 virtual bool score(const CollectorPtr& collector, int32_t max, int32_t firstDocID);
55
56 public:
57 virtual int32_t advance(int32_t target);
58 virtual int32_t docID();
59 virtual int32_t nextDoc();
60 virtual double score();
61 virtual void score(const CollectorPtr& collector);
62 virtual String toString();
63
64};
65
66 class BooleanScorerCollector : public Collector {
67 public:
68 BooleanScorerCollector(int32_t mask, const BucketTablePtr& bucketTable);
69 virtual ~BooleanScorerCollector();
70
71 LUCENE_CLASS(BooleanScorerCollector);
72
73 protected:
74 BucketTableWeakPtr _bucketTable;
75 BucketTable* __bucketTable = nullptr;
76 int32_t mask;
77 ScorerWeakPtr _scorer;
78 Scorer* __scorer = nullptr;
79
80 public:
81 virtual void collect(int32_t doc);
82 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
83 virtual void setScorer(const ScorerPtr& scorer);
84 virtual bool acceptsDocsOutOfOrder();
85};
86
87// An internal class which is used in score(Collector, int32_t) for setting the current score. This is required
88// since Collector exposes a setScorer method and implementations that need the score will call scorer->score().
89// Therefore the only methods that are implemented are score() and doc().
90 class BucketScorer : public Scorer {
91 public:
92 BucketScorer();
93 virtual ~BucketScorer();
94
95
96 int32_t freq;
97 LUCENE_CLASS(BucketScorer);
98 float termFreq(){
99 return freq;
100 }
101
102
103 public:
104 double _score;
105 int32_t doc;
106
107 public:
108 virtual int32_t advance(int32_t target);
109 virtual int32_t docID();
110 virtual int32_t nextDoc();
111 virtual double score();
112};
113
114 class Bucket : public LuceneObject {
115 public:
116 Bucket();
117 virtual ~Bucket();
118
119 LUCENE_CLASS(Bucket);
120
121 public:
122 int32_t doc; // tells if bucket is valid
123 double score; // incremental score
124 int32_t bits; // used for bool constraints
125 int32_t coord; // count of terms in score
126 BucketWeakPtr _next; // next valid bucket
127 Bucket* __next = nullptr; // next valid bucket
128};
129
131 class BucketTable : public LuceneObject {
132 public:
133 BucketTable();
134 virtual ~BucketTable();
135
136 LUCENE_CLASS(BucketTable);
137
138 public:
139 static const int32_t SIZE;
140 static const int32_t MASK;
141
142 Collection<BucketPtr> buckets;
143 BucketPtr first; // head of valid list
144 Bucket* __first = nullptr; // head of valid list
145
146 public:
147 CollectorPtr newCollector(int32_t mask);
148 int32_t size();
149};
150
151 class SubScorer : public LuceneObject {
152 public:
153 SubScorer(const ScorerPtr& scorer, bool required, bool prohibited, const CollectorPtr& collector, const SubScorerPtr& next);
154 virtual ~SubScorer();
155
156 LUCENE_CLASS(SubScorer);
157
158 public:
159 ScorerPtr scorer;
160 bool required;
161 bool prohibited;
162 CollectorPtr collector;
163 SubScorerPtr next;
164};
165
166}
167
168#endif
Collector.h
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Scorer.h
Lucene::BooleanScorerCollector::collect
virtual void collect(int32_t doc)
Called once for every document matching a query, with the unbased document number.
Lucene::BooleanScorerCollector::__scorer
Scorer * __scorer
Definition BooleanScorer.h:78
Lucene::BooleanScorerCollector::mask
int32_t mask
Definition BooleanScorer.h:76
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::BooleanScorerCollector::BooleanScorerCollector
BooleanScorerCollector(int32_t mask, const BucketTablePtr &bucketTable)
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::BooleanScorerCollector::~BooleanScorerCollector
virtual ~BooleanScorerCollector()
Lucene::BooleanScorerCollector::_scorer
ScorerWeakPtr _scorer
Definition BooleanScorer.h:77
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::BooleanScorerCollector::_bucketTable
BucketTableWeakPtr _bucketTable
Definition BooleanScorer.h:74
Lucene::BooleanScorerCollector::__bucketTable
BucketTable * __bucketTable
Definition BooleanScorer.h:75
Lucene::BooleanScorer::coordFactors
Collection< double > coordFactors
Definition BooleanScorer.h:42
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::scorers
SubScorerPtr scorers
Definition BooleanScorer.h:39
Lucene::BooleanScorer::maxCoord
int32_t maxCoord
Definition BooleanScorer.h:41
Lucene::BooleanScorer::score
virtual double score()
Returns the score of the current document matching the query. Initially invalid, until nextDoc() or a...
Lucene::BooleanScorer::~BooleanScorer
virtual ~BooleanScorer()
Lucene::BooleanScorer::score
virtual bool score(const CollectorPtr &collector, int32_t max, int32_t firstDocID)
Collects matching documents in a range. Hook for optimization. Note, firstDocID is added to ensure th...
Lucene::BooleanScorer::bucketTable
BucketTablePtr bucketTable
Definition BooleanScorer.h:40
Lucene::BooleanScorer::minNrShouldMatch
int32_t minNrShouldMatch
Definition BooleanScorer.h:46
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::BooleanScorer::BooleanScorer
BooleanScorer(const SimilarityPtr &similarity, int32_t minNrShouldMatch, Collection< ScorerPtr > optionalScorers, Collection< ScorerPtr > prohibitedScorers)
Lucene::BooleanScorer::requiredMask
int32_t requiredMask
Definition BooleanScorer.h:43
Lucene::BooleanScorer::doc
int32_t doc
Definition BooleanScorer.h:50
Lucene::BooleanScorer::__current
Bucket * __current
Definition BooleanScorer.h:49
Lucene::BooleanScorer::nextMask
int32_t nextMask
Definition BooleanScorer.h:45
Lucene::BooleanScorer::toString
virtual String toString()
Returns a string representation of the object.
Lucene::BooleanScorer::end
int32_t end
Definition BooleanScorer.h:47
Lucene::BooleanScorer::current
BucketPtr current
Definition BooleanScorer.h:48
Lucene::BooleanScorer::score
virtual void score(const CollectorPtr &collector)
Scores and collects all matching documents.
Lucene::BooleanScorer::prohibitedMask
int32_t prohibitedMask
Definition BooleanScorer.h:44
Lucene::BooleanScorer::docID
virtual int32_t docID()
Returns the following:
Lucene::BucketScorer::docID
virtual int32_t docID()
Returns the following:
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::BucketScorer::termFreq
float termFreq()
Definition BooleanScorer.h:98
Lucene::BucketScorer::score
virtual double score()
Returns the score of the current document matching the query. Initially invalid, until nextDoc() or a...
Lucene::BucketScorer::freq
int32_t freq
Definition BooleanScorer.h:96
Lucene::BucketScorer::_score
double _score
Definition BooleanScorer.h:104
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....
Lucene::BucketScorer::doc
int32_t doc
Definition BooleanScorer.h:105
Lucene::BucketScorer::~BucketScorer
virtual ~BucketScorer()
Lucene::BucketScorer::BucketScorer
BucketScorer()
Lucene::BucketTable
A simple hash table of document scores within a range.
Definition BooleanScorer.h:131
Lucene::BucketTable::buckets
Collection< BucketPtr > buckets
Definition BooleanScorer.h:142
Lucene::BucketTable::BucketTable
BucketTable()
Lucene::BucketTable::first
BucketPtr first
Definition BooleanScorer.h:143
Lucene::BucketTable::SIZE
static const int32_t SIZE
Definition BooleanScorer.h:139
Lucene::BucketTable::~BucketTable
virtual ~BucketTable()
Lucene::BucketTable::size
int32_t size()
Lucene::BucketTable::newCollector
CollectorPtr newCollector(int32_t mask)
Lucene::BucketTable::__first
Bucket * __first
Definition BooleanScorer.h:144
Lucene::BucketTable::MASK
static const int32_t MASK
Definition BooleanScorer.h:140
Lucene::Bucket
Definition BooleanScorer.h:114
Lucene::Bucket::__next
Bucket * __next
Definition BooleanScorer.h:127
Lucene::Bucket::~Bucket
virtual ~Bucket()
Lucene::Bucket::score
double score
Definition BooleanScorer.h:123
Lucene::Bucket::bits
int32_t bits
Definition BooleanScorer.h:124
Lucene::Bucket::Bucket
Bucket()
Lucene::Bucket::_next
BucketWeakPtr _next
Definition BooleanScorer.h:126
Lucene::Bucket::doc
int32_t doc
Definition BooleanScorer.h:122
Lucene::Bucket::coord
int32_t coord
Definition BooleanScorer.h:125
Lucene::Collection
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
Lucene::Collector
Collectors are primarily meant to be used to gather raw results from a search, and implement sorting ...
Definition Collector.h:100
Lucene::LuceneObject::LuceneObject
LuceneObject()
Lucene::Scorer
Common scoring functionality for different types of queries.
Definition Scorer.h:33
Lucene::Scorer::similarity
SimilarityPtr similarity
Definition Scorer.h:45
Lucene::Scorer::Scorer
Scorer(const SimilarityPtr &similarity)
Constructs a Scorer.
Lucene::SubScorer::~SubScorer
virtual ~SubScorer()
Lucene::SubScorer::collector
CollectorPtr collector
Definition BooleanScorer.h:162
Lucene::SubScorer::required
bool required
Definition BooleanScorer.h:160
Lucene::SubScorer::SubScorer
SubScorer(const ScorerPtr &scorer, bool required, bool prohibited, const CollectorPtr &collector, const SubScorerPtr &next)
Lucene::SubScorer::next
SubScorerPtr next
Definition BooleanScorer.h:163
Lucene::SubScorer::scorer
ScorerPtr scorer
Definition BooleanScorer.h:159
Lucene::SubScorer::prohibited
bool prohibited
Definition BooleanScorer.h:161
Lucene
Definition AbstractAllTermDocs.h:12
Lucene::BucketPtr
boost::shared_ptr< Bucket > BucketPtr
Definition LuceneTypes.h:284
Lucene::BucketTablePtr
boost::shared_ptr< BucketTable > BucketTablePtr
Definition LuceneTypes.h:286
Lucene::ScorerWeakPtr
boost::weak_ptr< Scorer > ScorerWeakPtr
Definition LuceneTypes.h:429
Lucene::SimilarityPtr
boost::shared_ptr< Similarity > SimilarityPtr
Definition LuceneTypes.h:435
Lucene::BucketTableWeakPtr
boost::weak_ptr< BucketTable > BucketTableWeakPtr
Definition LuceneTypes.h:286
Lucene::BucketWeakPtr
boost::weak_ptr< Bucket > BucketWeakPtr
Definition LuceneTypes.h:284
Lucene::SubScorerPtr
boost::shared_ptr< SubScorer > SubScorerPtr
Definition LuceneTypes.h:462
Lucene::ScorerPtr
boost::shared_ptr< Scorer > ScorerPtr
Definition LuceneTypes.h:429
Lucene::CollectorPtr
boost::shared_ptr< Collector > CollectorPtr
Definition LuceneTypes.h:295
Lucene::IndexReaderPtr
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157

clucene.sourceforge.net