Skip to content

Commit

Permalink
style: swap spaces for tabs when indenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chloe070196 committed Sep 3, 2024
1 parent ae0ff69 commit 505f03d
Showing 1 changed file with 100 additions and 100 deletions.
200 changes: 100 additions & 100 deletions code/web/sys/SearchObject/SummonSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@

class SearchObject_SummonSearcher extends SearchObject_BaseSearcher{

static $instance;
static $instance;
/** @var SummonSettings */
private $summonBaseApi ='http://api.summon.serialssolutions.com';
private $summonBaseApi ='http://api.summon.serialssolutions.com';

/**Build URL */
private $sessionId;
private $version = '2.0.0';
private $service = 'search';
private $responseType = "json";
private $sessionId;
private $version = '2.0.0';
private $service = 'search';
private $responseType = "json";

private static $searchOptions;
private $curl_connection;
private static $searchOptions;
private $curl_connection;

/**Track query time info */
protected $queryStartTime = null;
protected $queryStartTime = null;
protected $queryEndTime = null;
protected $queryTime = null;

// STATS
// STATS
protected $resultsTotal = 0;

protected $searchTerms;

protected $lastSearchResults;

// Module and Action for building search results
// Module and Action for building search results
protected $resultsModule = 'Search';
protected $resultsAction = 'Results';

/** @var string */
/** @var string */
protected $searchSource = 'local';
protected $searchType = 'basic';
protected $searchType = 'basic';

/** Values for the options array*/
protected $holdings = true;
Expand Down Expand Up @@ -105,15 +105,15 @@ class SearchObject_SummonSearcher extends SearchObject_BaseSearcher{

protected $facetFields;

public function __construct() {
//Initialize properties with default values
$this->searchSource = 'summon';
$this->searchType = 'summon';
$this->resultsModule = 'Summon';
$this->resultsAction = 'Results';
public function __construct() {
//Initialize properties with default values
$this->searchSource = 'summon';
$this->searchType = 'summon';
$this->resultsModule = 'Summon';
$this->resultsAction = 'Results';
}
/**
/**
* Initialise the object from the global
* search parameters in $_REQUEST.
* @access public
Expand Down Expand Up @@ -182,9 +182,9 @@ private function getSettings() {
AspenError::raiseError(new AspenError('There are no Summon Settings set for this library system.'));
}

public function getCurlConnection() {
public function getCurlConnection() {
if ($this->curl_connection == null) {
$this->curl_connection = curl_init();
$this->curl_connection = curl_init();
curl_setopt($this->curl_connection, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($this->curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($this->curl_connection, CURLOPT_RETURNTRANSFER, true);
Expand All @@ -208,16 +208,16 @@ public function getHeaders() {
/**
* Use Institution's Summon API credentials to authenticate and allow connection with the Summon API
*/
public function authenticate($settings, $queryString) {
public function authenticate($settings, $queryString) {
$headers = $this->getHeaders();
$data = implode("\n", $headers). "\n/$this->version/search\n" . urldecode($queryString) . "\n";
$hmacHash = $this->hmacsha1($settings->summonApiPassword, $data);
$headers['Authorization'] = "Summon $settings->summonApiId;$hmacHash";
if (!is_null($this->sessionId)){
$headers['x-summon-session-id'] = $this->sessionId;
}
if (!is_null($this->sessionId)){
$headers['x-summon-session-id'] = $this->sessionId;
}
return $headers;
}
}

public function getSort() {
$this->sortOptions = array(
Expand Down Expand Up @@ -312,7 +312,7 @@ public function splitFacets($combinedFacets) {
return $splitFacets;
}

/**
/**
* Return an array of data summarising the results of a search.
*
* @access public
Expand Down Expand Up @@ -357,7 +357,7 @@ public function renderLinkPageTemplate() {
return $url;
}

/**
/**
* Use the record driver to build an array of HTML displays from the search
* results. Called by results.php.
*
Expand Down Expand Up @@ -388,7 +388,7 @@ public function getResultRecordHTML() {
return $html;
}

/**
/**
* Use the record driver to build an array of HTML displays from the search
* results.
*
Expand Down Expand Up @@ -582,7 +582,7 @@ public function getSummonFilters() {
* @param string $key Hash key
* @param string $data Data to hash
*
* @return string Generated hash
* @return string Generated hash
*/
protected function hmacsha1($key, $data) {
$blocksize=64;
Expand Down Expand Up @@ -639,67 +639,67 @@ public function sendRequest() {
return $recordData;
}

public function process($input, $textQuery = null) {
public function process($input, $textQuery = null) {
// if no search options are found, assing them
// alternatively, if the search options do not match the current search, update them
if (SearchObject_SummonSearcher::$searchOptions == null ||
if (SearchObject_SummonSearcher::$searchOptions == null ||
SearchObject_SummonSearcher::$searchOptions['textQuery'] != $textQuery ) {
if ($this->responseType != 'json') {
return $input;
}
SearchObject_SummonSearcher::$searchOptions = json_decode($input, true);
if (!SearchObject_SummonSearcher::$searchOptions) {
SearchObject_SummonSearcher::$searchOptions = array(
'recordCount' => 0,
'documents' => array(),
'errors' => array(
array(
'code' => 'PHP-Internal',
'message' => 'Cannot decode JSON response: ' . $input
)
)
);
}
// Detect errors
if (isset(SearchObject_SummonSearcher::$searchOptions['errors']) && is_array(SearchObject_SummonSearcher::$searchOptions['errors'])) {
foreach (SearchObject_SummonSearcher::$searchOptions['errors'] as $current) {
$errors[] = "{$current['code']}: {$current['message']}";
}
$msg = 'Unable to process query<br />Summon returned: ' .
implode('<br />', $errors);
throw new Exception($msg);
}
if (SearchObject_SummonSearcher::$searchOptions) {
return SearchObject_SummonSearcher::$searchOptions;
} else {
return null;
}
} else {
return SearchObject_SummonSearcher::$searchOptions;
}
}

/**
if ($this->responseType != 'json') {
return $input;
}
SearchObject_SummonSearcher::$searchOptions = json_decode($input, true);
if (!SearchObject_SummonSearcher::$searchOptions) {
SearchObject_SummonSearcher::$searchOptions = array(
'recordCount' => 0,
'documents' => array(),
'errors' => array(
array(
'code' => 'PHP-Internal',
'message' => 'Cannot decode JSON response: ' . $input
)
)
);
}
// Detect errors
if (isset(SearchObject_SummonSearcher::$searchOptions['errors']) && is_array(SearchObject_SummonSearcher::$searchOptions['errors'])) {
foreach (SearchObject_SummonSearcher::$searchOptions['errors'] as $current) {
$errors[] = "{$current['code']}: {$current['message']}";
}
$msg = 'Unable to process query<br />Summon returned: ' .
implode('<br />', $errors);
throw new Exception($msg);
}
if (SearchObject_SummonSearcher::$searchOptions) {
return SearchObject_SummonSearcher::$searchOptions;
} else {
return null;
}
} else {
return SearchObject_SummonSearcher::$searchOptions;
}
}

/**
* Send HTTP request with headers modified to meet Summon API requirements
*/
protected function httpRequest($baseUrl, $queryString, $headers) {
protected function httpRequest($baseUrl, $queryString, $headers) {
foreach ($headers as $key =>$value) {
$modified_headers[] = $key.": ".$value;
}
$curlConnection = $this->getCurlConnection();
$curlOptions = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "{$baseUrl}?{$queryString}",
CURLOPT_HTTPHEADER => $modified_headers
);
curl_setopt_array($curlConnection, $curlOptions);
$result = curl_exec($curlConnection);
if ($result === false) {
throw new Exception("Error in HTTP Request.");
}
// curl_close($curlConnection);
return $result;
}
$curlConnection = $this->getCurlConnection();
$curlOptions = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "{$baseUrl}?{$queryString}",
CURLOPT_HTTPHEADER => $modified_headers
);
curl_setopt_array($curlConnection, $curlOptions);
$result = curl_exec($curlConnection);
if ($result === false) {
throw new Exception("Error in HTTP Request.");
}
// curl_close($curlConnection);
return $result;
}

/**
* Start the timer to work out how long a query takes. Complements
Expand Down Expand Up @@ -735,32 +735,32 @@ public function getQuerySpeed() {
/**
* Search indexes
*/
public function getSearchIndexes() {
public function getSearchIndexes() {
return [
"Title" => translate([
'text' => "Title",
'isPublicFacing' => true,
'inAttribute' => true,
]),
'All Text' => translate([
'text' => "All Text",
'All Text' => translate([
'text' => "All Text",
'isPublicFacing' => true,
'inAttribute' => true,
]),
'Keyword' => translate([
'text' => "Keyword",
'isPublicFacing' => true,
'inAttribute' => true,
]),
'Keyword' => translate([
'text' => "Keyword",
'isPublicFacing' => true,
'inAttribute' => true,
])
])
];
}
}

//Default search index
public function getDefaultIndex() {
public function getDefaultIndex() {
return $this->searchIndex;
}

public function setSearchTerm() {
public function setSearchTerm() {
if (strpos($this->searchTerms, ':') !== false) {
[
$searchIndex,
Expand All @@ -778,7 +778,7 @@ public function setSearchTerm() {
}
}

public function getIndexError() {
public function getIndexError() {
// TODO: Implement getIndexError() method.
}

Expand Down Expand Up @@ -806,7 +806,7 @@ function loadDynamicFields() {
// TODO: Implement loadDynamicFields() method.
}

public function getEngineName() {
public function getEngineName() {
return 'summon';
}

Expand All @@ -823,7 +823,7 @@ public function getresultsTotal(){
}

public function processSearch($returnIndexErrors = false, $recommendations = false, $preventQueryModification = false) {
}
}

public function __destruct() {
if ($this->curl_connection) {
Expand Down

0 comments on commit 505f03d

Please sign in to comment.