forked from DigitalAustinPapers/DigitalAustinSite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_results.php
68 lines (53 loc) · 2.18 KB
/
search_results.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
61
62
63
64
65
66
67
68
<?php
// Most of this logic was previously in /data/search.php. The original
// intent was to include search_results.php in /data/search.php. That
// proved difficult because of include paths.
// This script is responsible for taking a query from the user and generating
// a JSON array containing the results.
//
// The results are based on the following fields in the GET data:
// query - The text that the user is searching for. This text will
// be split on non-word characters and then stemmed.
// location - A place ID. If given and not -1, results will only be
// returned if they were either sent from or to the specified location
//
// Example potential output:
// [{"id": 4321, "title":"First Result Title",
// "summary":"This is a summary of the first
// result", "date":"2012-5-16", "cityId":1234}]
//
// Returns an array of character n-grams from the target string
session_start();
require_once('vendor/autoload.php');
require_once 'src/TemplateRenderer.class.php';
include 'php/porterStemmer.php';
include_once 'php/database.php';
include 'data/query.php';
logString("search.php start");
$database = connectToDB();
$sql = buildDocumentSearchQuery();
$docData = array();
$sentimentScores = array();
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or die($sql . "<br>" . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
while ($row = mysqli_fetch_assoc($result))
{
array_push($docData, $row);
array_push($sentimentScores, $row['sentimentScore']);
}
logString("search.php end");
$search_results = array();
$template = new TemplateRenderer();
if(count($sentimentScores) > 0) {
$min_sentiment = min($sentimentScores);
$max_sentiment = max($sentimentScores);
}
foreach ($docData as $result_key => $result_value) {
$rendered_template = $template->render('_search_result.twig', array(
'result' => $result_value,
'min_sentiment' => $min_sentiment,
'max_sentiment' => $max_sentiment,
));
array_push($search_results, $rendered_template);
}
print json_encode(array('json'=> $docData,
'html'=> $search_results));