Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Created September 22, 2015 16:43
Show Gist options
  • Save dmcassel/1d4bbc2fe8f7e04ff54d to your computer and use it in GitHub Desktop.
Save dmcassel/1d4bbc2fe8f7e04ff54d to your computer and use it in GitHub Desktop.
// 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