Skip to main content.
home | support | download

Back to List Archive

Re: PHP module options

From: David L Norris <dave(at)>
Date: Wed Mar 16 2005 - 05:26:25 GMT
On Tue, 2005-03-15 at 20:24 -0800, Nick Le Mouton wrote:
> Is there some sort of documentation for the PHP module? Reason I'm 
> asking is I'm looking for a method to only return 15 results at a time 
> (paged results).

The Perl API is basically identical to PHP but the function and method
names are formatted according to PHP conventions:

> At the moment I'm getting all the results, putting them into an array 
> and using array_slice() to trim it down to the size I want, but there's 
> gotta be a better way.

Well, that's why there are Seek and Next...  Swish-e library always
returns all results.  Any paging is emulated by the front-end
application.  It is unnecessary to load all of the results into an
array.  You probably only want to work with the results you intend to

Perhaps something like this (totally untested) to return an array of
just the "page" you want (defaulting to page 1 and 15 per page):

function page_results($results, $page_number=1, $per_page=15){
  $start = $per_page * ($page_number - 1);
  $results->seek_result($start);  // Seek to your first entry
  for($i=0; $i < $per_page; $i++){
    $result = $results->next_result();  // get a result object
    $res[$i]['rank'] = $result->property('swishrank');  // rank autoprop
    $res[$i]['path'] = $result->property('swishdocpath'); // filename
    $res[$i]['title'] = $result->property('swishtitle'); // html title
  return $res;

You'd call that like:
  $results = $search->execute();

  $results = $search->execute();
  page_results($results, 2, 25);

 David Norris
  ICQ - 412039
Received on Tue Mar 15 21:26:26 2005