Пример #1
0
    def index_dimension(self, dimension, dimension_tag, locale,
                        locale_tag, **options):
        """Create dimension index records.

        If `Attribute.info` has key `no_search` set to `True`, then the field
        is skipped
        """

        print "indexing %s, locale: %s" % (dimension, locale)

        hierarchy = dimension.hierarchy()

        # Switch browser locale
        self.browser.set_locale(locale)
        cell = cubes.Cell(self.cube)

        for depth_m1, level in enumerate(hierarchy.levels):
            depth = depth_m1 + 1

            levels = hierarchy.levels[0:depth]
            keys = [level.key.ref() for level in levels]
            level_key = keys[-1]
            level_label = (level.label_attribute.ref())

            if options.get("labels_only"):
                attributes = [level.label_attribute]
            else:
                attributes = []
                for attr in level.attributes:
                    if not attr.info or \
                            (attr.info and not attr.info.get("no_search")):
                        attributes.append(attr)

            for record in self.browser.values(cell, dimension, depth):
                print "Dimension value: %s" % record
                path = [record[key] for key in keys]
                path_string = cubes.string_from_path(path)

                for attr in attributes:
                    ref = to_unicode_string(attr.ref())
                    self.writer.add_document(
                        locale=to_unicode_string(locale),
                        dimension=dimension.name,
                        level=level.name,
                        depth=depth,
                        path=path_string,
                        level_key=record[level_key],
                        level_label=record[level_label],
                        attribute=attr.name,
                        value=to_unicode_string(record[ref])
                    )
Пример #2
0
    def index_dimension(self, dimension, dimension_tag, locale, locale_tag,
                        **options):
        """Create dimension index records."""

        hierarchy = dimension.hierarchy()

        # Switch browser locale
        self.browser.set_locale(locale)
        cell = cubes.Cell(self.cube)

        labels_only = bool(options.get("labels_only"))

        for depth_m1, level in enumerate(hierarchy.levels):
            depth = depth_m1 + 1

            levels = hierarchy.levels[0:depth]
            keys = [level.key.ref() for level in levels]
            level_key = keys[-1]
            level_label = (level.label_attribute.ref())

            if labels_only:
                attributes = [level.label_attribute]
            else:
                attributes = []
                for attr in level.attributes:
                    if not attr.info or \
                            (attr.info and not attr.info.get("no_search")):
                        attributes.append(attr)

            for record in self.browser.values(cell, dimension, depth):
                path = [record[key] for key in keys]
                path_string = cubes.string_from_path(path)

                for attr in attributes:
                    fname = attr.ref()
                    irecord = {
                        "locale_tag": locale_tag,
                        "dimension": dimension.name,
                        "dimension_tag": dimension_tag,
                        "level": level.name,
                        "depth": depth,
                        "path": path_string,
                        "attribute": attr.name,
                        "value": record[fname],
                        "level_key": record[level_key],
                        "level_label": record[level_label]
                    }

                    self.add(irecord)
Пример #3
0
    def index_dimension(self, dimension, dimension_tag, locale,
                        locale_tag, **options):
        """Create dimension index records."""

        hierarchy = dimension.hierarchy()

        # Switch browser locale
        self.browser.set_locale(locale)
        cell = cubes.Cell(self.cube)

        labels_only = bool(options.get("labels_only"))

        for depth_m1, level in enumerate(hierarchy.levels):
            depth = depth_m1 + 1

            levels = hierarchy.levels[0:depth]
            keys = [level.key.ref() for level in levels]
            level_key = keys[-1]
            level_label = (level.label_attribute.ref())

            if labels_only:
                attributes = [level.label_attribute]
            else:
                attributes = []
                for attr in level.attributes:
                    if not attr.info or \
                            (attr.info and not attr.info.get("no_search")):
                        attributes.append(attr)

            for record in self.browser.values(cell, dimension, depth):
                path = [record[key] for key in keys]
                path_string = cubes.string_from_path(path)

                for attr in attributes:
                    fname = attr.ref()
                    irecord = {
                        "locale_tag": locale_tag,
                        "dimension": dimension.name,
                        "dimension_tag": dimension_tag,
                        "level": level.name,
                        "depth": depth,
                        "path": path_string,
                        "attribute": attr.name,
                        "value": record[fname],
                        "level_key": record[level_key],
                        "level_label": record[level_label]
                        }

                    self.add(irecord)
Пример #4
0
    def index_dimension(self, dimension, dimension_tag, locale, locale_tag,
                        **options):
        """Create dimension index records.

        If `Attribute.info` has key `no_search` set to `True`, then the field
        is skipped
        """

        print "indexing %s, locale: %s" % (dimension, locale)

        hierarchy = dimension.hierarchy()

        # Switch browser locale
        self.browser.set_locale(locale)
        cell = cubes.Cell(self.cube)

        for depth_m1, level in enumerate(hierarchy.levels):
            depth = depth_m1 + 1

            levels = hierarchy.levels[0:depth]
            keys = [level.key.ref() for level in levels]
            level_key = keys[-1]
            level_label = (level.label_attribute.ref())

            if options.get("labels_only"):
                attributes = [level.label_attribute]
            else:
                attributes = []
                for attr in level.attributes:
                    if not attr.info or \
                            (attr.info and not attr.info.get("no_search")):
                        attributes.append(attr)

            for record in self.browser.values(cell, dimension, depth):
                path = [record[key] for key in keys]
                path_string = cubes.string_from_path(path)

                for attr in attributes:
                    ref = unicode(attr.ref())
                    self.writer.add_document(locale=unicode(locale),
                                             dimension=dimension.name,
                                             level=level.name,
                                             depth=depth,
                                             path=path_string,
                                             level_key=record[level_key],
                                             level_label=record[level_label],
                                             attribute=attr.name,
                                             value=unicode(record[ref]))