1 from mygpo
.core
.models
import Podcast
, PodcastGroup
2 from mygpo
.utils
import is_url
3 from mygpo
.data
.feeddownloader
import update_podcasts
4 from mygpo
.api
.sanitizing
import sanitize_url
7 def search_wrapper(result
):
9 if doc
['doc_type'] == 'Podcast':
11 elif doc
['doc_type'] == 'PodcastGroup':
12 p
= PodcastGroup
.wrap(doc
)
17 def search_podcasts(q
, limit
=20, skip
=0):
22 podcast
= Podcast
.for_url(url
, create
=True)
25 update_podcasts([podcast
])
27 podcast
= Podcast
.for_url(url
)
34 #FIXME current couchdbkit can't parse responses for multi-query searches
35 q
= q
.replace(',', '')
37 res
= db
.search('podcasts/search', wrapper
=search_wrapper
,
38 include_docs
=True, limit
=limit
, skip
=skip
, q
=q
,
39 sort
='\\subscribers<int>')
41 #FIXME: return empty results in case of search backend error
43 return list(res
), res
.total_rows