2

1

I am requesting a Basic/Intermediate Example of Annotate using:

test = foo.text()search(regex).  

I think I am beginning to understand how percolate/annotate works using jquery. I think an example using regular expression would help me apply it to a rule.

Thanks.

flag
Thanks. The two examples shows two sets of data being searched, first Mike's shows searching just the domain element within the object and Jams shows searching the entire text of the object (title, body, domain). Provided I understand it correctly. – Nate Mar 10 at 15:39

2 Answers

2

Here's a simple example:

select using ".*" setting()

emit <<

function percolate_select_function(obj){
   var regex_test = $K(obj).text().test(/ebay.com/);

   if(regex_test){
      return true;
   } else {
      return false;
   }
}

>>

percolate(percolate_select_function)
link|flag
1 
+1 for clear and concise answer. – Alex Mar 10 at 2:06
1 
+1 for doing it differently than me. : ) – Mike Grace Mar 10 at 2:51
Thanks Jam & Mike. Great help. – Nate Mar 10 at 15:28
0

Flow of annotate & percolate actions

  1. For each search result your action finds, it will call a custom JavaScript function.
  2. You tell the action the name of the function by passing it as a parameter to the percolate or annotate action.
  3. 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.
  4. 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.
  5. 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);
  }
}
link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.