def finish_term(self):
        terminfo = self._postwriter.finish_postings()

        # Add row to term info table
        keybytes = pack_ushort(self._fieldid) + self._btext
        valbytes = terminfo.to_bytes()
        self._tindex.add(keybytes, valbytes)
Exemplo n.º 2
0
    def finish_term(self):
        terminfo = self._postwriter.finish_postings()

        # Add row to term info table
        keybytes = pack_ushort(self._fieldid) + self._btext
        valbytes = terminfo.to_bytes()
        self._tindex.add(keybytes, valbytes)
Exemplo n.º 3
0
    def keycoder(self, key):
        # Encode term
        fieldmap = self.fieldmap
        fieldname, text = key

        if fieldname in fieldmap:
            fieldnum = fieldmap[fieldname]
        else:
            fieldnum = self.fieldcounter
            fieldmap[fieldname] = fieldnum
            self.fieldcounter += 1

        key = pack_ushort(fieldnum) + utf8encode(text)[0]
        return key
Exemplo n.º 4
0
    def keycoder(self, key):
        # Encode term
        fieldmap = self.fieldmap
        fieldname, text = key

        if fieldname in fieldmap:
            fieldnum = fieldmap[fieldname]
        else:
            fieldnum = self.fieldcounter
            fieldmap[fieldname] = fieldnum
            self.fieldcounter += 1

        key = pack_ushort(fieldnum) + utf8encode(text)[0]
        return key
Exemplo n.º 5
0
    def write_tagint(self, i):
        """Writes a sometimes-compressed unsigned integer to the wrapped file.
        This is similar to the varint methods but uses a less compressed but
        faster format.
        """

        # Store numbers 0-253 in one byte. Byte 254 means "an unsigned 16-bit
        # int follows." Byte 255 means "An unsigned 32-bit int follows."
        if i <= 253:
            self.file.write(chr(i))
        elif i <= 65535:
            self.file.write("\xFE" + pack_ushort(i))
        else:
            self.file.write("\xFF" + pack_uint(i))
Exemplo n.º 6
0
    def write_tagint(self, i):
        """Writes a sometimes-compressed unsigned integer to the wrapped file.
        This is similar to the varint methods but uses a less compressed but
        faster format.
        """

        # Store numbers 0-253 in one byte. Byte 254 means "an unsigned 16-bit
        # int follows." Byte 255 means "An unsigned 32-bit int follows."
        if i <= 253:
            self.file.write(chr(i))
        elif i <= 65535:
            self.file.write("\xFE" + pack_ushort(i))
        else:
            self.file.write("\xFF" + pack_uint(i))
Exemplo n.º 7
0
 def _keycoder(self, fieldname, tbytes):
     assert isinstance(tbytes, bytes_type), "tbytes=%r" % tbytes
     fnum = self._fieldmap.get(fieldname, 65535)
     return pack_ushort(fnum) + tbytes
 def _keycoder(self, fieldname, tbytes):
     assert isinstance(tbytes, bytes_type), "tbytes=%r" % tbytes
     fnum = self._fieldmap.get(fieldname, 65535)
     return pack_ushort(fnum) + tbytes
Exemplo n.º 9
0
 def keycoder(self, key):
     fieldname, text = key
     fnum = self.fieldmap.get(fieldname, 65535)
     return pack_ushort(fnum) + utf8encode(text)[0]
Exemplo n.º 10
0
 def write_ushort(self, n):
     self.file.write(pack_ushort(n))
Exemplo n.º 11
0
 def write_string2(self, s):
     self.write(pack_ushort(len(s)) + s)
Exemplo n.º 12
0
 def keycoder(self, key):
     fieldname, text = key
     fnum = self.fieldmap.get(fieldname, 65535)
     return pack_ushort(fnum) + utf8encode(text)[0]
Exemplo n.º 13
0
 def write_ushort(self, n):
     self.file.write(pack_ushort(n))
Exemplo n.º 14
0
 def write_string2(self, s):
     self.write(pack_ushort(len(s)) + s)