Created
September 22, 2015 16:43
-
-
Save dmcassel/1d4bbc2fe8f7e04ff54d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This could be any query. Here we've simplified to a single word query. | |
var query = "flannel"; | |
var results = []; // Accumulator for result snippets | |
for(var doc of cts.search(query)) { | |
var builder = new NodeBuilder(); | |
// The callback is the function that's executed when highlight finds a match | |
// to the query | |
function callback(builder, text, node, queries, start) { | |
builder.addNode({"match": text}); | |
}; | |
cts.highlight( | |
// Project some of the fields of the matched documents into new JavaScript | |
// object and continue highlighting. | |
{ | |
"guid": doc.root.guid, | |
"about": doc.root.about, | |
}, query, callback, builder | |
); | |
results.push(builder.toNode()); | |
} | |
results; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment