Flow of annotate & percolate actions
- For each search result your action finds, it will call a custom JavaScript function.
- You tell the action the name of the function by passing it as a parameter to the percolate or annotate action.
- When the action calls your custom emitted JavaScript function it passes it the search result DOM object with extracted data tied to the dom using the jQuery function data(). The full URL of the result link and the domain of the link has been extracted for you using this method.
- You can then use the HTML content of the search result and/or the extracted data to make a decision on whether or not to annotate it or percolate depending on the action.
- Select search result for action's action by returning 'true' or reject it by returning 'false' in your function.
Use of regular expression in action function
In my example app below I am using the match() which runs a regular expression on a string and returns true it finds a match.
I am using the regular expression flags of global and case-insensitivity which aren't necessary but I threw them in there to show that it can be done. Would be more useful if I was searching the text of the search result or the URL.
Example function using regex
function findDevex(obj){
return $K(obj).data("domain").match(/stackoverflow/gi);
}
Example percolation app
ruleset a60x17 {
meta {
name "StackOverflow fan"
author "Mike Grace"
description <<
percolating stackoverflow.com search results
>>
logging on
}
dispatch {
domain "google.com"
domain "yahoo.com"
domain "bing.com"
}
rule percolation is active {
select using "google.com|search.yahoo.com|bing.com" setting ()
emit <<
function findDevex(obj){
return $K(obj).data("domain").match(/stackoverflow/gi);
}
>>
percolate(findDevex);
}
}