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 
36 
37 protected:
40  int32_t maxCoord;
42  int32_t requiredMask;
43  int32_t prohibitedMask;
44  int32_t nextMask;
46  int32_t end;
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 
64 public:
66  virtual ~BooleanScorerCollector();
67 
69 
70 protected:
71  BucketTableWeakPtr _bucketTable;
72  int32_t mask;
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 
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 
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 
125 
126 public:
127  static const int32_t SIZE;
128  static const int32_t MASK;
129 
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 
144 
145 public:
146  ScorerPtr scorer;
147  bool required;
151 };
152 
153 }
154 
155 #endif
CollectorPtr collector
Definition: BooleanScorer.h:149
int32_t bits
Definition: BooleanScorer.h:113
BooleanScorer uses a ~16k array to score windows of docs. So it scores docs 0-16k first...
Definition: BooleanScorer.h:30
BucketTablePtr bucketTable
Definition: BooleanScorer.h:39
static const int32_t MASK
Definition: BooleanScorer.h:128
boost::shared_ptr< BucketTable > BucketTablePtr
Definition: LuceneTypes.h:286
int32_t maxCoord
Definition: BooleanScorer.h:40
boost::weak_ptr< Scorer > ScorerWeakPtr
Definition: LuceneTypes.h:429
boost::weak_ptr< Bucket > BucketWeakPtr
Definition: LuceneTypes.h:284
int32_t prohibitedMask
Definition: BooleanScorer.h:43
ScorerWeakPtr _scorer
Definition: BooleanScorer.h:73
SimilarityPtr similarity
Definition: Scorer.h:29
virtual double score()
Returns the score of the current document matching the query. Initially invalid, until nextDoc() or a...
int32_t end
Definition: BooleanScorer.h:46
int32_t coord
Definition: BooleanScorer.h:114
bool prohibited
Definition: BooleanScorer.h:148
virtual int32_t advance(int32_t target)
Advances to the first beyond the current whose document number is greater than or equal to target...
boost::weak_ptr< BucketTable > BucketTableWeakPtr
Definition: LuceneTypes.h:286
bool required
Definition: BooleanScorer.h:147
virtual String toString()
Returns a string representation of the object.
boost::shared_ptr< Scorer > ScorerPtr
Definition: LuceneTypes.h:429
int32_t doc
Definition: BooleanScorer.h:48
BucketPtr current
Definition: BooleanScorer.h:47
Definition: BooleanScorer.h:63
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...
int32_t requiredMask
Definition: BooleanScorer.h:42
boost::shared_ptr< Bucket > BucketPtr
Definition: LuceneTypes.h:284
Common scoring functionality for different types of queries.
Definition: Scorer.h:22
boost::shared_ptr< Collector > CollectorPtr
Definition: LuceneTypes.h:295
SubScorerPtr next
Definition: BooleanScorer.h:150
int32_t doc
Definition: BooleanScorer.h:94
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition: LuceneTypes.h:157
Base class for all Lucene classes.
Definition: LuceneObject.h:31
virtual int32_t docID()
Returns the following:
#define LUCENE_CLASS(Name)
Definition: LuceneObject.h:24
Definition: AbstractAllTermDocs.h:12
BooleanScorer(const SimilarityPtr &similarity, int32_t minNrShouldMatch, Collection< ScorerPtr > optionalScorers, Collection< ScorerPtr > prohibitedScorers)
A simple hash table of document scores within a range.
Definition: BooleanScorer.h:119
int32_t nextMask
Definition: BooleanScorer.h:44
Collectors are primarily meant to be used to gather raw results from a search, and implement sorting ...
Definition: Collector.h:100
Collection< BucketPtr > buckets
Definition: BooleanScorer.h:130
static const int32_t SIZE
Definition: BooleanScorer.h:124
int32_t minNrShouldMatch
Definition: BooleanScorer.h:45
Definition: BooleanScorer.h:138
double score
Definition: BooleanScorer.h:112
boost::shared_ptr< Similarity > SimilarityPtr
Definition: LuceneTypes.h:435
int32_t mask
Definition: BooleanScorer.h:72
boost::shared_ptr< SubScorer > SubScorerPtr
Definition: LuceneTypes.h:462
SubScorerPtr scorers
Definition: BooleanScorer.h:35
Definition: BooleanScorer.h:103
Collection< double > coordFactors
Definition: BooleanScorer.h:41
Definition: BooleanScorer.h:85
BucketPtr first
Definition: BooleanScorer.h:131
BucketWeakPtr _next
Definition: BooleanScorer.h:115

clucene.sourceforge.net