Ejemplo n.º 1
0
    def fulltext(self, query, source=True, context=True, translation=True,
                 checksums=False):
        '''
        Performs full text search on defined set of fields.

        Returns queryset unless checksums is set.
        '''

        lang = self.all()[0].translation.language.code
        ret = fulltext_search(query, lang, source, context, translation)

        if checksums:
            return ret

        return self.filter(checksum__in=ret)
Ejemplo n.º 2
0
    def same_source(self, unit):
        '''
        Finds units with same source.
        '''
        checksums = fulltext_search(
            unit.get_source_plurals()[0],
            unit.translation.language.code,
            True, False, False
        )

        return self.filter(
            checksum__in=checksums,
            translation__language=unit.translation.language,
            translated=True
        ).exclude(
            pk=unit.id
        )
Ejemplo n.º 3
0
    def more_like_this(self, unit, top=5):
        '''
        Finds closely similar units.
        '''
        more_results = more_like(unit.checksum, unit.source, top)

        same_results = fulltext_search(
            unit.get_source_plurals()[0],
            unit.translation.language.code,
            True, False, False
        )

        checksums = more_results - same_results

        return self.filter(
            checksum__in=checksums,
            translation__language=unit.translation.language,
            translated=True
        ).exclude(
            pk=unit.id
        )