1
# -*- test-case-name: lupy.test -*-
2
# This module is part of the Lupy project and is Copyright 2003 Amir
3
# Bakhtiar (amir@divmod.org). This is free software; you can redistribute
4
# it and/or modify it under the terms of version 2.1 of the GNU Lesser
5
# General Public License as published by the Free Software Foundation.
7
from MoinMoin.support.lupy.index import term
9
#import copy #broken, see comments at top of this file:
10
from MoinMoin.support import copy
12
class SegmentTermEnum:
14
def __init__(self, i, fis, isi):
17
self.size = self.input.readInt()
24
self.term = term.Term('','')
25
self.trmInfo = term.TermInfo()
29
"""Return a copy of self.
32
# TODO: implement as __copy__
33
clone = copy.copy(self)
34
clone.input = self.input.clone()
36
clone.trmInfo = term.TermInfo()
37
clone.trmInfo.setTo(self.trmInfo)
38
#clone.prevTxt = self.term.text()
47
return self.trmInfo.docFreq
50
def freqPointer(self):
51
return self.trmInfo.freqPointer
57
if self.position > self.size -1:
63
self.term = self.readTerm()
65
self.trmInfo.docFreq = self.input.readVInt()
66
self.trmInfo.freqPointer += self.input.readVLong()
67
self.trmInfo.proxPointer += self.input.readVLong()
70
self.indexPointer += self.input.readVLong()
72
return self.term, self.indexPointer
77
def proxPointer(self):
78
return self.trmInfo.proxPointer
82
# this bit is a mite tricky. in the java version they use a
83
# buffer for reading and just use 'start' as the offset for
84
# putting the read string into the buffer; when strings with
85
# common prefixes were read in, the offset would preserve the
86
# prefix. So here we just remember the last string and slice
87
# the common prefix from it.
88
start = self.input.readVInt()
89
self.prevTxt = txt = self.prevTxt[:start] + self.input.readString()
90
fi = self.input.readVInt()
91
fld = self.fieldInfos.fieldName(fi)
92
t = term.Term(fld,txt,False)
96
def seek(self, pointer, p, t, ti):
97
self.input.seek(pointer)
101
self.trmInfo.setTo(ti)
102
self.prevTxt = self.term.text()
104
def termInfo(self, ti=None):
106
nti = term.TermInfo()
107
nti.setTo(self.trmInfo)
110
ti.setTo(self.trmInfo)
113
return cmp(a.term, b.term)
116
class SegmentInfo(object):
118
def __init__(self, name, docCount, d):
120
self.docCount = docCount
124
class SegmentInfos(list):
126
def __init__(self, lst = None):
131
def __getslice__(self, lo, hi):
132
res = SegmentInfos(list.__getslice__(self, lo, hi))
133
res.counter = self.counter
136
def read(self, directory):
137
input = directory.openFile('segments')
139
self.counter = input.readInt() # read counter
141
while i > 0: # read segment infos
142
si = SegmentInfo(input.readString(),
150
def write(self, directory):
151
output = directory.createFile('segments.new')
153
output.writeInt(self.counter)
154
output.writeInt(len(self))
156
output.writeString(si.name)
157
output.writeInt(si.docCount)
161
# Install new segment info
162
directory.renameFile('segments.new','segments')
165
return 'SegInfo' + list.__repr__(self)