Commit 7dab95c3 authored by Michal Čihař's avatar Michal Čihař

Better naming of function

parent f48da809
......@@ -43,7 +43,8 @@ IGNORE_WORDS = set([
'with',
])
IGNORE_SEARCH = set([
# List of
IGNORE_SIMILAR = set([
'also',
'href',
'me',
......@@ -143,9 +144,9 @@ class UnitManager(models.Manager):
def separate_words(self, words):
return settings.SEARCH_WORD_SPLIT_REGEX.split(words)
def get_search_list(self, words):
def get_similar_list(self, words):
words = [word.lower() for word in self.separate_words(words)]
return [word for word in words if not word in IGNORE_SEARCH]
return [word for word in words if not word in IGNORE_SIMILAR]
def __index_item(self, text, language, unit):
from ftsearch.models import WordLocation, Word
......
......@@ -388,14 +388,16 @@ def get_string(request, checksum):
def get_similar(request, unit_id):
unit = get_object_or_404(Unit, pk = int(unit_id))
words = Unit.objects.get_search_list(unit.get_source_plurals()[0])
words = Unit.objects.get_similar_list(unit.get_source_plurals()[0])
similar = Unit.objects.none()
cnt = len(words)
# Try to find 10 similar string, remove up to 5 words
while similar.count() < 10 and cnt > 0 and len(words) - cnt < 5:
for search in itertools.combinations(words, cnt):
print search
similar |= Unit.objects.search(search, Language.objects.get(code = 'en')).filter(translation__subproject__project = unit.translation.subproject.project, translation__language = unit.translation.language).exclude(id = unit.id)
similar |= Unit.objects.search(search, Language.objects.get(code = 'en')).filter(
translation__subproject__project = unit.translation.subproject.project,
translation__language = unit.translation.language).exclude(id = unit.id)
print similar.count()
cnt -= 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment