4 # FILE: SPT--GlobalSearchEngine.php 6 # Part of the Collection Workflow Integration System (CWIS) 7 # Copyright 2005-2013 Edward Almasy and Internet Scout Research Group 8 # http://scout.wisc.edu/cwis/ 21 # ---- PUBLIC INTERFACE -------------------------------------------------- 40 public function Search($SearchString, $StartingResult = 0, $NumberOfResults = 10)
42 # save start time to use in calculating search time 43 $StartTime = $this->GetMicrotime();
45 # create OAI-SQ set specification from search string 46 $SetSpec =
"OAI-SQ!".$SearchString;
48 # perform global search 49 $SearchResults = $this->PerformSearch(
50 $SetSpec, $StartingResult, $NumberOfResults);
53 $this->LastSearchTime = $this->GetMicrotime() - $StartTime;
55 # return results to caller 56 return $SearchResults;
65 return $this->NumberOfResultsAvailable;
74 return $this->LastSearchTime;
78 # ---- PRIVATE INTERFACE ------------------------------------------------- 80 private $NumberOfResultsAvailable;
81 private $LastSearchTime;
90 private function PerformSearch($SetSpec, $StartingResult, $NumberOfResults)
92 # for each global search site 94 $DB->Query(
"SELECT * FROM GlobalSearchSites");
95 $SearchResults = array();
96 while ($SiteInfo = $DB->FetchRow())
98 # retrieve results from site 99 $SiteSearchResults = $this->SearchSite($SiteInfo, $SetSpec);
101 # add results to result list 102 $SearchResults = array_merge($SearchResults, $SiteSearchResults);
105 usort($SearchResults,
function ($A, $B) {
109 # save number of results found 110 $this->NumberOfResultsAvailable = count($SearchResults);
112 # trim result list to match range requested by caller 113 $SearchResults = array_slice($SearchResults, $StartingResult, $NumberOfResults);
115 # return search results to caller 116 return $SearchResults;
125 private function SearchSite($SiteInfo, $SetSpec)
127 # create OAI client and perform query 128 $Client =
new OAIClient($SiteInfo[
"OaiUrl"]);
129 $Client->SetSpec($SetSpec);
130 $QueryResults = $Client->GetRecords();
132 # for each result returned from query 133 foreach ($QueryResults as $Result)
135 # extract and save result data where available 137 $ResultData[
"Title"] =
138 isset($Result[
"metadata"][
"DC:TITLE"][0])
139 ? $Result[
"metadata"][
"DC:TITLE"][0] : NULL;
140 $ResultData[
"Description"] =
141 isset($Result[
"metadata"][
"DC:DESCRIPTION"][0])
142 ? $Result[
"metadata"][
"DC:DESCRIPTION"][0] : NULL;
144 isset($Result[
"metadata"][
"DC:IDENTIFIER"][0])
145 ? $Result[
"metadata"][
"DC:IDENTIFIER"][0] : NULL;
146 $ResultData[
"Full Record Link"] =
147 isset($Result[
"about"][
"SEARCHINFO"][
"FULLRECORDLINK"][0])
148 ? $Result[
"about"][
"SEARCHINFO"][
"FULLRECORDLINK"][0] : NULL;
149 $ResultData[
"Search Score"] =
150 isset($Result[
"about"][
"SEARCHINFO"][
"SEARCHSCORE"][0])
151 ? $Result[
"about"][
"SEARCHINFO"][
"SEARCHSCORE"][0] : NULL;
152 $ResultData[
"Cumulative Rating"] =
153 isset($Result[
"about"][
"SEARCHINFO"][
"CUMULATIVERATING"][0])
154 ? $Result[
"about"][
"SEARCHINFO"][
"CUMULATIVERATING"][0] : NULL;
155 $ResultData[
"Cumulative Rating Scale"] =
156 isset($Result[
"about"][
"SEARCHINFO"][
"CUMULATIVERATINGSCALE"][0])
157 ? $Result[
"about"][
"SEARCHINFO"][
"CUMULATIVERATINGSCALE"][0] : NULL;
159 # save site info for result 160 $ResultData[
"Site ID"] = $SiteInfo[
"SiteId"];
161 $ResultData[
"Site Name"] = $SiteInfo[
"SiteName"];
162 $ResultData[
"Site URL"] = $SiteInfo[
"SiteUrl"];
164 # add result data to search results 165 $SearchResults[] = $ResultData;
168 # return search results to caller 169 return $SearchResults;
176 private function GetMicrotime()
178 list($usec, $sec) = explode(
" ", microtime());
179 return ((
float)$usec + (
float)$sec);
SQL database abstraction object with smart query caching.
static SortCompare($A, $B)
Perform compare and return value appropriate for sort function callbacks.
NumberOfResults()
Gets the number of results returned in the last search.
SearchTime()
Gets the time taken to perform the previous search, in microseconds.
__construct()
Constructs a GlobalSearchEngine object.
Search($SearchString, $StartingResult=0, $NumberOfResults=10)
Performs a keyword search using a specified search string and returns the results, starting with the one numbered with the starting result (default 0) and continuing until reaching the desired number of results (default 10).