src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 149 a10198c95808
parent 147 955119f901b4
child 150 40cf046b7049
--- a/src/js/serializers/JSONSerializer.js	Wed Oct 26 12:40:24 2011 +0200
+++ b/src/js/serializers/JSONSerializer.js	Wed Oct 26 12:41:14 2011 +0200
@@ -71,4 +71,36 @@
     }
     
     return ret_array;
-}
\ No newline at end of file
+};
+
+/* breaks a string in words and searches each of these words. Returns an array
+   of objects with the id of the annotation and its number of occurences.
+   
+   FIXME: optimize ? seems to be n^2 in the worst case.
+*/
+IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) {
+  var ret = { };
+  var keywords = searchString.split(/\s+/);
+  
+  for (var i in keywords) {
+    var keyword = keywords[i];
+    
+    var found_annotations = []
+    found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", ""));
+    found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, ""));
+    
+    for (var j in found_annotations) {
+      var current_annotation = found_annotations[j];
+      
+      if (!ret.hasOwnProperty(current_annotation.id)) {
+        ret[current_annotation.id] = 1;
+      } else {
+        ret[current_annotation.id] += 1;
+      }
+      
+    }
+
+  };
+  
+  return ret;
+};
\ No newline at end of file