OPAC spellchecker using Yahoo! webservice
Tags: advanced, opac, spelling, aleph
Last Updated: Oct 30, 2009 00:49
- License: BSD style
- Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.
- Link to terms: [Detailed license terms]
- Skill required for using this code:
advanced
Description
There are several ways to provide your OPAC with a spellchecker. This is one way using the Yahoo! webservice. You could hook it up to other spellcheckers like the Google SOAP webservice or Pspell. This example uses the javascript framework of Prototype for DOM manipulation, AJAX call and PHP to handle the communication with the Yahoo! REST webservice. It does require that you register your application with Yahoo! and there is a limit of 5000 requests / day.
State
Stable
Screen captures

Author(s) homepage
http://www.bibl.hj.se
Download
See the attachments.
Working example
http://julia.hj.se [Aleph:though we use the Google SOAP service the mechanism is more or less the same]
Installation instructions
1. Download the javascript framework Prototype
2. Make Prototype available in your OPAC. We include it in meta-tags
<Code sample>
<script type="text/javascript" src="path_to_where_you_put_it/prototype.js"></script>
</Code sample>
3. On the page where you want to include the spellchecker you need to obtain the search terms and pass them on the back end script that queries the Yahoo! webservice. Include this javascript where you want to check the terms. Find-b-list-head is a good place to include it. Also on the page where you include the script you want to add a Div so that the AJAX call knows where to include the spelling suggestion once it returns.
<Code sample>
<div id="Suggestion"></div>
<script language="javascript" type="text/javascript" src="path_to_where_you_put_it/spell.js" ></script>
</Code sample>
4. Put the yahoo.php file on your webserver. You will need PHP on the ALEPH OPAC server. Due to security you can not AJAX requests across servers. You will also need to register for a application ID with Yahoo!, you also might want to look at the documentation for the Spelling Suggestion Service. Edit the yahoo.php file and enter your Application ID and URL for the OPAC.
<Code sample>
<?php
//Define and receive the search terms
$term = $_GET\['URL'\];
//Uncomment below to test service
//$term = 'ammerica';
//Set up for making the call to the service, you need a Application ID that you get from Yahoo\! Developer zone
$request = 'http://search.yahooapis.com/WebSearchService/V1/spellingSuggestion?appid=YOURAPPID&query='.$term.'';
//Make the call
$xml = simplexml_load_file($request);
//If there is no suggestion, let the user know
if (empty($xml->Result)){
echo "No suggestion available<br>";
}else{
//if there is a suggestion, let the user know what it is and give them a link to the opac
foreach ($xml->Result as $suggestion) {
$suggest = $xml->Result;
$suggest2 = http_build_query($suggest);
$suggest3 = str_replace('0=','',$suggest2);
echo "Did you mean <a href=http://YOUROPAC/F/?func=find-b&request=$suggest3&find_code=WRD&adjacent=N&x=53&y=1&con_lng=eng>$suggest?</a>";
}
}
//The image below needs to be included according the terms of use with Yahoo\!
?>
<br /><br />
<a href="http://developer.yahoo.com/" >
<img src="http://l.yimg.com/us.yimg.com/i/us/nt/bdg/websrv_120_1.gif" border="0">
</a>
</Code sample>
TO DO list
Look into the handling of scandinavian diacritics making sure they work and are being displayed correct
Known issues
Response time from the webservice
Comments
Text...
Comments (13)
Sep 11, 2008
Ori Miller says:
It would be nice if someone could rewrite the PHP code in perl, since perl is in...It would be nice if someone could rewrite the PHP code in perl, since perl is installed by default in all UNIX systems.
Other than that - good job and well explained.
Sep 16, 2008
Glenn Pillsbury says:
This is great.This is great.
Sep 12, 2008
Daniel Forsman says:
If you can't install PHP on your Aleph server but have access to it on another s...If you can't install PHP on your Aleph server but have access to it on another service the PHP part can be included through a Iframe. I'll post a example of that aswell.
If there is a interest I could also make a post to the wiki on how we compiled PHP on the Aleph webserver. And then ... if you could get the aleph apache module to work with php you could do some really interesting things.
As for the Perl part, i'm sure someone has done this with Perl. I just feel more confident with PHP then perl so I don't think i'm the right guy for that.
Sep 25, 2008
Glenn Pillsbury says:
I've made a simple modification to the spell.js file to extract the find_code va...I've made a simple modification to the spell.js file to extract the find_code value (WRD, WTI, etc) of the search and pass that along to yahoo.php and then to the "did you mean" link. It seemed helpful to maintain the same kind of search the user initially chose.
I would like to contribute my file to the project if you're interested.
Oct 12, 2008
Daniel Forsman says:
Glenn, please contribute!Glenn, please contribute!
Sep 25, 2008
Glenn Pillsbury says:
One potential glitch I found while implementing this occurred if the initial sea...One potential glitch I found while implementing this occurred if the initial search URL was not constructed like "&request=XXXXX&find_code=XXX". The order in which the variables appear in the URL is determined by the order in which they appear in the source code of the html form. For example, one of our search boxes uses hidden fields for all the variables except request. The spellchecker didn't work until I rearranged the order of the hidden fields to have the find_code hidden field come immediately after the request field.
It would be best if the spell.js could extract the request based on a regular expression that looked for "&request=XXXXXXX&" only, and didn't rely on the presence of another variable as a "stop" location.
Still, this feature has been received very well by our librarians! Thanks!
Oct 08, 2008
Mark Watmough says:
Thanks for placing this on here Daniel - it spurred me onto have a look at it wi...Thanks for placing this on here Daniel - it spurred me onto have a look at it with our catalogue.
We haven't got a PHP enabled Aleph server, so we couldn't use the method you suggested. I did however notice that you can contact the yahoo database and get a return in JSON format (similar to the recent googlebooks enhancement). I have this working on our test server currently, with a view to going live with it. If anyone would like to see this, or have access to the code, then i'd be more than happy to oblige.
Oct 13, 2008
Daniel Forsman says:
Ah, that is cool. I need to look into javascript xml-parsers someday. Also, I ...Ah, that is cool.
I need to look into javascript xml-parsers someday.
Also, I would just like to say that I do not mind if someone wants to do updates to the attached files. Just add a version number if you make improvments.
Mark, GJ! You should put up a page with that spellchecker here on El Commons!
Apr 07, 2009
Rodrigo Calloni says:
Hello Mark Could please share this code with us too? I am a hosted ALEPH custom...Hello Mark
Could please share this code with us too? I am a hosted ALEPH customer so no PHP server for us in our hosted machine.
Thanks in advance!
Rodrigo
Apr 09, 2009
Mark Watmough says:
Hi Rodrigo, I finally managed to add a page to the El Commons site detailing th...Hi Rodrigo,
I finally managed to add a page to the El Commons site detailing the Yahoo spelling suggestion service JSON response implementation. You can find it here.
Thanks,
Mark.
Nov 28, 2008
Gisela Weber says:
Hello, I've just been entrusted to maintain our OPAC and therefor I'm not yet v...Hello,
I've just been entrusted to maintain our OPAC and therefor I'm not yet very familiar to it. I'm looking for a possibility to include spell-checking and think the method described here fits our needs.
As I started experimenting with the php-code above, it seemed not to be necessary to use the Prototype-Framework as I get results with the php-script alone.
Can someone please explain to me, what Prototype is good for or how/why to use it? I also would be glad to get links.
Greetings
Jonas
Nov 28, 2008
Daniel Forsman says:
What Prototype does in this case is that it handles the call to the PHP script f...What Prototype does in this case is that it handles the call to the PHP script from the OPAC. If you run the PHP script stand alone you will get the results. The problem for me was to get the Aleph apache module to run PHP code. If you have done that I would be very happy to hear how you did it.
So basicly what Prototype does is that it handles the AJAX call to the script from the OPAC.
There are other javascript libraries that you could use if you don't like Prototype. Ex Libris seems to be working a lot with Jquery for other products.
Does this help?
Apr 07, 2009
Rodrigo Calloni says:
Hello Daniel and all, I've asked about the files related to this development......Hello Daniel and all,
I've asked about the files related to this development... I just realized that the files are in the attachment link at the top.
First time using this, sorry about that.
Best regards,
Rodrigo