Search API Guide

Table of Contents

  1. Introduction
  2. Creating a Request Object
    1. Using Presets
    2. Adding Project Filters
  3. Running a Search Using the Request Object
  4. Processing the Results

Introduction

The SDR Search Service API is a set of classes that interface with the SDR XML Search Service. Through these classes, your web app can easily perform search queries or fetch metadata from SDR.

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.

Creating a Request Object

Before you run any query using the SDRSearchService, you will want to create a new SDRServiceRequest object representing your search request.

$req = new SDRServiceRequest();

Using Presets

If you are performing a routine type of search, you can use the search type presets.

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 Project Filters

If you want to limit your results so that only resources associated with a particular set of projects are returned, you can use project filters. In almost all cases, you will want to filter your results to one or several projects.

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.

Running a Search Using the Request Object

There are many ways to run a search using SDRSearchService. Here's a simple way:
$result = SDRSearchService::getResourceResponse($req);

Processing the Results


Generated on Wed Nov 24 02:01:29 2010 for Common by  doxygen 1.5.6