category breakdown
[contractdashboard.git] / solr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
 
include_once ("./lib/common.inc.php");
 
// create a ping query
$ping = $solr_client->createPing();
 
// execute the ping query
try {
    $result = $solr_client->ping($ping);
    echo 'Ping query successful';
    echo '<br/><pre>';
    var_dump($result->getData());
    echo '</pre>';
} catch (Solarium\Exception $e) {
    echo 'Ping query failed';
}
 
 
$update = $solr_client->createUpdate();
$update->addCommit();
 
// this executes the query and returns the result
$result = $solr_client->update($update);
 
echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime();
   
$buffer = $solr_client->getPlugin('bufferedadd');
$buffer->setBufferSize(500); 
$page = 583728;
while ($conn) {
    echo ($page++).PHP_EOL;
    $stmt = $conn->prepare('SELECT * FROM contractnotice ORDER BY "CNID" LIMIT 1000 OFFSET '.($page*1000));
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
 
 
// create a new document for the data
$data = array("id" => $row["CNID"]);
foreach ($row as $key => $value) {
if ($key != 'atmID' && $key != 'CNID' && $key != 'supplierPostcode' && $key != 'contactPostcode') {
if ($key == 'value') {
$value = intval($value);
} 
if ($key == 'publishDate' || $key == 'importDate') {
$value = explode(" ",$value)[0];
}
$value = preg_replace( '/[^[:print:]]/', '',$value);
$data[$key] = $value;
}
//print_r($data);
 $buffer->createDocument($data);
}
}
}
$buffer->flush();