compass/doc-src/content/search-data.js.erb

35 lines
1003 B
Plaintext
Raw Normal View History

2010-05-08 22:23:07 +00:00
function unique(arrayName)
{
var newArray = new Array();
label: for (var i = 0; i < arrayName.length; i++)
{
for (var j = 0; j < newArray.length; j++)
{
if (newArray[j] == arrayName[i])
continue label;
}
newArray[newArray.length] = arrayName[i];
}
return newArray;
}
function search(query, callback) {
var terms = $.trim(query).replace(/[\W\s_]+/m,' ').toLowerCase().split(/\s+/);
var matching_ids = null;
for (var i = 0; i < terms.length; i++) {
var term = terms[i];
var exactmatch = index.terms[term] || [];
var approxmatch = index.approximate[term] || [];
var ids = unique(exactmatch.concat(approxmatch));
if (matching_ids) {
matching_ids = $.grep(matching_ids, function(id) {
return ids.indexOf(id) != -1;
});
} else {
matching_ids = ids;
}
}
callback($.map(matching_ids, function(id){ return index.items[id]; }))
}
var index = <%= search_index.to_json %>;