(Classic) percolate()

Engine Compatibility

percolate is not supported by the Node engine.

percolate(<js_function>)

The percolate action iterates through search results on the current page as well as pages after the current page. Currently the percolate action takes a javascript function as its parameter. This function is run for each search result with the result being passed in as a parameter. A search result is percolated, or brought to the top, when the function passed to the action returns true. To start off, lets take a simple example and explain it:

ruleset a1299x177 {
	meta {
		name "percolate example"
		author "nathan cerny"
		logging off
	}
	dispatch {
		// domain "exampley.com"
	}
	rule percolate is active {
        select using "google.com|search.yahoo.com|bing.com" setting ()
    
    emit <<
     
        var perc_data = ["www.windley.com"];
     
        function perc_filter(obj){
            var host = $K(obj).data("domain");
            var o = perc_data.indexOf(host);
            if(o !== -1){
                return true;
            } else {
                return false;
            }
        }
    
    >>;
     
    percolate(perc_filter);
    
    }
}

Now let's break this simple percolation example down: the first part of the rule,

select using "google.com|search.yahoo.com|bing.com" setting()

tells the rule what domains to fire on, in this particular select statement, we use the regex OR symbol "|" to tell this rule to fire on any of the sites in the statement.

The next part of the rule takes place in an

emit << >>

block. This allows us to code Javascript directly into our rule.

Inside of our emit block, we code a function that defines how search resultes are percolated, this is the beauty of the percolate action, you write our own function that fully customizes the way that the search percolation happens. The percolate action simply takes your custom function as a parameter.

In the above specific percolation example, we just implement a simple domain check. First note that your percolation function takes a parameter, and then that parameter is used to pull information using the .data() method. The .data() method only works like this when your percolation function is used with the KRL action, percolate. In this example, we check the domain of the current search result, and if it matches "kynetx.com", we return true, which tells the percolate action to percolate it.

There are infinitely many ways one can design their custom percolate function, one way is to run through a JSON object, and if the key is found, percolate it.

The following ruleset shows percolate() being used

ruleset a1299x177 {
	meta {
		name "percolate example"
		author "nathan cerny"
		logging off
	}
	dispatch {
		// domain "exampley.com"
	}
	rule percolate is active {
        select using "google.com|search.yahoo.com|bing.com" setting ()
    
    emit <<
     
        var perc_data = ["www.windley.com"];
     
        function perc_filter(obj){
            var host = $K(obj).data("domain");
            var o = perc_data.indexOf(host);
            if(o !== -1){
                return true;
            } else {
                return false;
            }
        }
    
    >>;
     
    percolate(perc_filter);
    
    }
}

 

 

Copyright Picolabs | Licensed under Creative Commons.