summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/clucene/src/CLucene/index/TermInfosReader.h
blob: 6a0ed69abfb151d529d802cebdbc250a4dbca7ee (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
100
101
102
103
104
105
106
/*
 * 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) 2012 Digia Plc and/or its subsidiary(-ies), all rights reserved.
*/
#ifndef _lucene_index_TermInfosReader_
#define _lucene_index_TermInfosReader_

#if defined(_LUCENE_PRAGMA_ONCE)
#   pragma once
#endif

#include <QtCore/QString>

#include "CLucene/store/Directory.h"
#include "CLucene/util/ThreadLocal.h"
#include "SegmentTermEnum.h"

CL_NS_DEF(index)

class FieldInfos;
class Term;
class TermInfo;
class TermInfos;
class TermInfosWriter;

// PORT STATUS: 365707 (jlucene 1.9)
// This stores a monotonically increasing set of <Term, TermInfo> pairs in a
// Directory. Pairs are accessed either by Term or by ordinal position the set.  
class TermInfosReader : LUCENE_BASE
{
private:
    CL_NS(store)::Directory* directory;
    QString segment;
    FieldInfos* fieldInfos;

    CL_NS(util)::ThreadLocal<SegmentTermEnum*, 
        CL_NS(util)::Deletor::Object<SegmentTermEnum> > enumerators;

    SegmentTermEnum* getEnum();
    SegmentTermEnum* origEnum;
    SegmentTermEnum* indexEnum;
    int64_t _size;

    Term* indexTerms;
    int32_t indexTermsLength;
    TermInfo* indexInfos;
    int64_t* indexPointers;

    DEFINE_MUTEX(THIS_LOCK)

public:
    // Reads the TermInfos file(.tis) and eventually the Term Info Index(.tii)
    TermInfosReader(CL_NS(store)::Directory* dir, const QString& segment,
        FieldInfos* fis);
    ~TermInfosReader();

    //Close the enumeration of TermInfos
    void close();

    //Return the size of the enumeration of TermInfos
    int64_t size() const;

    int32_t getSkipInterval() {
        return origEnum->skipInterval; }

    // Returns an enumeration of terms starting at or after the named term. 
    // If no term is specified, an enumeration of all the Terms 
    // and TermInfos in the set is returned.
    SegmentTermEnum* terms(const Term* term = NULL);

    // Returns the TermInfo for a Term in the set
    // synchronized
    TermInfo* get(const Term* term);

private:
    // Reads the term info index file or .tti file.
    void ensureIndexIsRead();

    // Returns the offset of the greatest index entry which is less than term.
    int32_t getIndexOffset(const Term* term);

    // Reposition the current Term and TermInfo to indexOffset
    void seekEnum(const int32_t indexOffset);  

    // Scans the Enumeration of terms for term and returns the corresponding
    // TermInfo instance if found. The search is started from the current term.
    TermInfo* scanEnum(const Term* term);

    // Scans the enumeration to the requested position and returns the Term
    // located at that position
    Term* scanEnum(const int32_t position);

    // Returns the position of a Term in the set. synchronized 
    int64_t getPosition(const Term* term);

    // Returns the nth term in the set. synchronized
    Term* get(const int32_t position);
};

CL_NS_END

#endif