def delete_song(cls, song_id): song = Song().get(song_id, links=True) if song is None: raise NotFoundException() # remove the song from storage first song.remove() # deleting a song also deletes all the associated versions for v in song.versions: version = Version().get(v, links=True) version.remove() # then remove the singer and re-index any related objects SongIndex.delete_by_id(song.id)
def create_song(cls, song_json, versions, songs): if song_json is None: return None # create the song object and save it to the store song = Song({"song" : song_json}) if versions is not None: song.versions = versions if songs is not None: song.songs = songs song.save() # call the indexing process, and index this object and all # related ones SongIndex.by_id(song.id, cascade=True) return song
def update_song(cls, song_id, song_json=None, versions=None, songs=None): # retrieve and update the song object in the desired way song = Song().get(song_id, links=True) if song is None: raise NotFoundException() if song_json is not None: song.patch_song(song_json, replace_all=True, keep_id=True) if versions is not None: song.versions = versions if songs is not None: song.songs = songs song.save() # call the indexing process, and index this object and all related ones print song.id SongIndex.by_id(song.id, cascade=True) return song
def get_song(cls, song_id): song = SongIndex.pull(song_id) if song is None: raise NotFoundException() return song.raw
################################################### # INDEXING ################################################### # connection object to use for the save operations conn = esprit.raw.Connection(host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB) # index all the songs ##################### for sid in song_ids: song = Song().get(sid, links=True, host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB) si = SongIndex.from_song(song) si.save(conn=conn) # index all the singers ####################### for sid in singer_ids: singer = Singer().get(sid, links=True, host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB) si = SingerIndex.from_singer(singer) si.save(conn=conn) # index all the versions ######################## for vid in version_ids: version = Version().get(vid, links=True, host=settings.ELASTIC_SEARCH_HOST, index=settings.ELASTIC_SEARCH_DB)