[Migration] remove CouchDB fulltext index
[mygpo.git] / mygpo / directory / search.py
blobe655da8a6a5de6860694ba3a4cf2073bc050419b
1 from mygpo.podcasts.models import Podcast
2 from mygpo.utils import is_url, normalize_feed_url
3 from mygpo.data.feeddownloader import PodcastUpdater, NoPodcastCreated
4 from mygpo.cache import cache_result
5 from mygpo.db.couchdb.podcast import search
8 @cache_result(timeout=60*60)
9 def search_podcasts(q, limit=20, skip=0):
11 if is_url(q):
12 url = normalize_feed_url(q)
14 try:
15 podcast = Podcast.objects.get(urls__url=url)
16 except Podcast.DoesNotExist:
17 podcast = None
19 if not podcast or not podcast.title:
21 updater = PodcastUpdater()
23 try:
24 updater.update(url)
25 except NoPodcastCreated as npc:
26 return [], 0
28 try:
29 podcast = Podcast.objects.get(urls__url=url)
30 return [podcast], 1
31 except Podcast.DoesNotExist:
32 return [], 0
35 return search(q, skip, limit)