Using the SDRServiceRequest object, the Search API generates the request that should be made to the SDR XML Service and runs that request. Depending on which function you use, it can return the XML response directly, or it can parse the response into a number of data objects.
$req = new SDRServiceRequest();
For example, for quick search, you could specify the PRESET_FIND_QUICK type, and then pass in the required parameters -- a search string (ss), and a starting result (sr). The starting result is used to skip into the middle of a set of results for the purpose of pagination.
$req->usePreset(SDRServiceRequest::PRESET_FIND_QUICK, array('ss' => $query, 'sr' => $sr));
Adding a filter for the CSERD project means limiting your search to items that are approved to be publicly searched across Shodor and NSDL.
For instance, there are activity, lesson, discussion, and worksheet resources, all associated with the Interactivate project. We want to be able to search for activities, lessons, and discussions in the Interactivate site search, in CSERD, and in NSDL. However, while we want to keep metadata associated with worksheets, we don't want them showing up in most search interfaces. Therefore, the Interactivate activities, lessons, and discussions are also added to the CSERD project, while the worksheets are not.
On the Interactivate search page, to limit our search to items that are in both Interactivate and CSERD (i.e., items in the Interactivate project that are available for public searching), we would set the following filters on our request:
$req->addProjectFilter(SDRContract::PROJECT_INTERACTIVATE);
$req->addCSERDFilter();
$req->setFilterProjectType('and');
Calling addCSERDFilter() is just a shortcut for:
$req->addProjectFilter(SDRContract::PROJECT_CSERD);
If we had wanted to search the union rather than the intersection of Interactivate and CSERD, we would have instead set the project filter type to "or." This can be useful in search pages that bring together multiple projects as sources.
$req->setFilterProjectType('or');
There is no way at the moment to search on the union of multiple projects while requiring that all results be in CSERD.
$result = SDRSearchService::getResourceResponse($req);