示例#1
0
    def handle(self, *args, **options):
        # Optimize index
        if options['optimize']:
            self.optimize_index()
            return
        # Optionally rebuild indices from scratch
        if options['clean']:
            clean_indexes()

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

        try:
            # Process all units
            for unit in self.iterate_units(**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 code in target_writers:
                target_writers[code].commit()
示例#2
0
    def handle(self, *args, **options):
        # Optionally rebuild indices from scratch
        if options["clean"]:
            clean_indexes()

        # 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()
示例#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 = 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()
示例#4
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()
示例#5
0
 def optimize_index(self):
     """Optimize index structures"""
     index = get_source_index()
     index.optimize()
     languages = Language.objects.have_translation()
     for lang in languages:
         index = get_target_index(lang.code)
         index.optimize()
示例#6
0
 def optimize_index(self):
     """Optimizes index structures"""
     index = get_source_index()
     index.optimize()
     languages = Language.objects.have_translation()
     for lang in languages:
         index = get_target_index(lang.code)
         index.optimize()
示例#7
0
 def cleanup_fulltext(self):
     """Remove stale units from fulltext"""
     languages = Language.objects.have_translation().values_list('code',
                                                                 flat=True)
     # We operate only on target indexes as they will have all IDs anyway
     for lang in languages:
         index = get_target_index(lang)
         try:
             fields = index.reader().all_stored_fields()
         except EmptyIndexError:
             continue
         for item in fields:
             if Unit.objects.filter(pk=item['pk']).exists():
                 continue
             clean_search_unit(item['pk'], lang)
示例#8
0
 def cleanup_fulltext(self):
     """Remove stale units from fulltext"""
     with transaction.atomic():
         languages = list(Language.objects.have_translation().values_list(
             'code', flat=True
         ))
     # We operate only on target indexes as they will have all IDs anyway
     for lang in languages:
         index = get_target_index(lang)
         try:
             fields = index.reader().all_stored_fields()
         except EmptyIndexError:
             continue
         for item in fields:
             if Unit.objects.filter(pk=item['pk']).exists():
                 continue
             clean_search_unit(item['pk'], lang)