Source code for peragro

"""
A client that provides audio search

provides different api(s) for audio search, including text based and content
based search.
"""

from elasticsearch import Elasticsearch


[docs]class PeragroClient(): """ An audio search client """ def __init__(self): """ initialize client object with elasticsearch object """ self.es = Elasticsearch()
[docs] def set_index(self, index): """ set index for to lookup in elasticsearch Input: -index: an elasticsearch index """ self.index = index
[docs] def get_sound(self, id_): """ Get sound by its id input: -id: id of sound output: -sound: sound details if it exists otherwise None Usage: >>> id = "X2VFAB12GH" >>> sound = c.get_sound(id) """ if self.es.exists(index=self.index, doc_type='_all', id=id_): res = self.es.get(index=self.index, id=id_) return res else: return None
#def text_search(self, query, fields): # """ # fields parameter allows to specify the information # you want in the results list # """ # pass #def text_search(self, query, filter, fields): # """ # search based on filter # """ # pass