Skip to content

Instantly share code, notes, and snippets.

@KeithHanson
Forked from ecton/snippet.js
Created August 20, 2009 22:40
Show Gist options
  • Save KeithHanson/171477 to your computer and use it in GitHub Desktop.
Save KeithHanson/171477 to your computer and use it in GitHub Desktop.
function splitAndScoreText(results, text, score) {
if (text != null) {
var words = text.replace(/[^\w]+/g," ").toLowerCase().split(" ");
for (var word in words) {
if (words[word].length > 1) {
if ("a,about,an,and,are,as,at,be,by,from,how,i,in,is,it,of,on,or,that,the,this,to,was,we,what,when,where,which,with".search(words[word]) < 0) {
results[words[word]] = (results[words[word]] || 0) + score;
}
}
}
}
}
function(doc) {
if (doc['couchrest-type'] == "Exhibitor") {
var seenWords = {};
splitAndScoreText(seenWords, doc.name, 100);
splitAndScoreText(seenWords, doc.description, 1);
for (var word in seenWords) {
emit([word, seenWords[word]], null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment