Пример #1
0
    def handle(self, *args, **options):
        # Optionally rebuild indices from scratch
        if options['clean']:
            create_source_index()
            for lang in Language.objects.have_translation():
                create_target_index(lang=lang.code)

        # Open writer
        source_writer = BufferedWriter(get_source_index())
        target_writers = {}

        try:
            # Process all units
            for unit in self.iterate_units(*args, **options):
                lang = unit.translation.language.code
                # Lazy open writer
                if lang not in target_writers:
                    target_writers[lang] = BufferedWriter(
                        get_target_index(lang)
                    )
                # Update target index
                if unit.translation:
                    update_target_unit_index(target_writers[lang], unit)
                # Update source index
                update_source_unit_index(source_writer, unit)

        finally:
            # Close all writers
            source_writer.close()
            for lang in target_writers:
                target_writers[lang].close()
Пример #2
0
    def handle(self, *args, **options):
        languages = Language.objects.all()
        if options['clean']:
            create_source_index()
            for lang in languages:
                create_target_index(lang = lang.code)

        base = self.get_units(*args, **options)

        if base.count() == 0:
            return

        with FULLTEXT_INDEX.source_writer(buffered = False) as writer:
            for unit in base.values('checksum', 'source', 'context').iterator():
                Unit.objects.add_to_source_index(
                    unit['checksum'],
                    unit['source'],
                    unit['context'],
                    writer)

        for lang in languages:
            with FULLTEXT_INDEX.target_writer(lang = lang.code, buffered = False) as writer:
                for unit in base.filter(translation__language =
                    lang).exclude(target = '').values('checksum', 'target').iterator():
                    Unit.objects.add_to_target_index(
                        unit['checksum'],
                        unit['target'],
                        writer)
Пример #3
0
    def handle(self, *args, **options):
        # Optionally rebuild indices from scratch
        if options['clean']:
            create_source_index()
            for lang in Language.objects.have_translation():
                create_target_index(lang=lang.code)

        # Open writer
        source_writer = get_source_index().writer()
        target_writers = {}

        try:
            # Process all units
            for unit in self.iterate_units(*args, **options):
                lang = unit.translation.language.code
                # Lazy open writer
                if lang not in target_writers:
                    target_writers[lang] = get_target_index(lang).writer()
                # Update target index
                if unit.translation:
                    update_target_unit_index(target_writers[lang], unit)
                # Update source index
                update_source_unit_index(source_writer, unit)

        finally:
            # Close all writers
            source_writer.commit()
            for lang in target_writers:
                target_writers[lang].commit()
Пример #4
0
    def handle(self, *args, **options):
        languages = Language.objects.all()
        if options['clean']:
            create_source_index()
            for lang in languages:
                create_target_index(lang=lang.code)

        base = self.get_units(*args, **options)

        if base.count() == 0:
            return

        with FULLTEXT_INDEX.source_writer(buffered=False) as writer:
            for unit in base.values('checksum', 'source',
                                    'context').iterator():
                Unit.objects.add_to_source_index(unit['checksum'],
                                                 unit['source'],
                                                 unit['context'], writer)

        for lang in languages:
            with FULLTEXT_INDEX.target_writer(lang=lang.code,
                                              buffered=False) as writer:
                for unit in base.filter(translation__language=lang).exclude(
                        target='').values('checksum', 'target').iterator():
                    Unit.objects.add_to_target_index(unit['checksum'],
                                                     unit['target'], writer)
Пример #5
0
    def handle(self, *args, **options):
        # Optionally rebuild indices from scratch
        if options['clean']:
            create_source_index()
            for lang in Language.objects.have_translation():
                create_target_index(lang=lang.code)

        units = self.get_units(*args, **options)

        update_index(units)
Пример #6
0
    def handle(self, *args, **options):
        # Optionally rebuild indices from scratch
        if options['clean']:
            create_source_index()
            for lang in Language.objects.have_translation():
                create_target_index(lang=lang.code)

        units = self.get_units(*args, **options)

        update_index(units)
Пример #7
0
    def handle(self, *args, **options):
        languages = Language.objects.all()

        # Optionally rebuild indices from scratch
        if options['clean']:
            create_source_index()
            for lang in languages:
                create_target_index(lang=lang.code)

        units = self.get_units(*args, **options)

        # Update source index
        with FULLTEXT_INDEX.source_writer(buffered=False) as writer:
            checksums = units.values('checksum', 'source', 'context')
            for unit in checksums.iterator():
                Unit.objects.add_to_source_index(
                    unit['checksum'],
                    unit['source'],
                    unit['context'],
                    writer
                )

        # Update per language indices
        for lang in languages:
            with FULLTEXT_INDEX.target_writer(lang=lang.code, buffered=False) as writer:

                language_units = units.filter(
                    translation__language=lang
                ).exclude(
                    target=''
                ).values(
                    'checksum', 'target'
                )

                for unit in language_units.iterator():
                    Unit.objects.add_to_target_index(
                        unit['checksum'],
                        unit['target'],
                        writer
                    )