unspsc update
[contractdashboard.git] / search.php
blob:a/search.php -> blob:b/search.php
<?php <?php
   
/* /*
search ABNs search ABNs
search agency name search agency name
search categories search categories
search supplier names search supplier names
--search supplier postcodes/suburbs/cities-- --search supplier postcodes/suburbs/cities--
search CN number search CN number
search description full text search description full text
*/ */
include('./lib/common.inc.php'); include('./lib/common.inc.php');
if ($_REQUEST['searchID']) { if ($_REQUEST['searchID']) {
$searchIDParts = explode("-", $_REQUEST['searchID']); $searchIDParts = explode("-", $_REQUEST['searchID']);
$type = array_shift($searchIDParts); $type = array_shift($searchIDParts);
$host = $_SERVER['HTTP_HOST']; $host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
   
if ($type == "agency") { if ($type == "agency") {
header("Location: http://$host$uri/displayAgency.php?agency=" . implode("-", $searchIDParts)); header("Location: http://$host$uri/displayAgency.php?agency=" . implode("-", $searchIDParts));
} }
if ($type == "supplier") { if ($type == "supplier") {
header("Location: http://$host$uri/displaySupplier.php?supplier=" . implode("-", $searchIDParts)); header("Location: http://$host$uri/displaySupplier.php?supplier=" . implode("-", $searchIDParts));
} }
if ($type == "cnid") { if ($type == "cnid") {
header("Location: http://$host$uri/displayContract.php?CNID=" . implode("-", $searchIDParts)); header("Location: http://$host$uri/displayContract.php?CNID=" . implode("-", $searchIDParts));
} }
exit; exit;
} else { } else {
include_header("Search Results"); include_header("Search Results");
/*// get a select query instance /*// get a select query instance
$query = $solr_client->createSelect(); $query = $solr_client->createSelect();
   
// set a query (all prices starting from 12) // set a query (all prices starting from 12)
$query->setQuery($_REQUEST['searchKeyword']); $query->setQuery($_REQUEST['searchKeyword']);
   
// set start and rows param (comparable to SQL limit) using fluent interface // set start and rows param (comparable to SQL limit) using fluent interface
$query->setStart(0)->setRows(100); $query->setStart(0)->setRows(100);
   
// set fields to fetch (this overrides the default setting 'all fields') // set fields to fetch (this overrides the default setting 'all fields')
$query->setFields(array('id','description','value','agencyName','contractStart','supplierName', 'score')); $query->setFields(array('id','description','value','agencyName','contractStart','supplierName', 'score'));
   
// sort the results by price ascending // sort the results by price ascending
//$query->addSort('price', $query::SORT_ASC); //$query->addSort('price', $query::SORT_ASC);
   
// this executes the query and returns the result // this executes the query and returns the result
$resultset = $solr_client->select($query); $resultset = $solr_client->select($query);
   
// display the total number of documents found by solr // display the total number of documents found by solr
echo 'Found '.$resultset->getNumFound(). ' results. <table>'; echo 'Found '.$resultset->getNumFound(). ' results. <table>';
   
foreach ($resultset as $row) { foreach ($resultset as $row) {
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value'][0]), 2); $value = number_format(doubleval($row['value'][0]), 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['id']}\">{$row['id']}</a></td> <td><a href=\"displayContract.php?CNID={$row['id']}\">{$row['id']}</a></td>
<td><b>{$row['description'][0]}</b></a></td> <td><b>{$row['description'][0]}</b></a></td>
<td>\$$value</td><td>{$row['agencyName'][0]}</td> <td>\$$value</td><td>{$row['agencyName'][0]}</td>
<td>{$row['contractStart'][0]}</td> <td>{$row['contractStart'][0]}</td>
<td>{$row['supplierName'][0]}</td> <td>{$row['supplierName'][0]}</td>
</tr>"); </tr>");
   
*/ */
$keyword = $_REQUEST['searchKeyword']; $keyword = $_REQUEST['searchKeyword'];
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice FROM contractnotice
WHERE ' .$yearQ . ' to_tsvector(\'english\', description) @@ plainto_tsquery(\'english\', :keyword) and "childCN" is null WHERE ' .$yearQ . ' to_tsvector(\'english\', description) @@ plainto_tsquery(\'english\', :keyword) and "childCN" is null
ORDER BY "value" DESC limit 100'; ORDER BY "value" DESC limit 1000';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":keyword", $keyword); $query->bindParam(":keyword", $keyword);
$query->execute(); $query->execute();
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
  if ($query->rowCount() > 999) {
  // if 1000 records warn too many results
  print "<b> More than 1000 results found so only first 1000 shown. Please filter by year or keyword to see all results </b>";
  }
echo '<table>'; echo '<table>';
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
//print_r($row); //print_r($row);
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format($row['value'], 2); $value = number_format($row['value'], 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></td> <td><b>{$row['description']}</b></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
   
include_footer(); include_footer();
} }
?> ?>