Post Reply 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search via API
07-22-2013, 10:59 PM
Post: #1
Search via API
As of clearFusionCMS 1.3.0 we expose an API, one of the features of the API is that you can perform searches on remote installs of the CMS.

The following snippet can be placed on an existing search results page to search a remote install and display the top 3 results.
PHP Code:
$request $tplEngine->controller->getRequest();
$q $request->getQuery('q')) && !$request->hasQuery('page')) {
$resultTpl = isset($resultTpl) ? $tplEngine->getChunk($resultTpl) : '<li><a href="[[+link]]">[[+title]]</a><p>[[+summary]]</p></li>';
$wrapperTpl = isset($wrapperTpl) ? $tplEngine->getChunk($wrapperTpl) : '<ul>[[+results]]</ul>';
$client = new flHttpClient('');
$client->setAuth('your API key''')
'q' => $q,
'pageSize' => 3

$client->sendRequest(flHttpClient::GET) && $client->getResponseCode() == 200) {
$r json_decode($client->getBody());
$r->totalMatches) {
"<h2>Results from the remote install</h2>";
'<p>' $r->totalMatches ' results found, <a href="' urlencode($q) . '">Search again on remote site</a>?</p>';
$html '';
$r->results as $result) {
$html .= $tplEngine->parseString($resultTpl, array(
'link' => $result->link,
'title' => $result->title,
'summary' => $result->summary
$tplEngine->parseString($wrapperTpl, array('results' => $html));
    } must be replaced with the address of the site to run the search on.
'your API key' must be replaced with a valid API key from the installation receiving the search request.

You can see this feature in use on as when you search it also performs the search on the user guide hosted at

clearFusionCMS Lead Developer
Find all posts by this user
Quote this message in a reply
Post Reply 

Forum Jump:

User(s) browsing this thread: 1 Guest(s)