Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Reflect boneyard status in title

...

KNS includes two actions that annotate search results. These two methods provide a mechanism to annotate search results on Google, Bing, and Yahoo.

Selector Function

These methods take the name of a javascript method that inspects each search result and returns the html for annotation. If no annotation is desired, return false and no annotation will be performed. The annotation method is called once for each search result, and is provided as an argument the DOM element of the search result for your evaluation. You can inspect the DOM element to evaluate the search result, and we also provide common data in a universal way. We recommend using these methods (shown in the example below) instead of extracting the same data yourself.

...

Code Block
languagejavascript
themeConfluence
titleDataset Example
emit <<
function my_select(obj) {
  var domain = $K(obj).data("domain");
  var url = $K(obj).data("url");
  var o = mydataset[domain];
  if(o) {
     return "<span>Found in Dataset!</span>";
  } else {
    false;
  }
}
>>;
annotate_search_results(my_select);

Remote Data

In addition to an annotation method, you can perform a call to a remote service. This is helpful when using a very large dataset because the call is made after the page has loaded and the results are available. The remote data store is queried and passed information about the results that can be used to return specific annotation.

...

Code Block
languagejavascript
themeConfluence
titleAnnotate Remote Decorator
rule annotate_remote_decorator is active {
 
       emit <<
 
      function selector(data) { // data is the data returned by your remote data/script
               return data + "Extra annotation stuff"; 
     }
 
       >>
       annotate_search_results(selector) with remote = "http://www.example.com/path/to/script";
}
 

Annotation Options

The search annotation methods have the following options that can be used to modify default behavior. Options are specified using the withsyntax, as shown in the examples.

...

  • results_lister - (defaults to "li.g, div.g, li div.res, #results>ul>li") - jQuery selector for finding relevant results to annotate. The default finds search results for Google, Yahoo, and Bing.
  • element_to_modify - (defaults to "div.s,div.abstr,p") - the jQuery selector for finding the element to modify within the results returned by the result lister. The default finds the main body of a search result.

Annotating Additional Websites

You may wish to use Search annotation on sites that are not natively supported by the annotation actions. You can extend this functionality onto other websites or customize existing sites by use of the domains option.

Code Block
languagejavascript
themeConfluence
annotate_search_results(my_selector)
  with domains = {"www.ebay.com": { "selector": ".lview.nol",
                                    "modify": "#anchors",
                                    "watcher": "",
                                    "urlSel": ".v4lnk" } };

Advanced CSS Customization

Search annotation can be customized using advanced CSS options. Local search results are not presented in a wrapper, so these options do not apply.

...