Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement full text search using DSpace OpenSearch API #4

Open
mzarafon opened this issue Sep 15, 2017 · 1 comment
Open

Implement full text search using DSpace OpenSearch API #4

mzarafon opened this issue Sep 15, 2017 · 1 comment

Comments

@mzarafon
Copy link

The API call looks like this:

https://scholarship.tricolib.brynmawr.edu/open-search/discover?query=" . $query . "&scope=10066/4022&order=DESC&rpp=20&sort_by=0&page=1&etal=0

Where $query is the search query

@apjanco
Copy link
Contributor

apjanco commented Sep 18, 2017

From previous Drupal project: `<?php
//section header
echo "

Full Text Search

";

//get current url to find out what the user searched
$url = $_SERVER["REQUEST_URI"];
$index1 = strpos($url, "site/") + 5;
$index2 = strpos($url, "?");
if($index2 === false){
$query = substr($url , $index1 );
}else{
$query = substr($url , $index1 , $index2-$index1 );
}

//Narrow Scope to Just AQSI Statements

//Open Search does everything in D-Space

//convert weird character codes like '&' and spaces into the right code for Dspace
$query = str_replace("%25", "%", $query );
$more_url = "https://scholarship.tricolib.brynmawr.edu/open-search/discover?query=" . $query . "&scope=10066/4022&order=DESC&rpp=20&sort_by=0&page=1&etal=0";
echo "

<a href="" . $more_url . "">Narrow Results- (Search only AQSI Statements)

";

//Open Search feed for DSpace
$feed_url = "https://scholarship.tricolib.brynmawr.edu/open-search/discover?query=" . $query . "&format=rss&rpp=100&scope=10066/4022";

// Debugging code for OpenSearch queries to make sure the API call is formatted correctly -Mike Z//

// echo "

" . $feed_url . "
";

// End debugging code //

//get the xml file associated with that search

//this will have all the data including title, link, and description

//we will format this file to full the full text search with data
$data = file_get_contents($feed_url);

//get rid of the extra tags at the top of the document

//this is extra information about the feed that we don't need
$header_index = strpos($data, "");
$data = substr($data , $header_index);

//get each individual entry, so we can go through it one at a time in our for loop
$array = explode("" , $data);
$len = count($array);

//formatting to match regular searches
echo "<ol class="search-results apachesolr_search-results">";

//first one is empty not sure why, but there's no data there, so we'll skip it

//the first statement starts at index 1
for ($i=1; $i<$len; $i++){
//Statement Title
$index1 = strpos($array[$i], "<title>") + 7;
$index2 = strpos($array[$i],"</title>" , $index1);
$title = substr($array[$i] , $index1 , $index2-$index1 );
//url to the statement
$index1 = strpos($array[$i], "<link") + 6;
$index2 = strpos($array[$i], "/>" , $index1);
$statement_location = substr($array[$i] , $index1 , $index2-$index1 );
//statement description
$index1 = strpos($array[$i], "<summary type="text">") + 21;
$index2 = strpos($array[$i], "" , $index1);
$description = substr($array[$i] , $index1 , $index2-$index1 );
//published date
$index1 = strpos($array[$i], "") + 11;
$index2 = strpos($array[$i], "" , $index1);
$date = substr($array[$i] , $index1 , $index2-$index1 );
//format the date
$year = substr($date , 0 , 4 );
$month = substr($date , 5 , 2 );
$day = substr($date , 8 , 2 );
$date = "( $month - $day - $year)";
//print out this data and format it the same way as the Apache Solr searches
echo "<li class="search-result"><h3 class="title">";
echo "<a " . $statement_location . " class="search-result" >" . $title . "
<div class="search-snippet-info">
<p class="search-snippet">" . $description . $date . "



";
}
echo "";
if($len ==21){
//there are more results that we can't see
//convert weird character codes like '&' and spaces into the right code for Dspace
$query = str_replace("%25", "%", $query );
$more_url = "http://triceratops.brynmawr.edu/dspace/handle/10066/4022/discover?order=DESC&rpp=20&sort_by=0&page=2&query=" . $query . "&etal=0";
echo "

<a href="" . $more_url . "">More Full Text Results...

";
}
?>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants