CLucene PHP wrapper test
Experimental only
Index results:
if ( !cl_new_document($cl) ) echo "
New Document error: ".cl_errstr($cl);
if ( !cl_add_field($cl,"ref", $HTTP_POST_VARS["ndxRef"],true) ) echo "
Reference error: ". cl_errstr($cl);
if ( !cl_add_field($cl,"cnt", $HTTP_POST_VARS["ndxCnt"]) ) echo "
Content error: ". cl_errstr($cl);
echo "Document to add: ".cl_document_info($cl);
if ( !cl_insert_document($cl) )
echo "
Insert error: ". cl_errstr($cl);
else
echo "
Document added!";
?>
}elseif ( $HTTP_POST_VARS["action"] == "search" ){
?>
Search results:
$field = $HTTP_POST_VARS["fld"]."";
if ( $field == "" )
$field = "cnt";
elseif ( strpos($field,",") > 0 )
$field = explode(",",$field);
if ( cl_search($cl, $HTTP_POST_VARS["s"], $field)){
echo "Search found ".cl_hitcount($cl)." documents while searching for ".cl_searchinfo($cl)."
";
do{
echo "Document: ".cl_getfield($cl,"ref")."
";
}while( cl_nexthit($cl) );
}else{
echo "Search failed - ".cl_errstr($cl)."
";
}
?>
}elseif ( $HTTP_POST_VARS["action"] == "optimize" ){
?>
Optimize results:
if ( !cl_optimize($cl) )
echo "Optimize failed: ".cl_errstr($cl);
else
echo "Optimizing successful...";
?>
}elseif ( $HTTP_POST_VARS["action"] == "delete" ){
?>
Delete results:
$ret = cl_delete($cl,$HTTP_POST_VARS["dv"],$HTTP_POST_VARS["d"]);
if ( $ret < 0 ){
echo "Deleting failed: ".cl_errstr($cl);
}else{
echo "Deleted $ret documents.";
}
}else{
echo "Unknown search type.";
}
}else{
echo "Opening ${HTTP_POST_VARS["location"]} failed. - " . cl_errstr($cl) . "
";
}
cl_close($cl);
}
?>
================================
================================