YAZ language searching/filtering
Posted: Thu Jul 09, 2009 3:20 pm
Hi,
I am implementing Z39.50 through YAZ PHP.
And I have a problem with add language filter to the results. I attached my searching function at the bottom of this email. And below is the line of code to do the language filter:
$bib1['lang'] = "u=54 s=pw";
The host I am using is congress of library :
$libraries['Congress'] = "z3950.loc.gov:7090/voyager";
And the query string (query_str) I passed to the function is " term=green and term=energy and lang=eng".
Without the language (term=green and term=energy), it works fine, I compare the searching result against loc.gov guided searchi. Once I added the language condition, the result is wrong, which gives me either the items in non-english language or very less result.
Please point out what is the problem of my code! it would be supper great if you have a sample code!
Thanks a million!
Best regards,
Alan Shen
=============================== code ===============================
function yaz_find_records($host, $query_str, $start_index, $maxrec)
{
//return data
$collection = array();
$bib1["term"] = "u=1016 s=pw t=l,r=102";
$bib1["ti"] = "u=4 s=pw t=l,r=103"; //title
$bib1["au"] = "u=1003 s=pw t=l,r=103"; //author
$bib1["ab"] = "u=62 s=pw t=l,r=102";
$bib1["isbn"] = "u=7 s=pw";
$bib1['ean'] = "u=1214 s=pw";
$bib1['lang'] = "u=54 s=pw";
$bib1['dat'] = "u=31,r=5";
$bibl['callnumb'] = "u=16 s=pw"; //unknow qualifer
$id = yaz_connect($host);
$cclresult = "";
yaz_ccl_conf($id, $bib1);
if (!yaz_ccl_parse($id, $query_str, $cclresult)) {
/*
echo 'Error: ' .
$cclresult["errorstring"] . '<br>';*/
return;
}
yaz_element($id, 'f'); //F for full B for brief
yaz_syntax($id,"usmarc");
yaz_sort($id, "u=4");
yaz_search($id,"rpn",$cclresult["rpn"]);
yaz_wait();
$count=yaz_hits($id);
if ($start_index > $count)
{
return;
}
if ($start_index + $maxrec - 1 > $count)
$maxrec = $count - $start_index + 1;
yaz_range($id, $start_index, $maxrec);
yaz_present($id);
yaz_wait();
$error = yaz_error($id);
if (!empty($error))
{
echo "Error: $error";
return;
} else
$i = 0;
for ($p = $start_index; $p < $start_index+$maxrec; $p++)
{
//$rec = yaz_record($id,$p,"xml");
$rec = yaz_record($id,$p,"xml");
if (empty($rec)) continue;
$collection[$i] = $rec;
$i++;
}
$ret = array(
'collection' => $collection,
'count' => yaz_hits($id));
return $ret;
}
I am implementing Z39.50 through YAZ PHP.
And I have a problem with add language filter to the results. I attached my searching function at the bottom of this email. And below is the line of code to do the language filter:
$bib1['lang'] = "u=54 s=pw";
The host I am using is congress of library :
$libraries['Congress'] = "z3950.loc.gov:7090/voyager";
And the query string (query_str) I passed to the function is " term=green and term=energy and lang=eng".
Without the language (term=green and term=energy), it works fine, I compare the searching result against loc.gov guided searchi. Once I added the language condition, the result is wrong, which gives me either the items in non-english language or very less result.
Please point out what is the problem of my code! it would be supper great if you have a sample code!
Thanks a million!
Best regards,
Alan Shen
=============================== code ===============================
function yaz_find_records($host, $query_str, $start_index, $maxrec)
{
//return data
$collection = array();
$bib1["term"] = "u=1016 s=pw t=l,r=102";
$bib1["ti"] = "u=4 s=pw t=l,r=103"; //title
$bib1["au"] = "u=1003 s=pw t=l,r=103"; //author
$bib1["ab"] = "u=62 s=pw t=l,r=102";
$bib1["isbn"] = "u=7 s=pw";
$bib1['ean'] = "u=1214 s=pw";
$bib1['lang'] = "u=54 s=pw";
$bib1['dat'] = "u=31,r=5";
$bibl['callnumb'] = "u=16 s=pw"; //unknow qualifer
$id = yaz_connect($host);
$cclresult = "";
yaz_ccl_conf($id, $bib1);
if (!yaz_ccl_parse($id, $query_str, $cclresult)) {
/*
echo 'Error: ' .
$cclresult["errorstring"] . '<br>';*/
return;
}
yaz_element($id, 'f'); //F for full B for brief
yaz_syntax($id,"usmarc");
yaz_sort($id, "u=4");
yaz_search($id,"rpn",$cclresult["rpn"]);
yaz_wait();
$count=yaz_hits($id);
if ($start_index > $count)
{
return;
}
if ($start_index + $maxrec - 1 > $count)
$maxrec = $count - $start_index + 1;
yaz_range($id, $start_index, $maxrec);
yaz_present($id);
yaz_wait();
$error = yaz_error($id);
if (!empty($error))
{
echo "Error: $error";
return;
} else
$i = 0;
for ($p = $start_index; $p < $start_index+$maxrec; $p++)
{
//$rec = yaz_record($id,$p,"xml");
$rec = yaz_record($id,$p,"xml");
if (empty($rec)) continue;
$collection[$i] = $rec;
$i++;
}
$ret = array(
'collection' => $collection,
'count' => yaz_hits($id));
return $ret;
}