From: Marcin Koziej Date: Thu, 10 May 2012 12:03:51 +0000 (+0200) Subject: remove dupes in hints generated by pdcounter X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/05d3db941311f20a7131fab8118418c351ba5d3c?ds=inline;hp=0c3e8f92c425a22c1b9da737db89977d31312353 remove dupes in hints generated by pdcounter --- diff --git a/apps/search/index.py b/apps/search/index.py index f608a5bec..a0bf71588 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -1409,8 +1409,9 @@ class Search(IndexStore): else: tag = catalogue.models.Tag.objects.get(id=doc.get("tag_id")) # don't add the pdcounter tag if same tag already exists - if not (is_pdcounter and filter(lambda t: tag.slug == t.slug, tags)): - tags.append(tag) + + tags.append(tag) + except catalogue.models.Tag.DoesNotExist: pass except PDCounterAuthor.DoesNotExist: pass except PDCounterBook.DoesNotExist: pass diff --git a/apps/search/views.py b/apps/search/views.py index fd5883ede..56eef0976 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -10,6 +10,7 @@ from django.utils.translation import ugettext as _ from catalogue.utils import split_tags from catalogue.models import Book, Tag, Fragment +from pdcounter.models import Author as PDCounterAuthor, BookStub as PDCounterBook from catalogue.views import JSONResponse from search import Search, JVM, SearchResult from lucene import StringReader @@ -90,6 +91,18 @@ def hint(request): tags = search.hint_tags(prefix, pdcounter=True) books = search.hint_books(prefix) + + def is_dupe(tag): + if isinstance(tag, PDCounterAuthor): + if filter(lambda t: t.slug == tag.slug and t != tag, tags): + return True + elif isinstance(tag, PDCounterBook): + if filter(lambda b: b.slug == tag.slug, tags): + return True + return False + + tags = filter(lambda t: not is_dupe(t), tags) + def category_name(c): if c.startswith('pd_'): c = c[len('pd_'):]