Skip to content

Getting DataparkSearch results in PHP

Below is an example of accessing DataparkSearch Engine results from its searchd daemon in PHP language using RESTfull client and JSON.

httpful PHP library is used as a REST-client library. Simple download this httpful.phar file into the directory where you run this sample. For Linux you may do this with the command:

wget -c

Then you need to have curl and json PHP extensions installed on your system. For Ubuntu Linux you may instal them usin the following command:

sudo apt-get install php5-curl php5-json

This example uses RESTful API provided by searchd daemon of DataparkSearch Engine and a search result template producing JSON file, you can find it in the doc/samples/json.htm inside DataparkSearch distribution package.

As a result of execution of this script a list of page titles along with its URL is printed out followed by the total number of documents in the database for the query given, the time took for the query execution and the range of document numbers shown in the list.


// The host with searchd running
$host = '';

// The category of the results, 09 - for australian sites; this is specific for installation
$_c = '09';
// number of results per page, i.e. how many results will be returned
$_ps = 10;
// result page number, starting with 0
$_np = 0;
// synonyms use flag, 1 - to use, 0 - don't
$_sy = 0;
// word forms use flag, 1 - to use, 0 - don't (search for words in query exactly)
$_sp = 1;
// search mode, can be 'near', 'all', 'any'
$_m = 'near';
// results groupping by site flag, 'yes' - to group, 'no' - don't
$_GroupBySite = 'no';
// search result template 
$_tmplt = 'json2.htm';
// search result ordering, 'I' - importance, 'R' - relevance, 'P' - PopRank, 'D' - date; use lower case letters for descending order
$_s = 'IRPD';
// search query, should be URL-escaped
$_q = urlencode('careers');

$url = $host . '?c=' . $_c 
    . '&ps=' . $_ps 
    . '&np=' . $_np 
    . '&sy=' . $_sy 
    . '&sp=' . $_sp 
    . '&m=' . $_m 
    . '&GroupBySite=' . $_GroupBySite 
    . '&tmplt=' . $_tmplt 
    . '&s=' . $_s 
    . '&q=' . $_q 

$response = \Httpful\Request::get($url)

$result = $response->body->responseData;

foreach ($result->results as $res) {
    echo "{$res->title} => {$res->url}\n";

echo " ** Total {$result->found} documents found in {$result->time} sec.\n";
echo " Displaying documents {$result->first}-{$result->last}.\n";

3 thoughts on “Getting DataparkSearch results in PHP

Leave a Reply

Your email address will not be published.