04: SEARCHING & BROWSING YOUR COLLECTIONS

dmQuery is a powerful search utility, with a variety of parameters. This is part one of a discussion about dmQuery.

API: dmQuery

INVOKED (from OCLC’s own site): http://CdmServer.com:port/dmwebservices/index.php?q=dmQuery/alias/searchstrings/fields/sortby/
maxrecs/start/suppress/docptr/suggest/facets/showunpub/denormalizeFacets/format

  • alias is a single collection alias, a !-delimited list of collection aliases, or “all” for all collections.
  • searchstrings is a four-part, ^-delimited group in the order field^string^mode^operator.Use “CISOSEARCHALL” for all fields; mode can be “all”, “any”, “exact”, or “none”; operator can be “and” or “or”.Multiple words in string need to be separated by “+”.Up to six groups can be included, delimited by “!”.To browse a collection, specify a single alias and “0” as a searchstrings value. The operator for the last searchstring will be ignored.
  • fields is a !-delimited list of field nicknames, listing the fields for which metadata should be returned. A maximum of five fields may be specified. A maximum of 100 bytes is returned for each field.
  • sortby is a !-delimited list of field nicknames, detailing how the result should be sorted, in field order. The field nicknames must appear in the field array. If the last element in the array is specified as “reverse”, the sort will be in reverse (descending) order. Use “nosort” to sort the query by relevance.
  • maxrecs is the maximum number of records to return, from 1 to 1024.
  • start is the starting number of the first item returned in the result.
  • suppress specifies whether to suppress compound object pages from the search. Use “1” to suppress or “0” to not suppress (i.e., include pages).
  • docptr specifies the pointer value of a compound object to restrict the query just to the pages in that compound object. This requires that a single alias be specified. Use “0” if not specified.
  • suggest specifies whether to return a spelling suggestion, if available for the searchstring‘s string. Use “1” to get suggestions or use “0” to not return a suggestion.
  • facets is an optional !-delimited list of field nicknames to return as facets. Use “0” if not requesting facets.
  • showunpub specifies whether to show or not show items from unpublished collections. Use “1” if requesting items from unpublished collections or “0” to hide items from unpublished collections.
  • denormalizeFacets specifies whether to show capitalization and diacritics in facet fields that have shared Controlled Vocabulary. Use “1” if requesting capitalization and diacritics or “0” to turn off capitalization and diacritics.
  • format is either “xml” or “json”.

Example: https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmQuery/linl/title^Amelia^all^and/title!subjec!descri/title/100/1/0/0/0/0/xml.

Here, I am searching the Springfield Aviation Collection (linl) for any occurrences of the word “Amelia” in the TITLE field. I want the title, subject, and description fields returned, and want a maximum of 100 records returned. I am starting at the beginning of the set, I am not suppressing compound objects, etc.

dmQuery.php

<?php

$xmlData = file_get_contents('https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmQuery/linl/title^Amelia^all^and/title!subjec!descri/title/100/1/0/0/0/0/xml');

// Create the document object

$xml = simplexml_load_string($xmlData);

$pager = array();

// How many hits did the search yield?

foreach ($xml->xpath('//pager') as $hits) {
        $pager[] = array(
                'start' => (string) $hits->start,
                'total' => (string) $hits->total
        );
}

$result = array();

// Get the nodes and loop them

foreach ($xml->xpath('//record') as $record) {
        $result[] = array(
                'collection' => (string) $record->collection,
                'title' => (string) $record->title,
                'subject' => (string) $record->subjec,
                'descri' => (string) $record->descri,
                'thumb' => (string) $record->pointer
        );
}

// The first record, $pager[0], will have the total number of results and the starting record

$numberOfHits = $pager[0]["total"];
$startingAt = $pager[0]["start"];

echo "Number of hits: $numberOfHits starting at record number $startingAt\n\n";

// I can get away with just checking the first record for the collection alias, since I am only searching 1 collection. If I was searching across all the collections, I would have to check each alias

$collectionName = $result[0]["collection"];

echo "Collection alias: $collectionName\n\n";

$resultCount = count($result) - 1;

for ($i=0;$i<=$resultCount;$i++) {
        $title = $result[$i]["title"];
        $subject = $result[$i]["subject"];
        $description = $result[$i]["descri"];
        $thumb = $result[$i]["thumb"];
        echo "$title: $subject: $description: $thumb\n\n";
}

?>

I can modify https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmQuery/linl/title^Amelia^all^and/title!subjec!descri/title/100/1/0/0/0/0/xml to be https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmQuery/all/title^Amelia^all^and/title!subjec!descri/title/100/1/0/0/0/0/xml to search ALL collections (156, as of August 2016) for the term “Amelia”. I would have to modify the last loop to:

for ($i=0;$i<=$resultCount;$i++) {
        $title = $result[$i]["title"];
        $subject = $result[$i]["subject"];
        $description = $result[$i]["descri"];
        $thumb = $result[$i]["thumb"];
        $collectionName = $result[$i]["collection"];
        echo "$title: $subject: $description: $thumb from $collectionName\n\n";
}

dmBrowse.php searches for the term woman across all of the collections and links the thumbnails to a full record display:

dmBrowse.php

<?php

$xmlData = file_get_contents('https://server16614.contentdm.oclc.org/dmwebservices/index.php?q=dmQuery/all/title^woman^all^and/title!subjec!descri/title/50/1/0/0/0/0/xml');

// Create the document object

$xml = simplexml_load_string($xmlData);

$pager = array();

// How many hits did the search yield

foreach ($xml->xpath('//pager') as $hits) {
        $pager[] = array(
                'start' => (string) $hits->start,
                'total' => (string) $hits->total
        );
}

$result = array();

// Get the nodes and loop them

foreach ($xml->xpath('//record') as $record) {
        $result[] = array(
                'collection' => (string) $record->collection,
                'title' => (string) $record->title,
                'subject' => (string) $record->subjec,
                'descri' => (string) $record->descri,
                'thumb' => (string) $record->pointer
        );
}

$numberOfHits = $pager[0]["total"];
$resultCount = count($result) - 1;

?>
<html>
        <head>
                <title>My Search Results</title>
        </head>
        <body>
                <div id="header">
                        <h1 style="text-align: center;">My Library</h1>
                        <h2 style="text-align: center;">Browsing our collections, with <?php echo $numberOfHits ?> results</h2>
                </div>
                <div id="list">
                        <ol>
                        <?php
for ($i=0;$i<=$resultCount;$i++) {
        $title = $result[$i]["title"];
        $subject = $result[$i]["subject"];
        $description = $result[$i]["descri"];
        $thumb = $result[$i]["thumb"];
        $collection = $result[$i]["collection"];
        $collection = str_ireplace("/", "", "$collection");
        $urlStr = "dmGetItemInfoWebPage.php?collection=$collection&pointer=$thumb";
        $imgStr = "http://www.idaillinois.org/utils/getthumbnail/collection/$collection/id/" . $thumb;
        echo "<li><a href=\"$urlStr\"><img src=\"$imgStr\"></a> <strong>$title</strong><br /><em>$description</em><br />\n$subject\n<p /></li>\n";
}
?>
                        </ol>
                </div>
                <div id="footer">
                        <p />
                        <strong>Our Library</strong>
                </div>
        </body>
</html>