1 from mygpo
.core
.models
import Podcast
, PodcastGroup
2 from mygpo
.utils
import is_url
3 from mygpo
.couch
import get_main_database
4 from mygpo
.data
.feeddownloader
import update_podcasts
5 from mygpo
.api
.sanitizing
import sanitize_url
8 def search_wrapper(result
):
10 if doc
['doc_type'] == 'Podcast':
12 elif doc
['doc_type'] == 'PodcastGroup':
13 p
= PodcastGroup
.wrap(doc
)
18 def search_podcasts(q
, limit
=20, skip
=0):
23 podcast
= Podcast
.for_url(url
, create
=True)
26 update_podcasts([podcast
])
28 podcast
= Podcast
.for_url(url
)
33 db
= get_main_database()
35 #FIXME current couchdbkit can't parse responses for multi-query searches
36 q
= q
.replace(',', '')
38 res
= db
.search('podcasts/search', wrapper
=search_wrapper
,
39 include_docs
=True, limit
=limit
, skip
=skip
, q
=q
,
40 sort
='\\subscribers<int>')
42 #FIXME: return empty results in case of search backend error
44 return list(res
), res
.total_rows