summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/clucene/src/CLucene/search/BooleanScorer.h
blob: 2147bc51683729b1c8bfcc760a6846199c8eae3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
* 
* Distributable under the terms of either the Apache License (Version 2.0) or 
* the GNU Lesser General Public License, as specified in the COPYING file.
*
* Changes are Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
------------------------------------------------------------------------------*/
#ifndef _lucene_search_BooleanScorer_
#define _lucene_search_BooleanScorer_

#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif

#include "Scorer.h"

CL_NS_DEF(search)

class BooleanScorer : public Scorer {
public:
    class Bucket : LUCENE_BASE {
    public:
        int32_t	doc;				  // tells if bucket is valid
        qreal	score;				  // incremental score
        int32_t	bits;				  // used for bool constraints
        int32_t	coord;				  // count of terms in score
        Bucket*	next;				  // next valid bucket

        Bucket();
        ~Bucket();
    };

    class SubScorer: LUCENE_BASE {
    public:
        bool done;
        Scorer* scorer;
        bool required;
        bool prohibited;
        HitCollector* collector;
        SubScorer* next;
        SubScorer(Scorer* scr, const bool r, const bool p, HitCollector* c, SubScorer* nxt);
        ~SubScorer();
    };

    class BucketTable:LUCENE_BASE {		
    private:
        BooleanScorer* scorer;
    public:
        Bucket* buckets;
        Bucket* first;			  // head of valid list

        BucketTable(BooleanScorer* scr);
        int32_t size() const;
        HitCollector* newCollector(const int32_t mask);
        void clear();
        ~BucketTable();

    };

    class Collector: public HitCollector {
    private:
        BucketTable* bucketTable;
        int32_t mask;
    public:
        Collector(const int32_t mask, BucketTable* bucketTable);

        void collect(const int32_t doc, const qreal score);
    };

    SubScorer* scorers;
    BucketTable* bucketTable;

    int32_t maxCoord;
    int32_t nextMask;

    int32_t end;
    Bucket* current;

public:
    LUCENE_STATIC_CONSTANT(int32_t,BucketTable_SIZE=1024);
    int32_t requiredMask;
    int32_t prohibitedMask;
    qreal* coordFactors;

    BooleanScorer(Similarity* similarity);
    ~BooleanScorer();
    void add(Scorer* scorer, const bool required, const bool prohibited);
    int32_t doc() const { return current->doc; }
    bool next();
    qreal score();
    bool skipTo(int32_t target);
    void explain(int32_t doc, Explanation* ret);
    TCHAR* toString();
    void computeCoordFactors();
};

CL_NS_END
#endif