diff -Naur harvester/include/quicksearch.inc.php harvester.new/include/quicksearch.inc.php --- harvester/include/quicksearch.inc.php 2004-02-22 17:50:03.000000000 -0700 +++ harvester.new/include/quicksearch.inc.php 2005-11-11 15:37:54.000000000 -0700 @@ -5,19 +5,19 @@ // PKP OAI Harvester // Copyright (c) 2003-2004 The Public Knowledge Project // http://www.pkp.ubc.ca -// +// // This file is part of the PKP OAI Harvester. -// +// // The PKP OAI Harvester is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // The PKP OAI Harvester is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with the PKP OAI Harvester; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -28,39 +28,42 @@ ?> \ No newline at end of file + diff -Naur harvester/search.php harvester.new/search.php --- harvester/search.php 2004-02-22 17:50:03.000000000 -0700 +++ harvester.new/search.php 2005-11-11 15:37:27.000000000 -0700 @@ -5,19 +5,19 @@ // PKP OAI Harvester // Copyright (c) 2003-2004 The Public Knowledge Project // http://www.pkp.ubc.ca -// +// // This file is part of the PKP OAI Harvester. -// +// // The PKP OAI Harvester is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // The PKP OAI Harvester is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with the PKP OAI Harvester; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -25,567 +25,475 @@ // search.php // Search the records, either via a quick search or advanced search form - // include necessary files include("include/common.inc.php"); - // extract search form variables -foreach(array("query", "search", "is_search", "limit", "match", "archive", "query_author", "query_affiliation", "query_title", "query_abstract", "query_date_from_month", "query_date_from_day", "query_date_from_year", "query_date_to_month", "query_date_to_day", "query_date_to_year", "query_discipline", "query_topics", "query_approach", "query_coverage", "query_language", "query_sponsor", "query_type") as $var) { - $$var = isset($_POST[$var]) ? $_POST[$var] : $_GET[$var]; +$get_vars = array( + "search", + "is_search", + "archive", + "query", + "limit", + "query_author", + "query_subject", + "query_title", + "query_abstract", + "query_date_from_month", + "query_date_from_day", + "query_date_from_year", + "query_date_to_month", + "query_date_to_day", + "query_date_to_year", + "query_language", + "query_sponsor", + "query_type", + "sort", + "match", + "max_records", + "records", + "page" +); + +// APPEND POST VARS, KEEPING ANY GET VARIABLES +foreach(array_keys($_POST) as $k) { + if(!isset($_GET[$k])) { + $_GET[$k] = $_POST[$k]; + } } -$page = (int) $_GET['page']; - +foreach($get_vars as $var) { + if(isset($_GET[$var]) && !empty($_GET[$var])) { + $$var = htmlentities(trim($_GET[$var])); + } +} -// this page's title -if(!empty($query)) { - $title = "Search Results"; -} else { +// this page's title and default match +if(empty($is_search)) { + if(empty($match)) { + $match = "all"; + } $title = "Metadata Search"; +} else { + $title = "Search Results"; } - // current document's hierarchy in the site -$site_hierarchy = array("Home"=>"index.php"); +$site_hierarchy = array("Home" => "index.php"); // include html header include("include/header.inc.php"); - -// set date from/to -if($query_date_from_month && $query_date_from_day && $query_date_from_year && checkdate($query_date_from_month, $query_date_from_day, $query_date_from_year)) { - $query_date_from = strip_html("$query_date_from_year-$query_date_from_month-$query_date_from_day"); -} -else { - $query_date_from = strip_html($query_date_from); +// verify dates +if(!empty($query_date_from_month) || !empty($query_date_from_day) || !empty($query_date_from_year)) { + if(checkdate($query_date_from_month, $query_date_from_day, $query_date_from_year)) { + $query_date_from = "$query_date_from_year-$query_date_from_month-$query_date_from_day"; + } else { + $date_from_err = "Invalid From date"; + } } -if($query_date_to_month && $query_date_to_day && $query_date_to_year && checkdate($query_date_to_month, $query_date_to_day, $query_date_to_year)) { - $query_date_to = strip_html("$query_date_to_year-$query_date_to_month-$query_date_to_day"); -} -else { - $query_date_to = strip_html($query_date_to); +if(!empty($query_date_to_month) || !empty($query_date_to_day) || !empty($query_date_to_year)) { + if(checkdate($query_date_to_month, $query_date_to_day, $query_date_to_year)) { + $query_date_to = "$query_date_to_year-$query_date_to_month-$query_date_to_day"; + } else { + $date_to_err = "Invalid To date"; + } } +if(empty($sort)) { + $sort = "date_desc"; +} -if($query || ($is_search && ($query || $query_author || $query_affiliation || $query_title || $query_abstract || $query_date_from || $query_date_to || $query_discipline || $query_topics || $query_approach || $query_coverage || $query_language || ($query_type && $query_type != "All")))) { +if(!empty($is_search) && empty($date_from_err) && empty($date_to_err)) { // include quick search form include("include/quicksearch.inc.php"); - + + $page = isset($page) ? ((int) $page) : 0; + $max_records = isset($max_records) ? ((int) $max_records) : 10; + // build query - $sql = "SELECT id, title, author, add_authors, identifier, UNIX_TIMESTAMP(date) AS date FROM metadata WHERE"; - - // build advanced query - if($search=="advanced") { - // set correct boolean value - if($match=="all") { $boolean = "AND"; } - else { $boolean = "OR"; } - - $has_date = $has_query = 0; - - // match all - if($query) { - $query = strip_html($query); - $sql .= " (MATCH(author, add_authors, affiliation, add_affiliations) AGAINST ('$query') OR MATCH(title) AGAINST ('$query') OR MATCH(abstract) AGAINST ('$query') OR MATCH(discipline, topic, publisher, contributors, approach, format, source, language, relation, coverage) AGAINST ('$query'))"; - $has_query = 1; + $sql = "SELECT id, title, author, add_authors, identifier, UNIX_TIMESTAMP(date) AS date"; + $criteria = array(); + + // set BOOLEAN operator for SQL criteria + // Only user selectable on advanced search + // QuickSearch defaults to AND + if($search == "advanced") { + if($match == "all") { + $boolean = " AND "; + } else { + $boolean = " OR "; } - - // match author - if($query_author) { - $query_author = strip_html($query_author); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(author, add_authors) AGAINST ('$query_author')"; - $has_query = 1; + } else { + $boolean = " AND "; + } + + // match archive + if(isset($archive) && $archive != "all") { + $archive = (int) $archive; + $criteria[] = "(archive = $archive)"; + } + + // match query text + if($query) { + $qry_txt = "+" . trim(implode(" +", explode(" ", $query))); + $match_query = array(); + + if(empty($limit) || !$limit) { + $limit = "all"; } - + // match author - if($query_affiliation) { - $query_affiliation = strip_html($query_affiliation); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(affiliation, add_affiliations) AGAINST ('$query_affiliation')"; - $has_query = 1; + if($limit == "all" || $limit == "author") { + $match_query[] = "author, add_authors, affiliation, add_affiliations"; } - + // match title - if($query_title) { - $query_title = strip_html($query_title); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(title) AGAINST ('$query_title')"; - $has_query = 1; + if($limit == "all" || $limit == "title") { + $match_query[] = "title"; } - + // match abstract - if($query_abstract) { - $query_abstract = strip_html($query_abstract); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(abstract) AGAINST ('$query_abstract')"; - $has_query = 1; - } - - - // match date from - if($query_date_from && check_date($query_date_from)) { - $query_date_from = strip_html($query_date_from); - if($has_query) { $sql.= " $boolean"; } - $sql .= " (date>='$query_date_from'"; - $has_query = 1; - $has_date = 1; - } - - // match date to - if($query_date_to && check_date($query_date_to)) { - $query_date_to = strip_html($query_date_to); - if($has_date) { $sql.= " AND"; } - else { $sql.= " $boolean"; } - $sql .= " date<='$query_date_to'"; - $has_query = 1; - } - - if($has_date) { - $sql .= ")"; - } - - // match discipline - if($query_discipline) { - $query_discipline = strip_html($query_discipline); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(discipline) AGAINST ('$query_discipline')"; - $has_query = 1; - } - - // match topic - if($query_topics) { - $query_topics = strip_html($query_topics); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(topic) AGAINST ('$query_topics')"; - $has_query = 1; - } - - // match coverage - if($query_coverage) { - $query_coverage = strip_html($query_coverage); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(coverage) AGAINST ('$query_coverage')"; - $has_query = 1; - } - - // match approach - if($query_approach) { - $query_approach = strip_html($query_approach); - if($has_query) { $sql.= " $boolean"; } - $sql .= " MATCH(approach) AGAINST ('$query_approach')"; - $has_query = 1; - } - - // match language - if($query_language) { - $query_language = strip_html($query_language); - if($has_query) { $sql.= " $boolean"; } - $sql .= " language='$query_language'"; - $has_query = 1; - } - - // match type - if($query_type && $query_type!="All") { - $query_type = strip_html($query_type); - if($has_query) { $sql.= " $boolean"; } - if($query_type=="Refereed Articles" || $query_type=="Reviewed Papers") { $sql .= " relation LIKE 'Refereed%'"; } - else if($query_type=="Dissertations") { $sql .= " type LIKE '%dissertation%'"; } - else { $sql .= " type LIKE '%$query_type%'"; } - $has_query = 1; - } - - // match archive - if(isset($archive) && $archive != "all") { - $archive = (int) $archive; - if($has_query) { $sql.= " $boolean"; } - $sql .= " archive='$archive'"; - $has_query = 1; - } - - } - - // build simple query - else { - $query = strip_html($query); - $sql .= " ("; - if(!$limit) { $limit = "all"; } - - // match author - if($limit=="all" || $limit=="author") { - $sql .= "MATCH(author, add_authors, affiliation, add_affiliations) AGAINST ('$query')"; + if($limit == "all" || $limit == "abstract") { + $match_query[] = "abstract"; } - - // match title - if($limit=="all" || $limit=="title") { - if($limit=="all") { $sql .= " OR "; } - $sql .= "MATCH(title) AGAINST ('$query')"; + + // match index terms + if($limit == "all" || $limit == "keywords") { + $match_query[] = "discipline, topic, publisher, contributors, approach, format, source, language, relation, coverage"; } - - // match abstract - if($limit=="all" || $limit=="abstract") { - if($limit=="all") { $sql .= " OR "; } - $sql .= "MATCH(abstract) AGAINST ('$query')"; + + if($limit == "all" || $limit == "subject") { + $match_query[] = "discipline, topic"; } - - // match index terms - if($limit=="all" || $limit=="keywords") { - if($limit=="all") { $sql .= " OR "; } - $sql .= "MATCH(discipline, topic, publisher, contributors, approach, format, source, language, relation, coverage) AGAINST ('$query')"; - } - - $sql .= ")"; - - // match archive - if(isset($archive) && $archive != "all") { - $archive = (int) $archive; - $sql .= " AND archive='$archive'"; + + $criteria[] = "(MATCH(" . implode(", ", $match_query) . ") AGAINST('$qry_txt' IN BOOLEAN MODE))"; + } + + // match author + if($query_author) { + $qry_txt = "+" . trim(implode(" +", explode(" ", $query_author))); + $criteria[] = "(MATCH(author, add_authors) AGAINST ('$qry_txt' IN BOOLEAN MODE))"; + } + + // match subject + // Added May 23, 2005 - robackja + if($query_subject) { + $qry_txt = "+" . trim(implode(" +", explode(" ", $query_subject))); + $criteria[] = "(MATCH(discipline, topic) AGAINST ('$qry_txt' IN BOOLEAN MODE))"; + } + + // match title + if($query_title) { + $qry_txt = "+" . trim(implode(" +", explode(" ", $query_title))); + $criteria[] = "(MATCH(title) AGAINST ('$qry_txt' IN BOOLEAN MODE))"; + } + + // match abstract + if($query_abstract) { + $qry_txt = "+" . trim(implode(" +", explode(" ", $query_abstract))); + $criteria[] = "(MATCH(abstract) AGAINST ('$qry_txt' IN BOOLEAN MODE))"; + } + + // match date from + if(!empty($query_date_from) && check_date($query_date_from)) { + $date_criteria = "(date >= '$query_date_from'"; + if(!empty($query_date_to) && check_date($query_date_to)) { + $date_criteria .= " and date <= '$query_date_to 23:59:59'"; + } + $date_criteria .= ")"; + $criteria[] = $date_criteria; + } + + // match language + if($query_language) { + $criteria[] = "(language in ('', '$query_language') or language is null)"; + } + + // match type + if($query_type && $query_type != "All") { + if($query_type == "Refereed Articles" || $query_type == "Reviewed Papers") { + $criteria[] = "(relation LIKE 'Refereed%')"; + } else if($query_type=="Dissertations") { + $criteria[] = "(type LIKE '%dissertation%')"; + } else { + $criteria[] = "(type LIKE '%$query_type%')"; + } + } + + $from_where = trim(implode($boolean, $criteria)); + $from_where = " FROM metadata" . ((count($criteria) > 0) ? " WHERE $from_where" : ""); + $sql .= $from_where; + + if(!$records) { + $metadata_count = $db->query("SELECT COUNT(*) as records" . $from_where); + $record_count = $db->assoc_array($metadata_count); + $records = (int) $record_count["records"]; + } + + if(!empty($sort) && $sort) { + $sort_order = array(); + if ($sort == "date_asc") { + $sort_order[] = "date"; + } else if ($sort == "date_desc") { + $sort_order[] = "date desc"; + } else if ($sort == "author") { + $sort_order[] = "author"; + } else if ($sort == "title") { + $sort_order[] = "title"; } + $sort_order[] = "id"; + $sql .= " order by " . implode(",", $sort_order); + } else { + $sql .= " order by date desc, id"; } - - // execute the query and print out the results + + $seek = $page * $max_records; + $sql .= " limit $seek,$max_records"; + + // Log SQL stmt to apache error_log + error_log($sql); + + //execute the query and print out the results $metadata_result = $db->query($sql); - - // get number of records + //get number of records $num_records = $db->num_rows($metadata_result); - - // maximum records to display at one time - $max_records = 10; - - // move to specified position if applicable - if($page) { - $new_position = ($page-1)*$max_records; - - if($new_position>$num_records) { - $new_position = 0; - $page = 1; - } - - $db->data_seek($metadata_result, $new_position); + + if(!empty($query)) { + echo "Search Results for \"$query\"

