src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 149 a10198c95808
parent 147 955119f901b4
child 150 40cf046b7049
equal deleted inserted replaced
148:5e877acd85ca 149:a10198c95808
    69           ret_array.push(annotation);
    69           ret_array.push(annotation);
    70       }
    70       }
    71     }
    71     }
    72     
    72     
    73     return ret_array;
    73     return ret_array;
    74 }
    74 };
       
    75 
       
    76 /* breaks a string in words and searches each of these words. Returns an array
       
    77    of objects with the id of the annotation and its number of occurences.
       
    78    
       
    79    FIXME: optimize ? seems to be n^2 in the worst case.
       
    80 */
       
    81 IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) {
       
    82   var ret = { };
       
    83   var keywords = searchString.split(/\s+/);
       
    84   
       
    85   for (var i in keywords) {
       
    86     var keyword = keywords[i];
       
    87     
       
    88     var found_annotations = []
       
    89     found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", ""));
       
    90     found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, ""));
       
    91     
       
    92     for (var j in found_annotations) {
       
    93       var current_annotation = found_annotations[j];
       
    94       
       
    95       if (!ret.hasOwnProperty(current_annotation.id)) {
       
    96         ret[current_annotation.id] = 1;
       
    97       } else {
       
    98         ret[current_annotation.id] += 1;
       
    99       }
       
   100       
       
   101     }
       
   102 
       
   103   };
       
   104   
       
   105   return ret;
       
   106 };