CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

GlobalSearchEngine.php
Go to the documentation of this file.
1 <?PHP
2
3 #
4 # FILE: SPT--GlobalSearchEngine.php
5 #
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/
9 #
10
11 /*
12 OUTSTANDING ISSUES:
13 - search string(s) must be escaped (~XX)
14 - search scores must be normalized
15 */
16
17
18 class GlobalSearchEngine {
19
20 # ---- PUBLIC INTERFACE --------------------------------------------------
21
25 function GlobalSearchEngine()
26 {
27 }
28
39 function Search($SearchString, $StartingResult = 0, $NumberOfResults = 10)
40 {
41 # save start time to use in calculating search time
42 $StartTime = $this->GetMicrotime();
43
44 # create OAI-SQ set specification from search string
45 $SetSpec = "OAI-SQ!".$SearchString;
46
47 # perform global search
48 $SearchResults = $this->PerformSearch(
49 $SetSpec, $StartingResult, $NumberOfResults);
50
51 # record search time
52 $this->LastSearchTime = $this->GetMicrotime() - $StartTime;
53
54 # return results to caller
55 return $SearchResults;
56 }
57
66 function FieldedSearch($SearchStrings, $StartingResult = 0, $NumberOfResults = 10)
67 {
68 }
69
74 function NumberOfResults() { return $this->NumberOfResultsAvailable; }
75
80 function SearchTime()
81 {
82 return $this->LastSearchTime;
83 }
84
85
86 # ---- PRIVATE INTERFACE -------------------------------------------------
87
88 var $NumberOfResultsAvailable;
89 var $LastSearchTime;
90
98 function PerformSearch($SetSpec, $StartingResult, $NumberOfResults)
99 {
100 # for each global search site
101 $DB = new Database();
102 $DB->Query("SELECT * FROM GlobalSearchSites");
103 $SearchResults = array();
104 while ($SiteInfo = $DB->FetchRow())
105 {
106 # retrieve results from site
107 $SiteSearchResults = $this->SearchSite($SiteInfo, $SetSpec);
108
109 # add results to result list
110 $SearchResults = array_merge($SearchResults, $SiteSearchResults);
111 }
112
120 function SearchScoreCmp($ResultA, $ResultB)
121 {
122 return ($ResultA["Search Score"] == $ResultB["Search Score"]) ? 0
123 : (($ResultA["Search Score"] < $ResultB["Search Score"]) ? 1 : -1);
124 }
125 usort($SearchResults, "SearchScoreCmp");
126
127 # save number of results found
128 $this->NumberOfResultsAvailable = count($SearchResults);
129
130 # trim result list to match range requested by caller
131 $SearchResults = array_slice($SearchResults, $StartingResult, $NumberOfResults);
132
133 # return search results to caller
134 return $SearchResults;
135 }
136
143 function SearchSite($SiteInfo, $SetSpec)
144 {
145 # create OAI client and perform query
146 $Client = new OAIClient($SiteInfo["OaiUrl"]);
147 $Client->SetSpec($SetSpec);
148 $QueryResults = $Client->GetRecords();
149
150 # for each result returned from query
151 foreach ($QueryResults as $Result)
152 {
153 # extract and save result data where available
154 unset($ResultData);
155 $ResultData["Title"] =
156 isset($Result["metadata"]["DC:TITLE"][0])
157 ? $Result["metadata"]["DC:TITLE"][0] : NULL;
158 $ResultData["Description"] =
159 isset($Result["metadata"]["DC:DESCRIPTION"][0])
160 ? $Result["metadata"]["DC:DESCRIPTION"][0] : NULL;
161 $ResultData["Url"] =
162 isset($Result["metadata"]["DC:IDENTIFIER"][0])
163 ? $Result["metadata"]["DC:IDENTIFIER"][0] : NULL;
164 $ResultData["Full Record Link"] =
165 isset($Result["about"]["SEARCHINFO"]["FULLRECORDLINK"][0])
166 ? $Result["about"]["SEARCHINFO"]["FULLRECORDLINK"][0] : NULL;
167 $ResultData["Search Score"] =
168 isset($Result["about"]["SEARCHINFO"]["SEARCHSCORE"][0])
169 ? $Result["about"]["SEARCHINFO"]["SEARCHSCORE"][0] : NULL;
170 $ResultData["Cumulative Rating"] =
171 isset($Result["about"]["SEARCHINFO"]["CUMULATIVERATING"][0])
172 ? $Result["about"]["SEARCHINFO"]["CUMULATIVERATING"][0] : NULL;
173 $ResultData["Cumulative Rating Scale"] =
174 isset($Result["about"]["SEARCHINFO"]["CUMULATIVERATINGSCALE"][0])
175 ? $Result["about"]["SEARCHINFO"]["CUMULATIVERATINGSCALE"][0] : NULL;
176
177 # save site info for result
178 $ResultData["Site ID"] = $SiteInfo["SiteId"];
179 $ResultData["Site Name"] = $SiteInfo["SiteName"];
180 $ResultData["Site URL"] = $SiteInfo["SiteUrl"];
181
182 # add result data to search results
183 $SearchResults[] = $ResultData;
184 }
185
186 # return search results to caller
187 return $SearchResults;
188 }
189
194 function GetMicrotime()
195 {
196 list($usec, $sec) = explode(" ", microtime());
197 return ((float)$usec + (float)$sec);
198 }
199 }
200
201
202 ?>
GlobalSearchEngine\FieldedSearch
FieldedSearch($SearchStrings, $StartingResult=0, $NumberOfResults=10)
Performs a search across multiple fields and returns the trimmed results to the caller.
Definition: GlobalSearchEngine.php:66
OAIClient
Definition: OAIClient.php:38
GlobalSearchEngine\$LastSearchTime
$LastSearchTime
Definition: GlobalSearchEngine.php:89
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
GlobalSearchEngine\NumberOfResults
NumberOfResults()
Gets the number of results returned in the last search.
Definition: GlobalSearchEngine.php:74
PHP
PHP
Definition: RSSClient--Test.php:12
GlobalSearchEngine\SearchTime
SearchTime()
Gets the time taken to perform the previous search, in microseconds.
Definition: GlobalSearchEngine.php:80
GlobalSearchEngine\GetMicrotime
GetMicrotime()
Convenience function for getting the time in microseconds.
Definition: GlobalSearchEngine.php:194
GlobalSearchEngine\Search
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).
Definition: GlobalSearchEngine.php:39
GlobalSearchEngine\PerformSearch
PerformSearch($SetSpec, $StartingResult, $NumberOfResults)
Performs an OAI-SQ search.
Definition: GlobalSearchEngine.php:98
GlobalSearchEngine\GlobalSearchEngine
GlobalSearchEngine()
Constructs a GlobalSearchEngine object.
Definition: GlobalSearchEngine.php:25
GlobalSearchEngine\SearchSite
SearchSite($SiteInfo, $SetSpec)
Searches one site with a specification of subset of records to be retrieved.
Definition: GlobalSearchEngine.php:143
GlobalSearchEngine\$NumberOfResultsAvailable
$NumberOfResultsAvailable
Definition: GlobalSearchEngine.php:88
GlobalSearchEngine
Definition: GlobalSearchEngine.php:18