\n"; + } else { + echo "Search Results

\n"; + } + + if($num_records > 0) { + $start_pos = $seek + 1; + $stop_pos = $seek + $num_records; + echo "Displaying records $start_pos through $stop_pos of $records.

\n"; } else { - $new_position = 0; - $page = 1; + echo "No Results Found.

\n"; } - - // set number of records to display on this page - if($max_records>($num_records-$new_position)) { - $num_to_show = $num_records-$new_position; - } - else { - $num_to_show = $max_records; - } - - // show info on records currently being displayed - $start_pos = $new_position+1; - $end_pos = $new_position+$num_to_show; - - if($query) { echo "Search Results for \"$query\" -

"; } - else { echo "Search Results -

"; } - - if($num_records>0) { - echo "Displaying records $start_pos through $end_pos of $num_records. -

"; - } - else { - echo "No results found. -

"; - } - - echo "
"; - - // print out records list - for($i=0;$i<$num_to_show;$i++) { + + echo "
\n"; + + //print out records list + for($i = 0; $i < $num_records; $i++) { $record_items = $db->assoc_array($metadata_result); - echo "\"\" $record_items[title]
-
\n"; + + echo "\"\" \n"; + echo "$record_items[title]
\n"; + echo "
\n"; + if(!empty($record_items[author])) { echo "$record_items[author]
\n"; } - $add_authors = split("\n",$record_items[add_authors]); - for($x=0; $x\n"; + + $add_authors = split("\n",$record_items["add_authors"]); + foreach($add_authors as $a) { + if(!empty($a)) { + echo "$a
\n"; } } - if($record_items[date] != "0000-00-00") { - echo "".date("F j, Y",$record_items[date])."
"; + + if($record_items["date"] != "0000-00-00") { + echo "" . date("F j, Y",$record_items["date"]) . "
"; } - echo "View Record | View Original\n -
\n
\n"; + + echo "View Record | View Original\n"; + echo "
\n
\n"; } - - echo "
"; - - - // build query string for prev/next urls - if($search=="advanced") { - if($query) { - $query = str_replace(" ","%20",$query); - $string .= "query=$query&"; - } - if($query_author) { - $query_author = str_replace(" ","%20",$query_author); - $string .= "query_author=$query_author&"; - } - if($query_title) { - $query_title = str_replace(" ","%20",$query_title); - $string .= "query_title=$query_title&"; - } - if($query_date_from) { - $query_date_from = str_replace(" ","%20",$query_date_from); - $string .= "query_date_from=$query_date_from&"; - } - if($query_date_to) { - $query_date_to = str_replace(" ","%20",$query_date_to); - $string .= "query_date_to=$query_date_to&"; - } - if($query_discipline) { - $query_discipline = str_replace(" ","%20",$query_discipline); - $string .= "query_discipline=$query_discipline&"; - } - if($query_topics) { - $query_topics = str_replace(" ","%20",$query_topics); - $string .= "query_topics=$query_topics&"; - } - if($query_approach) { - $query_approach = str_replace(" ","%20",$query_approach); - $string .= "query_approach=$query_approach&"; - } - if($query_coverage) { - $query_coverage = str_replace(" ","%20",$query_coverage); - $string .= "query_coverage=$query_coverage&"; - } - if($query_type) { - $query_type = str_replace(" ","%20",$query_type); - $string .= "query_type=$query_type&"; - } - if($match) { - $match = str_replace(" ","%20",$match); - $string .= "match=$match&"; - } - $string .= "search=advanced&is_search=1"; - } - else { - $query = str_replace(" ","%20",$query); - $string = "query=$query&limit=$limit"; + + echo "
\n"; + + foreach($get_vars as $var) { + if(isset($$var) && !empty($$var) && $var != "page") { + $qry_str[] .= "$var=" . htmlentities(trim($$var)); + } } - - + $string = implode("&", $qry_str); + // show next and prev page links, if applicable - if($page>1) { - $prev_page = $page-1; - $prev_link = "<< Previous Results"; - - } - - if($num_records>($page*$max_records)) { - $next_page = $page+1; - $next_link = "Next Results >>"; + if($page > 0) { + $prev_page = $page - 1; + $prev_link = "<< Previous Results"; } - - if($next_link||$prev_link) { + + $next_page = $page + 1; + if($records > ($next_page * $max_records)) { + $next_link = "Next Results >>"; + } + + if($next_link || $prev_link) { echo ""; echo $prev_link; if($prev_link && $next_link) { - echo " | "; + echo " | "; } echo $next_link; echo "

"; } - - echo "\"\" New Search"; -} -// show advanced search form -else if($search=="advanced") { + echo "\"\" New Search\n"; +} else if($search == "advanced") { + // show advanced search form ?> -
- - Advanced OAI Search -

-This site adheres to the Open Archives Initiative which is the emerging standard for "open access" research resources and, as such, permits the collective searching of the metadata for all documents in OAI databases. What follows is the template used by authors to provide metadata for their documents within the indexed systems. -

-To go beyond the systems in this archive and extend the search to all registered OAI databases, go to OAIster. - -

+ + +
- -
- Search databases: - -
- -
- Search all categories for: - -
- -
- Or search any one or more of the following categories... -
- -
- Author(s): -
- -
- Author Name: - -
- -
- Affiliation: - -
- -
- Title: - -
- -
- Abstract: - -
- -
- Date: -
- -
- From: - -
- -
- To: - -
- -
- Index terms (about) -
- You may wish to consult the Library of Congress Classification Outline for common index terms. -
- -
- Discipline(s): - -
- -
- Subject(s): - -
- -
- Approach/Method: - -
- -
- Coverage: - -
- -
- Language: -
- English=en; French=fr; Spanish=es (Additional codes).
-
- -
- Sponsor(s): - -
- -
- Type: - -
- -
- Match all search categories -
- -
- -
- -
 
- -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Search Archives:  + +
Search all categories for: 
Author(s) Name: 
Subject: 
Title: 
Abstract: 
From: 
To: 
Language:  +   + English=en; French=fr; Spanish=es (Additional codes). +
Type:  + +
Sort Results By:  + +
Results Per Page:  + +
  /> Match all search criteria
 
 
 
+
- + Go to Quick Search -
Quick Search -

-Search papers for: - in + + + +
+Search papers for:  + in + +
- -
+ Go to Advanced Search +
  +
  +
  +