summaryrefslogtreecommitdiffstats
path: root/3rdparty/clucene/src/CLucene/index/SegmentTermPositions.cpp
blob: e481838e959763b16e2f5c55fcd10004756568b8 (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
/*------------------------------------------------------------------------------
* 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.
------------------------------------------------------------------------------*/
#include "CLucene/StdHeader.h"
#include "SegmentHeader.h"

#include "Terms.h"

CL_NS_USE(util)
CL_NS_DEF(index)

SegmentTermPositions::SegmentTermPositions(const SegmentReader* _parent):
  SegmentTermDocs(_parent){
//Func - Constructor
//Pre  - Parent != NULL
//Post - The instance has been created

    CND_PRECONDITION(_parent != NULL, "Parent is NULL");
    
    proxStream = _parent->proxStream->clone();
    
    CND_CONDITION(proxStream != NULL,"proxStream is NULL");
    
    position  = 0;
    proxCount = 0;
}

SegmentTermPositions::~SegmentTermPositions() {
//Func - Destructor
//Pre  - true
//Post - The intance has been closed
    close();
}

TermDocs* SegmentTermPositions::__asTermDocs(){
    return (TermDocs*) this;
}
TermPositions* SegmentTermPositions::__asTermPositions(){
    return (TermPositions*) this;
}

void SegmentTermPositions::seek(const TermInfo* ti) {
    SegmentTermDocs::seek(ti);
    if (ti != NULL)
        proxStream->seek(ti->proxPointer);
    proxCount = 0;
}

void SegmentTermPositions::close() {
//Func - Frees the resources
//Pre  - true
//Post - The resources  have been freed

    SegmentTermDocs::close();
    //Check if proxStream still exists
    if(proxStream){
        proxStream->close();         
        _CLDELETE( proxStream );
    }
}

int32_t SegmentTermPositions::nextPosition() {
    /* DSR:CL_BUG: Should raise exception if proxCount == 0 at the
    ** beginning of this method, as in
    **   if (--proxCount == 0) throw ...;
    ** The JavaDocs for TermPositions.nextPosition declare this constraint,
    ** but CLucene doesn't enforce it. */
    proxCount--;
    return position += proxStream->readVInt();
}

bool SegmentTermPositions::next() {
    for (int32_t f = proxCount; f > 0; f--)		  // skip unread positions
        proxStream->readVInt();
    
    if (SegmentTermDocs::next()) {				  // run super
        proxCount = _freq;				  // note frequency
        position = 0;				  // reset position
        return true;
    }
    return false;
}

int32_t SegmentTermPositions::read(int32_t* docs, int32_t* freqs, int32_t length) {
    _CLTHROWA(CL_ERR_InvalidState,"TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
}

void SegmentTermPositions::skippingDoc() {
    for (int32_t f = _freq; f > 0; f--)		  // skip all positions
        proxStream->readVInt();
}

void SegmentTermPositions::skipProx(int64_t proxPointer){
    proxStream->seek(proxPointer);
    proxCount = 0;
}

CL_NS_END