Skip to main content.
home | support | download

Back to List Archive

Re: [swish-e] Output search results in csv format for download

From: Jordan Hayes <jmhayes(at)>
Date: Fri May 14 2010 - 01:44:09 GMT
>> Is there an option that I am over looking that would
>> allow me to have search results from search.cgi saved
>> to a csv or text file for downloading/saving?
> I know of no feature in search.cgi or swish.cgi like that.

It's not that hard to do, of course.

Here's an example site that allows optional downloading of the results 
of a swish.cgi-a-like in either CSV or PDF:

The meat of the PHP script looks like this:

$results = $sw->execute($term . $xtra);
[ ... ]
[ ... ]
function deliverCSV($results) {
    global $csvCols;

    header("Content-type: application/");
    header("Content-disposition: attachment; filename=afhi-"
      . gmdate("Y-m-d-H-i-s") . ".csv");

    $out = fopen('php://output', 'w');
    fputcsv($out, $csvCols);

    $row = 0;
    while ($r = $results->nextResult()) {
        csvOutputRow($out, $r);
        if ($row > 65000)


And csvOutputRow() looks like this:

function csvOutputRow(&$out, &$r) {
    $line = array(@$r->irisnum, @$r->abstract, @$r->accnotes,
      @$r->accs_date, @$r->accsnrid, @$r->admin,
      @$r->audiorec, @$r->author, @$r->beg_date, @$r->call,
      @$r->circa, @$r->circa_pub, @$r->class, @$r->dnotes,
      @$r->end_date, @$r->frame, @$r->framelst, @$r->fr_doc_id,
      @$r->fr_rware_lib, @$r->index_date, @$r->indexid, @$r->irisref,
      @$r->last_upd_date, @$r->lnft, @$r->main, @$r->majcom,
      @$r->mflm_date, @$r->numpages, @$r->oldacc, @$r->pub_date,
      @$r->qc_comments, @$r->qc_date, @$r->qcid, @$r->rcvd_date,
      @$r->rectype, @$r->reel, @$r->rel_date, @$r->scanned_images,
      @$r->scanrid, @$r->scnd_date, @$r->secinfo, @$r->subject,
      @$r->title, @$r->title_ae, @$r->title_xt);
    fputcsv($out, $line);


Users mailing list
Received on Thu May 13 21:44:12 2010