[Search] get search results from Elasticsearch
[mygpo.git] / mygpo / search / models.py
blobb8bb1ae8d99014d48d889c0568396619b96a75bc
1 """ Wrappers for the results of a search """
3 class PodcastResult(object):
4 """ Wrapper for a Podcast search result """
6 @classmethod
7 def from_doc(cls, doc):
8 """ Construct a PodcastResult from a search result """
9 obj = cls()
11 for key, val in doc['_source'].items():
12 setattr(obj, key, val)
14 obj.id = doc['_id']
15 return obj
17 @property
18 def slug(self):
19 return next(iter(self.slugs), None)
21 @property
22 def url(self):
23 return next(iter(self.urls), None)
25 def get_id(self):
26 return self.id