diff -r b99527037c89 -r 955119f901b4 src/js/serializers/JSONSerializer.js --- a/src/js/serializers/JSONSerializer.js Wed Oct 26 11:32:01 2011 +0200 +++ b/src/js/serializers/JSONSerializer.js Wed Oct 26 11:32:21 2011 +0200 @@ -36,3 +36,39 @@ IriSP.JSONSerializer.prototype.currentMedia = function() { return this._data.medias[0]; /* FIXME: don't hardcode it */ }; + +/* this function searches for an annotation which matches title, description and keyword + "" matches any field. +*/ +IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) { + var rTitle; + var rDescription; + var rKeyword; + + /* match anything if given the empty string */ + if (title == "") + title = ".*"; + if (description == "") + description = ".*"; + if (keyword == "") + keyword = ".*"; + + rTitle = new RegExp(title, "i"); + rDescription = new RegExp(description, "i"); + rKeyword = new RegExp(keyword, "i"); + + var ret_array = []; + + var i; + for (i in this._data.annotations) { + var annotation = this._data.annotations[i]; + + if (rTitle.test(annotation.content.title) && + rDescription.test(annotation.content.description)) { + /* FIXME : implement keyword support */ + ret_array.push(annotation); + } + } + + return ret_array; +} \ No newline at end of file