Ejemplo n.º 1
0
function find_reference($journal, $volume, $page, $year = '')
{
    global $db;
    $references = array();
    $hits = array();
    if ($journal == '' || $volume == '' || $page == '') {
        //echo "journal=$journal\n";
        return $hits;
    }
    $series = '';
    $issn = '';
    $oclc = 0;
    if (preg_match('/^(?<journal>.*),\\s+ser\\.\\s+(?<series>.*)$/', $journal, $m)) {
        $journal = $m['journal'];
        $series = $m['series'];
    }
    if (preg_match('/^(?<journal>.*),\\s+(ns|n.s.)$/', $journal, $m)) {
        $journal = $m['journal'];
        //$series = $m['series'];
    }
    if (preg_match('/^(?<page>\\d+),(.*)$/', $page, $m)) {
        $page = $m['page'];
    }
    $issn = issn_from_title($journal);
    if ($issn == '') {
        $oclc = oclc_for_title($journal);
    }
    //echo $issn;
    //echo $oclc;
    $sql = '';
    if ($issn != '') {
        $sql = 'SELECT * FROM rdmp_reference WHERE issn=' . $db->qstr($issn) . ' AND volume=' . $db->qstr($volume) . ' AND ' . $page . ' BETWEEN spage AND epage';
    }
    if ($oclc != '') {
        $sql = 'SELECT * FROM rdmp_reference WHERE oclc=' . $db->qstr($oclc) . ' AND volume=' . $db->qstr($volume) . ' AND ' . $page . ' BETWEEN spage AND epage';
    }
    if ($sql != '') {
        if ($series != '') {
            $sql .= ' AND series=' . $db->qstr($series);
        }
        if ($year != '') {
            $sql .= ' AND year=' . $db->qstr($year);
        }
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        while (!$result->EOF) {
            $references[] = $result->fields['reference_id'];
            $result->MoveNext();
        }
    }
    foreach ($references as $reference_id) {
        $hits[] = reference_to_bibjson(db_retrieve_reference($reference_id));
    }
    return $hits;
}
Ejemplo n.º 2
0
function matching_pages($publication, $year)
{
    global $debug;
    $pages = array();
    $matches = array();
    $matched = false;
    // Parse citation
    if (!$matched) {
        //echo $publication;
        if (preg_match('/(?<journal>.*)\\s+(?<volume>\\d+):\\s*(?<page>\\d+)\\.?$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(\\((?<series>.*)\\)\\s+)?(?<volume>\\d+),(\\s+\\((?<issue>\\d+)\\))?\\s+(?<page>\\d+)\\.$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        //echo $publication;
        if (preg_match('/(?<journal>.*)\\s+(?<volume>\\d+):\\s*(?<page>\\d+)\\s+(?<year>[0-9]{4})/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(?<volume>\\d+),\\s+(?<page>\\d+)\\.$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(?<volume>\\d+),\\s+(?<page>\\d+)/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(?<volume>\\d+),\\s+(?<page>\\d+),/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    // Proc. U.S. nat. Mus., 99, no. 3247, 475.
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(?<volume>\\d+), no. (?<issue>\\d+),\\s+(?<page>\\d+)\\.$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    if (!$matched) {
        if (preg_match('/(?<journal>.*),\\s+(?<volume>\\d+) \\((?<issue>\\d+)\\),\\s+(?<page>\\d+)\\.$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    // Spixiana 7 (2): 125.
    if (!$matched) {
        if (preg_match('/(?<journal>.*)\\s+(?<volume>\\d+) \\((?<issue>\\d+)\\):\\s+(?<page>\\d+)\\.$/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    // Ann. Mag. Nat. Hist. , ser. 8 vol. 13 p. 436
    if (!$matched) {
        if (preg_match('/(?<journal>.*)\\s*,\\s+ser.\\s+(?<series>\\d+)\\s+vol.\\s*(?<volume>\\d+)\\s+p.\\s+(?<page>\\d+)\\s+(?<year>[0-9]{4})/Uu', $publication, $matches)) {
            $matched = true;
        }
    }
    print_r($matches);
    echo $publication;
    if (!$matched) {
    } else {
        $reference = reference_from_matches($matches);
        if (!isset($reference->issn)) {
            // Try and get ISSN from bioGUID
            $issn = issn_from_title($reference->secondary_title);
            if ($issn != '') {
                $reference->issn = $issn;
            } else {
                // No luck with ISSN, look for OCLC
                if (!isset($reference->oclc)) {
                    $oclc = oclc_for_title($reference->secondary_title);
                    if ($oclc != 0) {
                        $reference->oclc = $oclc;
                    }
                }
            }
        }
        //print_r($reference);
        $atitle = '';
        if (isset($reference->title)) {
            $atitle = $reference->title;
        }
        $search_hits = bhl_find_article($atitle, $reference->secondary_title, $reference->volume, $reference->spage, isset($reference->series) ? $reference->series : '', isset($reference->year) ? $reference->year : '');
        if (count($search_hits) == 0) {
            // try alternative way of searching using article title
            $search_hits = bhl_find_article_from_article_title($atitle, $reference->secondary_title, $reference->volume, $reference->spage, isset($reference->series) ? $reference->series : '');
        }
        //print_r($search_hits);
        foreach ($search_hits as $hit) {
            $pages[] = $hit->PageID;
        }
    }
    print_r($pages);
    return $pages;
}
Ejemplo n.º 3
0
/**
 * @brief Handle OpenURL request
 *
 * We may have more than one parameter with same name, so need to access QUERY_STRING, not _GET
 * http://stackoverflow.com/questions/353379/how-to-get-multiple-parameters-with-same-name-from-a-url-in-php
 *
 */
function main()
{
    global $config;
    global $debug;
    global $format;
    $id = 0;
    $callback = '';
    // If no query parameters
    if (count($_GET) == 0) {
        display_form();
        exit(0);
    }
    if (isset($_GET['format'])) {
        switch ($_GET['format']) {
            case 'html':
                $format = 'html';
                break;
            case 'json':
                $format = 'json';
                break;
            default:
                $format = 'html';
                break;
        }
    }
    if (isset($_GET['callback'])) {
        $callback = $_GET['callback'];
    }
    $debug = false;
    if (isset($_GET['debug'])) {
        $debug = true;
    }
    // Handle query and display results.
    $query = explode('&', html_entity_decode($_SERVER['QUERY_STRING']));
    $params = array();
    foreach ($query as $param) {
        list($key, $value) = explode('=', $param);
        $key = preg_replace('/^\\?/', '', urldecode($key));
        $params[$key][] = trim(urldecode($value));
    }
    if ($debug) {
        echo '<h1>Params</h1>';
        echo '<pre>';
        print_r($params);
        echo '</pre>';
    }
    // This is what we got from user
    $referent = new stdclass();
    parse_openurl($params, $referent);
    // Flesh it out
    // If we are looking for an article we need an ISSN, or at least an OCLC
    // Ask whether have this in our database (assumes we have ISSN)
    if (!isset($referent->issn)) {
        // Try and get ISSN from bioGUID
        $issn = issn_from_title($referent->secondary_title);
        if ($issn != '') {
            $referent->issn = $issn;
        } else {
            // No luck with ISSN, look for OCLC
            if (!isset($referent->oclc)) {
                $oclc = oclc_for_title($referent->secondary_title);
                if ($oclc != 0) {
                    $referent->oclc = $oclc;
                }
            }
        }
    }
    if ($debug) {
        echo '<h1>Referent</h1>';
        echo '<pre>';
        print_r($referent);
        echo '</pre>';
    }
    // Handle identifiers
    if (isset($referent->url)) {
        // BHL URL, for example if we have already mapped article to BHL
        // in Zotero,
        if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $referent->url, $matches)) {
            //print_r($matches);
            $PageID = $matches['pageid'];
            $references = bhl_reference_from_pageid($PageID);
            //print_r($references);
            if (count($references) == 0) {
                // We don't have an article for this PageID
                $search_hit = bhl_score_page($PageID, $referent->title);
                // Store
                $id = db_store_article($referent, $PageID);
            } else {
                // Have a reference with this PageID already
                // Will need to handle case where > 1 article on same page, e.g.
                // http://www.biodiversitylibrary.org/page/3336598
                $id = $references[0];
            }
            // Did we get a hit?
            if ($id != 0) {
                // We have this reference in our database
                switch ($format) {
                    case 'json':
                        // Display object
                        $reference = db_retrieve_reference($id);
                        header("Content-type: text/plain; charset=utf-8\n\n");
                        if ($callback != '') {
                            echo $callback . '(';
                        }
                        echo json_format(json_encode($reference));
                        if ($callback != '') {
                            echo ')';
                        }
                        break;
                    case 'html':
                    default:
                        // Redirect to reference display
                        header('Location: ' . $config['web_root'] . 'reference/' . $id . "\n\n");
                        break;
                }
                exit;
            }
        }
    }
    // OK, we're not forcing a match to BHL, so do we have this article?
    $id = db_find_article($referent);
    //echo "<b>id=$id</b><br/>";
    if ($id != 0) {
        // We have this reference in our database
        switch ($format) {
            case 'json':
                // Display object
                $reference = db_retrieve_reference($id);
                header("Content-type: text/plain; charset=utf-8\n\n");
                if ($callback != '') {
                    echo $callback . '(';
                }
                echo json_format(json_encode($reference));
                if ($callback != '') {
                    echo ')';
                }
                break;
            case 'html':
            default:
                // Twitter as log
                if ($config['twitter']) {
                    $tweet_this = false;
                    $tweet_this = isset($_GET['rfr_id']);
                    if ($tweet_this) {
                        $url = $config['web_root'] . 'reference/' . $id . ' ';
                        //  . '#openurl'; // url + hashtag
                        $url = $id;
                        $url_len = strlen($url);
                        $status = '';
                        //$text = $_GET['rfr_id'];
                        $text = '#openurl ' . $_SERVER["HTTP_REFERER"];
                        //$text .= ' @rdmpage';
                        if (isset($article->title)) {
                        }
                        $status = $text;
                        $status_len = strlen($status);
                        $extra = 140 - $status_len - $url_len - 1;
                        if ($extra < 0) {
                            $status_len += $extra;
                            $status_len -= 1;
                            $status = substr($status, 0, $status_len);
                            $status .= '…';
                        }
                        $status .= ' ' . $url;
                        tweet($status);
                    }
                }
                // Redirect to reference display
                header('Location: reference/' . $id . "\n\n");
                break;
        }
        exit;
    }
    // OK, not found, so let's go look for it...
    // Search BHL
    $atitle = '';
    if (isset($referent->title)) {
        $atitle = $referent->title;
    }
    $search_hits = bhl_find_article($atitle, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->date) ? $referent->date : '', isset($referent->issn) ? $referent->issn : '');
    if (count($search_hits) == 0) {
        // try alternative way of searching using article title
        $search_hits = bhl_find_article_from_article_title($referent->title, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->issn) ? $referent->issn : '');
    }
    // At this point if we haven't found it in BHL we could go elsewhere, e.g. bioGUID,
    // in which case we'd need to take this into account when displaying HTML and JSON
    if ($debug) {
        echo '<h3>Search hits</h3>';
        echo '<pre>';
        print_r($search_hits);
        echo '</pre>';
    }
    if (1) {
        // Check whether we already have an article that starts on this
        foreach ($search_hits as $hit) {
            $references = bhl_reference_from_pageid($hit->PageID);
            //print_r($references);
            if (count($references) != 0) {
                // We have this reference in our database
                switch ($format) {
                    case 'json':
                        // Display object
                        $reference = db_retrieve_reference($references[0]);
                        header("Content-type: text/plain; charset=utf-8\n\n");
                        if ($callback != '') {
                            echo $callback . '(';
                        }
                        echo json_format(json_encode($reference));
                        if ($callback != '') {
                            echo ')';
                        }
                        break;
                    case 'html':
                    default:
                        // Redirect to reference display
                        header('Location: reference/' . $references[0] . "\n\n");
                        break;
                }
                exit;
            }
        }
    }
    // Output search results in various formats...
    switch ($format) {
        case 'json':
            display_bhl_result_json($referent, $search_hits, $callback);
            break;
        case 'html':
        default:
            display_bhl_result_html($referent, $search_hits);
            break;
    }
}
Ejemplo n.º 4
0
/**
 * @brief Find article in BHL database
 *
 * @param title Title of journal
 * @param volume Volume containing article
 * @param page Page of article (typically this will be the first page in the article
 * @param series Optional series, used in cases where journal has multiple series with same 
 * volume numbers
 *
 * @return Search results as array of objects containing BHL PageID, score of article title match
 * (default = -1) and snippet showing alignment of article title to BHL text (empty string if no
 * article title supplied.
 *
 * <pre>
 * Array
 * (
 *     [0] => stdClass Object
 *         (
 *             [PageID] => 4467383
 *             [score] => 0.583333333333
 *             [snippet] => Kansas Lawrence, Kansas NUMBER 31...
 *         )
 * )
 *
 */
function bhl_find_article($atitle, $title, $volume, $page, $series = '', $date = '', $issn = '')
{
    global $db;
    global $debug;
    // Data structure to hold search result
    $obj = new stdclass();
    $obj->TitleID = 0;
    $obj->ISSN = $issn;
    $obj->ItemIDs = array();
    $obj->hits = array();
    // hack
    if ($title == 'Transactions of the Geological Society of London') {
        $title = 'Transactions of the Geological Society';
    }
    // Step one
    // --------
    // Map journal title to BHL titles. We try to achieve this by first finding ISSN for title,
    // then querying BHL for that ISSN in the bhl_title_identifier table. If we don't have an ISSN,
    // or BHL doesn't have this ISSN then we try approximate string matching. This may return multiple
    // hits, for now we take the best one. If we still haven't found the title, it may be in the
    // VolumeInfo field (for example, large articles or monographs may be bound separately and hence
    // treated as individual titles, rather than as items of a title (e.g., Fieldiana). If still no
    // hits, we abandon search.
    // Can we do this via ISSN?
    if ($obj->ISSN == '') {
        $obj->ISSN = issn_from_title($title);
    }
    if ($obj->ISSN != '') {
        $obj->TitleID = bhl_titleid_from_issn($obj->ISSN);
    }
    if ($debug) {
        echo __FILE__ . ' line ' . __LINE__ . ' ISSN = ' . $obj->ISSN . "\n";
    }
    // Special cases where mapping is tricky
    switch ($obj->ISSN) {
        // Bulletin de la Société philomathique de Paris
        case '0366-3515':
            $obj->TitleID = 9580;
            break;
            // Bulletin Du Museum Paris
        // Bulletin Du Museum Paris
        case '1148-8425':
            $obj->TitleID = 5943;
            break;
            // Bulletin of the Natural History Museum. Zoology series
        // Bulletin of the Natural History Museum. Zoology series
        case '0968-0470':
            $obj->TitleID = 62642;
            break;
            // Bulletin of the Southern California Academy of Sciences
        // Bulletin of the Southern California Academy of Sciences
        case '0038-3872':
            $obj->TitleID = 4949;
            break;
            // Gayana
        // Gayana
        case '0016-531X':
            $obj->TitleID = 39684;
            break;
            // Stuttgarter Beiträge zur Naturkunde
        // Stuttgarter Beiträge zur Naturkunde
        case '0341-0145':
            $obj->TitleID = 49174;
            break;
            // Transactions American Microscopical Society
        // Transactions American Microscopical Society
        case '0003-0023':
            $obj->TitleID = 37912;
            break;
            // Transactions of the Linnean Society
        // Transactions of the Linnean Society
        case '1945-9432':
            $obj->TitleID = 2203;
            break;
        case '0771-0488':
            $obj->TitleID = 10603;
            break;
        case '1019-8563':
            $obj->TitleID = 15675;
            break;
        case '0177-7424':
            $obj->TitleID = 42670;
            break;
            // Scientific papers of the Natural History Museum, University of Kansas
        // Scientific papers of the Natural History Museum, University of Kansas
        case '1094-0782':
            $hits = bhl_title_lookup($atitle);
            if (count($hits) > 0) {
                if ($hits[0]['sl'] > 90) {
                    $obj->TitleID = $hits[0]['TitleID'];
                }
            }
            break;
        case '0375-099X':
            $obj->TitleID = 10294;
            break;
            // Spixiana
        // Spixiana
        case '0341-8391':
            $obj->TitleID = 40214;
            break;
            // Iheringia. Série zoologia
        // Iheringia. Série zoologia
        case '0073-4721':
            $obj->TitleID = 50228;
            break;
        case '0084-5620':
            $obj->TitleID = 45493;
            break;
            // Transactions of the Linnean Society of London. Zoology.
        // Transactions of the Linnean Society of London. Zoology.
        case '1945-9440':
            $obj->TitleID = 51416;
            break;
            // Zoological Science (Tokyo)
        // Zoological Science (Tokyo)
        case '0289-0003':
            $obj->TitleID = 61647;
            break;
            // Fieldiana
        // Fieldiana
        case '0015-0754':
            $obj->TitleID = 5132;
            break;
        default:
            break;
    }
    if ($debug) {
        echo __FILE__ . ' line ' . __LINE__ . ' TitleID = ' . $obj->TitleID . "\n";
    }
    /*$obj->ISSN = '0150-9322';
    	$obj->TitleID = 4647;*/
    // If no ISSN, or no mapping available via ISSN, so try string matching
    if ($obj->TitleID == 0) {
        $hits = bhl_title_lookup($title);
        if ($debug) {
            echo __FILE__ . ' line ' . __LINE__ . "\n";
            echo '<pre>';
            print_r($hits);
            echo '</pre>';
        }
        if (count($hits) > 0) {
            $obj->TitleID = $hits[0]['TitleID'];
        }
    }
    if ($debug) {
        echo __FILE__ . ' line ' . __LINE__ . ' TitleID = ' . $obj->TitleID . "\n";
    }
    // Special cases where title is in VolumeInfo (e.g., article is treated as a monograph)
    if ($obj->TitleID == 0) {
        if (isset($obj->ISSN)) {
            switch ($obj->ISSN) {
                case '0015-0754':
                    //echo $title . "\n";
                    //echo "Handle Fieldiana...\n";
                    $obj->ItemIDs = bhl_itemid_from_pattern('Fieldiana% Zoology%', '/^Fieldiana\\.? Zoology/', $volume);
                    break;
                default:
                    break;
            }
        }
    }
    // At this point if we have a title we then want to find items for this title
    if ($obj->TitleID != 0) {
        bhl_title_retrieve($obj->TitleID, $obj);
        // Problem -- volume info varies across titles (and sometimes within...)
        if ($debug) {
            echo __LINE__ . "<br/>TitleID:" . $obj->TitleID . "<br/>Volume: " . $volume . "<br/>Series: " . $series . "<br/>";
        }
        $volume_offset = 0;
        $obj->ItemIDs = bhl_itemid_from_volume($obj->TitleID, $volume, $series);
        if ($debug) {
            echo __LINE__ . " ItemIDs<br/>\n";
            print_r($obj->ItemIDs);
        }
        // Special cases where VolumeInfo is year, not volume
        if (count($obj->ItemIDs) == 0 && $date != '') {
            $year = substr($date, 0, 4);
            switch ($obj->TitleID) {
                case 11516:
                    $obj->ItemIDs = bhl_itemid_from_year($obj->TitleID, $year);
                    break;
                default:
                    break;
            }
        }
        // Special cases where we know there are problems. For example, there may be multiple titles
        // that correspond to the same journal. In these cases we clear the item list, and add to it
        // items from all titles that match our query
        $title_list = array();
        switch ($obj->TitleID) {
            // Actes de la Société linnéenne de Bordeaux
            case 4199:
            case 16235:
                $title_list = array(4199, 16235);
                break;
                // 	American journal of conchology
            // 	American journal of conchology
            case 15900:
            case 7077:
                $title_list = array(7077, 15900);
                break;
                // The American journal of science
            // The American journal of science
            case 14965:
            case 60982:
                $title_list = array(14965, 60982);
                break;
                // Annali del Museo civico di storia naturale di Genova
            // Annali del Museo civico di storia naturale di Genova
            case 7929:
            case 9576:
            case 43408:
                $title_list = array(7929, 9576, 43408);
                break;
                // Annales de la Société entomologique de Belgique
            // Annales de la Société entomologique de Belgique
            case 11933:
            case 11938:
                $title_list = array(11933, 11938);
                break;
                // Annales de la Société royale malacologique de Belgique
            // Annales de la Société royale malacologique de Belgique
            case 6301:
            case 6205:
            case 7031:
                $title_list = array(6301, 6205, 7031);
                break;
                // Atti della Società italiana di scienze
            // Atti della Società italiana di scienze
            case 9586:
            case 16255:
            case 16213:
                $title_list = array(9586, 16255, 16213);
                break;
                // Annales de la Société entomologique de Belgique.
            // Annales de la Société entomologique de Belgique.
            case 51679:
            case 11933:
                $title_list = array(51679, 11933);
                break;
                // Annales des Sciences naturelles
            // Annales des Sciences naturelles
            case 6343:
            case 2205:
            case 13266:
            case 4647:
            case 5010:
                $title_list = array(6343, 2205, 13266, 4647, 5010);
                break;
                // Ann. Mag. Nat. Hist.
            // Ann. Mag. Nat. Hist.
            case 2195:
            case 15774:
                $title_list = array(2195, 15774);
                break;
                // Anales de la Sociedad Científica Argentina
            // Anales de la Sociedad Científica Argentina
            case 44792:
            case 51644:
            case 3630:
                $title_list = array(44792, 51644, 3630);
                break;
                // Anales del Museo Nacional de Historia Natural de Buenos Aires
            // Anales del Museo Nacional de Historia Natural de Buenos Aires
            case 5595:
            case 5597:
                $title_list = array(5595, 5597);
                break;
                // Annals of the New York Academy of Sciences
            // Annals of the New York Academy of Sciences
            case 4382:
            case 51004:
                $title_list = array(4382, 51004);
                break;
                // Annals of the South African Museum
            // Annals of the South African Museum
            case 62815:
            case 6928:
                $title_list = array(62815, 6928);
                break;
                // 	Annales des sciences naturelles, Zoologie
            // 	Annales des sciences naturelles, Zoologie
            case 13266:
            case 4647:
                $title_list = array(4647, 13266);
                break;
                // Archiv für Naturgeschichte
            // Archiv für Naturgeschichte
            case 6638:
            case 7051:
            case 2371:
            case 5923:
            case 12937:
            case 12938:
                $title_list = array(6638, 7051, 2371, 5923, 12937, 12938);
                break;
                // Archives de zoologie expérimentale et générale
            // Archives de zoologie expérimentale et générale
            case 5559:
            case 7065:
                $title_list = array(5559, 7065);
                break;
                // Beiträge zur Kenntnis der Meeresfauna Westafrikas
            // Beiträge zur Kenntnis der Meeresfauna Westafrikas
            case 11824:
            case 7400:
                $title_list = array(11824, 7400);
                break;
                // Bericht der Senckenbergischen Naturforschenden Gesellschaft in Frankfurt am Main
            // Bericht der Senckenbergischen Naturforschenden Gesellschaft in Frankfurt am Main
            case 14292:
            case 8745:
                $title_list = array(14292, 8745);
                break;
                // Berliner entomologische Zeitschrift
            // Berliner entomologische Zeitschrift
            case 46204:
            case 46202:
            case 8267:
                $title_list = array(8267, 46202, 46204);
                break;
                // Boletin de la Sociedad de Biología de Concepción
            // Boletin de la Sociedad de Biología de Concepción
            case 45409:
            case 51419:
                $title_list = array(45409, 51419);
                break;
                // Brotéria
            // Brotéria
            case 5931:
            case 7952:
            case 7861:
                $title_list = array(5931, 7952, 7861);
                break;
                // Bulletin de l'Académie impériale des sciences de St.-Pétersbourg
            // Bulletin de l'Académie impériale des sciences de St.-Pétersbourg
            case 42575:
            case 49351:
            case 10614:
                $title_list = array(42575, 49351, 10614);
                break;
                // Bollettino dei musei di zoologia ed anatomia comparata della R. Università di Torino
            // Bollettino dei musei di zoologia ed anatomia comparata della R. Università di Torino
            case 14698:
            case 10776:
                $title_list = array(14698, 10776);
                break;
                // Bulletin de la Société botanique de France
                //case 5064:
                //case 9580:
                $title_list = array(5064, 9580);
                break;
                // Bulletin de la Société philomathique de Paris
            // Bulletin de la Société philomathique de Paris
            case 9580:
            case 5064:
                $title_list = array(9580, 5064);
                break;
                // Bulletin de la Société zoologique de France
            // Bulletin de la Société zoologique de France
            case 51699:
            case 7415:
            case 10614:
                $title_list = array(51699, 7415, 10614);
                break;
                // Bulletin du Muséum National d'Histoire Naturelle
            // Bulletin du Muséum National d'Histoire Naturelle
            case 14109:
            case 5943:
            case 14964:
            case 12908:
            case 13855:
                $title_list = array(14109, 5943, 14964, 12908, 13855);
                break;
                // Bulletin international de l'Académie des sciences de Cracovie
            // Bulletin international de l'Académie des sciences de Cracovie
            case 5605:
            case 5607:
            case 13192:
                $title_list = array(51699, 5605, 5607);
                break;
                // Bulletin of the British Ornithologists' Club.
            // Bulletin of the British Ornithologists' Club.
            case 8260:
            case 46639:
            case 62378:
                $title_list = array(8260, 46639, 62378);
                break;
                // Bulletin of the Illinois State Laboratory of Natural History
            // Bulletin of the Illinois State Laboratory of Natural History
            case 5041:
            case 8196:
                $title_list = array(5041, 8196);
                break;
                // Bulletin of the Natural History Museum (Entomology)
            // Bulletin of the Natural History Museum (Entomology)
            case 2192:
            case 2201:
            case 53882:
            case 62492:
                // supplement
                $title_list = array(2192, 2201, 53882, 62492);
                break;
                // Bulletin of the Southern California Academy of Sciences
            // Bulletin of the Southern California Academy of Sciences
            case 4949:
            case 50446:
            case 60457:
                $title_list = array(4949, 50446, 60457);
                break;
                // Bulletin of zoological nomenclature
            // Bulletin of zoological nomenclature
            case 11541:
            case 51603:
                $title_list = array(11541, 51603);
                break;
                // The Canadian field-naturalist
            // The Canadian field-naturalist
            case 1929:
            case 39970:
                $title_list = array(1929, 39970);
                break;
                // Comptes rendus hebdomadaires des séances de l'Académie des scien...
            // Comptes rendus hebdomadaires des séances de l'Académie des scien...
            case 7014:
            case 4466:
            case 1590:
                $title_list = array(4466, 7014, 1590);
                break;
                // Comptes rendus des séances de la Société de biologie et de ses filiales.
            // Comptes rendus des séances de la Société de biologie et de ses filiales.
            case 5068:
            case 8070:
                $title_list = array(5068, 8070);
                break;
                // Discovery Reports
            // Discovery Reports
            case 6168:
            case 15981:
                $title_list = array(6168, 15981);
                break;
                // Entomological News
            // Entomological News
            case 34360:
            case 2356:
            case 2359:
                $title_list = array(34360, 2356, 2359);
                break;
                // Fieldiana
            // Fieldiana
            case 5132:
            case 42256:
                $title_list = array(5132, 42256);
                break;
                // Gayana
            // Gayana
            case 39684:
            case 39988:
                $title_list = array(39988, 39684);
                break;
                // Jahrbuch der Hamburgischen Wissenschaftlichen Anstalten
            // Jahrbuch der Hamburgischen Wissenschaftlichen Anstalten
            case 7925:
            case 9594:
                $title_list = array(7925, 9594);
                break;
                // Journal für Ornithologie.
            // Journal für Ornithologie.
            case 11280:
            case 47027:
                $title_list = array(11280, 47027);
                break;
                // Journal of the Asiatic Society of Bengal
                // Journal and proceedings of the Asiatic Society of Bengal
            // Journal of the Asiatic Society of Bengal
            // Journal and proceedings of the Asiatic Society of Bengal
            case 51678:
            case 47024:
                $title_list = array(47024, 51678);
                break;
                // Journal of the Washington Academy of Sciences
            // Journal of the Washington Academy of Sciences
            case 2087:
            case 60244:
                $title_list = array(2087, 60244);
                break;
                // Kungliga Svenska Vetenskaps-Akademiens handlingar
            // Kungliga Svenska Vetenskaps-Akademiens handlingar
            case 2512:
            case 12549:
            case 50688:
                $title_list = array(2512, 12549, 50688);
                break;
                // London and Edinburgh Philosophical Magazine and Journal of Science
            // London and Edinburgh Philosophical Magazine and Journal of Science
            case 2440:
            case 58332:
            case 3735:
                $title_list = array(2440, 58332, 3735);
                break;
                // Memoirs And Proceedings of The Manchester Literary And Philosophical Society
            // Memoirs And Proceedings of The Manchester Literary And Philosophical Society
            case 50366:
            case 9535:
                $title_list = array(50366, 9535);
                break;
                // Mem. Calif. Acad. Sci.
            // Mem. Calif. Acad. Sci.
            case 3955:
            case 3949:
                $title_list = array(3955, 3949);
                break;
                // Memoirs of the Queensland Museum
            // Memoirs of the Queensland Museum
            case 12912:
            case 60751:
            case 61449:
                $title_list = array(12912, 60751, 61449);
                break;
                // Misc Pub Kansas (some of these are treated as individual titles)
            // Misc Pub Kansas (some of these are treated as individual titles)
            case 4050:
            case 16171:
            case 16222:
            case 5474:
                $title_list = array(4050, 16171, 16222, 5474);
                break;
                // Mitteilungen aus dem Naturhistorischen Museum in Hamburg
            // Mitteilungen aus dem Naturhistorischen Museum in Hamburg
            case 8009:
            case 9579:
            case 42281:
                $title_list = array(8009, 9579, 42281);
                break;
                // Mitteilungen aus dem Zoologischen Museum in Berlin.
            // Mitteilungen aus dem Zoologischen Museum in Berlin.
            case 11448:
            case 42540:
                $title_list = array(11448, 42540);
                break;
                // Mitteilungen des Naturwissenschaftlichen Vereines für Steiermark
            // Mitteilungen des Naturwissenschaftlichen Vereines für Steiermark
            case 12305:
            case 42384:
                $title_list = array(12305, 42384);
                break;
                // Meddelanden af Societatis pro Fauna et Flora Fennica
            // Meddelanden af Societatis pro Fauna et Flora Fennica
            case 3613:
            case 13470:
                $title_list = array(3613, 13470);
                break;
                // Mémoires du Muséum d'histoire naturelle.
            // Mémoires du Muséum d'histoire naturelle.
            case 4501:
            case 50067:
                $title_list = array(4501, 50067);
                break;
                // Memoirs of the National Museum of Victoria
                // Memoirs of the National Museum, Melbourne
                // Memoirs of the National Museum, Melbourne
            // Memoirs of the National Museum of Victoria
            // Memoirs of the National Museum, Melbourne
            // Memoirs of the National Museum, Melbourne
            case 58640:
            case 13041:
            case 57949:
            case 59883:
                $title_list = array(58640, 13041, 57949, 59883);
                break;
                // Monatsberichte der Königlichen Preussische Akademie des Wissenschaften zu Berlin
            // Monatsberichte der Königlichen Preussische Akademie des Wissenschaften zu Berlin
            case 48522:
            case 51443:
                $title_list = array(48522, 51443);
                break;
                // Natural history report.
            // Natural history report.
            case 1163:
            case 42665:
                $title_list = array(1163, 42665);
                break;
                // Occasional Papers of the Boston Society of Natural History
            // Occasional Papers of the Boston Society of Natural History
            case 7539:
            case 50720:
                $title_list = array(7539, 50720);
                break;
                // Occasional papers of the California Academy of Sciences
            // Occasional papers of the California Academy of Sciences
            case 4672:
            case 5584:
                $title_list = array(4672, 5584);
                break;
                // Occasional papers of the Museum of Natural History, the University of Kansas.
            // Occasional papers of the Museum of Natural History, the University of Kansas.
            case 7410:
            case 15798:
                $title_list = array(7410, 15798);
                break;
                // Öfversigt af Kongl. Vetenskaps-akademiens forhandlingar
            // Öfversigt af Kongl. Vetenskaps-akademiens forhandlingar
            case 2515:
            case 15534:
                $title_list = array(2515, 15534);
                break;
                // Ornithologische Monatsberichte
            // Ornithologische Monatsberichte
            case 8609:
            case 46941:
                $title_list = array(8609, 46941);
                break;
                // Notes from the Leyden Museum
            // Notes from the Leyden Museum
            case 8740:
            case 12935:
                $title_list = array(8740, 12935);
                break;
                // The Philippine journal of science
            // The Philippine journal of science
            case 69:
            case 50545:
                $title_list = array(69, 50545);
                break;
                // The Philosophical magazine
            // The Philosophical magazine
            case 982:
            case 58331:
            case 58328:
                $title_list = array(982, 58331, 58328);
                break;
                // Pom
            // Pom
            case 9567:
            case 8154:
            case 12098:
                $title_list = array(9567, 8154, 12098);
                break;
                // Proceedings of the Biological Society of Washington
            // Proceedings of the Biological Society of Washington
            case 2211:
            case 3622:
            case 50687:
                $title_list = array(2211, 3622, 50687);
                break;
                // Proceedings of the California Academy of Sciences
            // Proceedings of the California Academy of Sciences
            case 3952:
            case 7411:
            case 15816:
            case 3966:
            case 4274:
            case 3943:
            case 12931:
            case 45400:
                $title_list = array(3952, 7411, 15816, 3966, 4274, 3943, 12931, 45400);
                break;
                // Proceedings of The Linnean Society of New South Wales
            // Proceedings of The Linnean Society of New South Wales
            case 6525:
            case 60468:
                $title_list = array(6525, 60468);
                break;
                // Proceedings of the Zoological Society of London
            // Proceedings of the Zoological Society of London
            case 1594:
            case 44963:
                $title_list = array(1594, 44963);
                break;
                // Quarterly journal of microscopical science
            // Quarterly journal of microscopical science
            case 13831:
            case 14014:
                $title_list = array(13831, 14014);
                break;
                // Records of the Indian Museum
            // Records of the Indian Museum
            case 53477:
            case 10294:
                $title_list = array(53477, 10294);
                break;
                // Records of the South Australian Museum
            // Records of the South Australian Museum
            case 14053:
            case 42375:
            case 61893:
                $title_list = array(14053, 42375, 61893);
                break;
                // Report of the Commissioner for ...
            // Report of the Commissioner for ...
            case 6927:
            case 15220:
                $title_list = array(6927, 15220);
                break;
                // Revue d'entomologie
            // Revue d'entomologie
            case 10428:
            case 11902:
            case 14588:
                $title_list = array(10428, 11902, 14588);
                break;
                // Revue et magasin de zoologie pure et appliquée
            // Revue et magasin de zoologie pure et appliquée
            case 51560:
            case 51630:
            case 2744:
            case 2212:
                $title_list = array(2744, 51630, 51560, 2212);
                break;
                // Revue suisse de zoologie
            // Revue suisse de zoologie
            case 8981:
            case 62174:
                $title_list = array(8981, 62174);
                break;
                // The Scientific proceedings of the Royal Dublin Society
            // The Scientific proceedings of the Royal Dublin Society
            case 14895:
            case 44062:
                $title_list = array(14895, 44062);
                break;
                // Sitzungsberichte der Gesellschaft Naturforschender Freunde zu Berlin
            // Sitzungsberichte der Gesellschaft Naturforschender Freunde zu Berlin
            case 9584:
            case 7922:
                $title_list = array(7922, 9584);
                break;
                // Sitzungsberichte der Kaiserlichen Akademie der Wissenschaften. Mathematisch-Naturwissenschaftliche Classe
            // Sitzungsberichte der Kaiserlichen Akademie der Wissenschaften. Mathematisch-Naturwissenschaftliche Classe
            case 6884:
            case 8219:
            case 6888:
            case 6776:
            case 8100:
                $title_list = array(6884, 8219, 6888, 6776, 8100);
                break;
                // Stettiner Entomologische Zeitung
            // Stettiner Entomologische Zeitung
            case 8630:
            case 8641:
                $title_list = array(8630, 8641);
                break;
                // Stuttgarter Beiträge zur Naturkunde
            // Stuttgarter Beiträge zur Naturkunde
            case 49392:
            case 51723:
            case 49174:
            case 43750:
                $title_list = array(49392, 51723, 49174, 43750);
                break;
                // Tijdschrift voor entomologie.
            // Tijdschrift voor entomologie.
            case 10088:
            case 39564:
                $title_list = array(10088, 39564);
                break;
                // Transactions and proceedings and report of the Royal Society of South Australia (Incorporated)
            // Transactions and proceedings and report of the Royal Society of South Australia (Incorporated)
            case 51476:
            case 16197:
            case 16190:
                $title_list = array(51476, 16197, 16190);
                break;
                // Transactions and proceedings of the New Zealand Institute
            // Transactions and proceedings of the New Zealand Institute
            case 48984:
            case 4095:
                $title_list = array(48984, 4095);
                break;
                // Transactions of Kansas Academy of Sciences
            // Transactions of Kansas Academy of Sciences
            case 8255:
            case 8256:
                $title_list = array(8255, 8256);
                break;
                // Transactions of the American Entomological Society
            // Transactions of the American Entomological Society
            case 7830:
            case 7549:
            case 5795:
                $title_list = array(5795, 7549, 7830);
                break;
                // Transactions of the Connecticut Academy of Arts and Sciences
            // Transactions of the Connecticut Academy of Arts and Sciences
            case 7541:
            case 5604:
            case 13505:
                $title_list = array(7541, 5604, 13505);
                break;
                // Transactions of The Linnean Society of London
            // Transactions of The Linnean Society of London
            case 2203:
                //-> 683
            //-> 683
            case 8257:
                //-> -> 51416
            //-> -> 51416
            case 683:
            case 51416:
                $title_list = array(683, 51416);
                break;
                // Transactions of the Royal Society of South Australia
            // Transactions of the Royal Society of South Australia
            case 16197:
            case 16186:
            case 51127:
            case 16190:
            case 62638:
            case 63905:
            case 63906:
                $title_list = array(16197, 16186, 51127, 16190, 62638, 63905, 63906);
                break;
                // Transactions of the San Diego Society of Natural History
            // Transactions of the San Diego Society of Natural History
            case 51441:
            case 3144:
                $title_list = array(51441, 3144);
                break;
                // Transactions of the Zoological Society of London
            // Transactions of the Zoological Society of London
            case 12650:
            case 45493:
                $title_list = array(12650, 45493);
                break;
                // The Kansas University science bulletin
            // The Kansas University science bulletin
            case 3179:
            case 15415:
                $title_list = array(3179, 15415);
                break;
                // Tulane
            // Tulane
            case 3119:
            case 5361:
                $title_list = array(3119, 5361);
                break;
                // Verhandlungen der Naturforschenden Gesellschaft in Basel.
            // Verhandlungen der Naturforschenden Gesellschaft in Basel.
            case 8939:
            case 46540:
                $title_list = array(8939, 46540);
                break;
                // Verhandlungen des Zoologisch-Botanischen Vereins in Wien
            // Verhandlungen des Zoologisch-Botanischen Vereins in Wien
            case 11285:
            case 13275:
                $title_list = array(11285, 13275);
                break;
                // Veröffentlichungen der Zoologischen Staatssammlung München
            // Veröffentlichungen der Zoologischen Staatssammlung München
            case 39971:
            case 51449:
                $title_list = array(39971, 51449);
                break;
                // The Victorian Naturalist
            // The Victorian Naturalist
            case 5027:
            case 8941:
            case 60605:
            case 43746:
                $title_list = array(5027, 8941, 60605, 43746);
                break;
                // Videnskabelige meddelelser fra den Naturhistoriske forening
            // Videnskabelige meddelelser fra den Naturhistoriske forening
            case 7547:
            case 52368:
            case 2226:
                $title_list = array(7547, 52368, 2226);
                break;
                // Zeitschrift für wissenschaftliche Zoologie
            // Zeitschrift für wissenschaftliche Zoologie
            case 2334:
            case 9197:
                $title_list = array(2334, 9197);
                break;
                // Zoologische Jahrbücher
            // Zoologische Jahrbücher
            case 8980:
            case 13352:
                $title_list = array(8980, 13352);
                break;
            default:
                break;
        }
        if (count($title_list) != 0) {
            $obj->ItemIDs = array();
            foreach ($title_list as $id) {
                //echo "<h2>Title list $id</h2>";
                $obj->ItemIDs = array_merge(bhl_itemid_from_volume($id, $volume, $series), $obj->ItemIDs);
            }
        }
    }
    //echo __LINE__;
    if ($debug) {
        echo "Line " . __LINE__ . "<br/>";
        echo '<h2>Title list</h2>';
        print_r($title_list);
        print_r($obj->ItemIDs);
    }
    // At this point if we have any items then we have a potential hit. For each item in the list we
    // query the BHL database and look for pages with PageNumber matching our query
    $num_items = count($obj->ItemIDs);
    if ($num_items != 0) {
        for ($i = 0; $i < $num_items; $i++) {
            $sql = 'SELECT * FROM bhl_page 
			INNER JOIN page USING(PageID)
			WHERE (bhl_page.ItemID = ' . $obj->ItemIDs[$i]->ItemID . ') 
			AND (PageNumber = ' . $db->qstr($page) . ')
			OR (PageNumber = ' . $db->qstr('%[' . $page . ']') . ')
			ORDER BY SequenceOrder';
            $sql = 'SELECT * FROM bhl_page 
			INNER JOIN page USING(PageID)
			WHERE (bhl_page.ItemID = ' . $obj->ItemIDs[$i]->ItemID . ') 
			AND (PageNumber = ' . $db->qstr($page) . ')
			ORDER BY SequenceOrder';
            //echo $sql;
            $result = $db->Execute($sql);
            if ($result == false) {
                die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
            }
            $obj->ItemIDs[$i]->pages = array();
            switch ($result->NumRows()) {
                case 0:
                    //no hit :(
                    // Try and handle case where page one is a title page
                    $guess = bhl_step_back($obj->ItemIDs[$i]->ItemID, $page, $obj->ItemIDs[$i]->volume_offset);
                    if ($guess != 0) {
                        $obj->ItemIDs[$i]->pages[] = $guess;
                        $obj->hits[] = $guess;
                        $obj->ItemIDs[$i]->PageID = $guess;
                    }
                    break;
                case 1:
                    // unique hit
                    $obj->ItemIDs[$i]->pages[] = $result->fields['PageID'];
                    $obj->hits[] = $result->fields['PageID'];
                    $obj->ItemIDs[$i]->PageID = $result->fields['PageID'];
                    break;
                default:
                    // More than one hit, for example if Item has multiple volumes, hence potentially
                    // more than one page with this number.
                    while (!$result->EOF) {
                        $obj->ItemIDs[$i]->pages[] = $result->fields['PageID'];
                        $obj->hits[] = $result->fields['PageID'];
                        $result->MoveNext();
                    }
                    // Assume page in nth volume is nth page in SequenceOrder
                    // (but actually we store all hits and use string matching on title to filter)
                    $obj->ItemIDs[$i]->PageID = $obj->ItemIDs[$i]->pages[$obj->ItemIDs[$i]->volume_offset];
                    break;
            }
        }
    }
    if ($debug) {
        echo __LINE__;
        echo '<pre>';
        print_r($obj);
        echo '</pre>';
    }
    // Summarise results as array of hits
    $search_results = array();
    // Post process hits, filtering by title match...
    $n = count($obj->ItemIDs);
    for ($i = 0; $i < $n; $i++) {
        foreach ($obj->ItemIDs[$i]->pages as $page) {
            $search_hit = bhl_score_page($page, $atitle);
            /*			new stdclass;
            			$search_hit->PageID = $page;
            			$search_hit->score = -1;
            			$search_hit->snippet = '';
            			
            			// Score title match
            			if ($atitle != '')
            			{
            				$search_hit->score = bhl_score_string(
            					$search_hit->PageID, 
            					$atitle, 
            					$search_hit->snippet
            					);
            			} */
            $search_results[] = $search_hit;
        }
    }
    //return $obj;
    return $search_results;
}