Esempio n. 1
0
    def column_reader(self, fieldname, column=None, reverse=False,
                      translate=True):
        if self.is_closed:
            raise ReaderClosed

        fieldobj = self.schema[fieldname]
        column = column or fieldobj.column_type
        if not column:
            raise Exception("No column for field %r in %r"
                            % (fieldname, self))

        if self._perdoc.has_column(fieldname):
            creader = self._perdoc.column_reader(fieldname, column)
            if reverse:
                creader.set_reverse()
        else:
            # This segment doesn't have a column file for this field, so create
            # a fake column reader that always returns the default value.
            default = column.default_value(reverse)
            creader = columns.EmptyColumnReader(default, self.doc_count_all())

        if translate:
            # Wrap the column in a Translator to give the caller
            # nice values instead of sortable representations
            fcv = fieldobj.from_column_value
            creader = columns.TranslatingColumnReader(creader, fcv)

        return creader
Esempio n. 2
0
    def column_reader(self, fieldname, column):
        if not self.has_column(fieldname):
            raise ValueError("No column %r" % (fieldname, ))

        default = column.default_value()
        colreaders = []
        for r in self._readers:
            if r.has_column(fieldname):
                cr = r.column_reader(fieldname, column)
            else:
                cr = columns.EmptyColumnReader(default, r.doc_count_all())
            colreaders.append(cr)

        if len(colreaders) == 1:
            return colreaders[0]
        else:
            return columns.MultiColumnReader(colreaders)
Esempio n. 3
0
    def column_reader(self, fieldname, translate=True):
        column = self.schema[fieldname].column_type
        if not column:
            raise Exception("Field %r has no column type" % (fieldname, ))

        default = column.default_value()
        doccount = self.doc_count_all()

        creaders = []
        for r in self.readers:
            if r.has_column(fieldname):
                creaders.append(r.column_reader(fieldname,
                                                translate=translate))
            else:
                creaders.append(columns.EmptyColumnReader(default, doccount))

        return columns.MultiColumnReader(creaders)