local spell checker
Tags: perl
, javascript
, aleph
Last Updated: Oct 30, 2009 00:48
- Description
A couple of scripts to put a spell check facility into the OPAC to suggest new searches when users mispell search terms.
- Author: Patrick H Pollard
- Additional author(s):
- Institution:
University of Bristol - Year: 2008
- 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:
Basic to copy and paste, intermediate to change.
State
Development
Programming language
Javascript, Perl
Software requirements
Aspell
Screen captures
Author(s) homepage
Download
Attach the code file(s) to this page and link to them here.
Page attachments management can be reached from the top-right menu - 'attachments' after page save.
Working example
http://talitha.lib.bris.ac.uk:8997/F/
Using the following Ex Libris open interfaces
Text...
Changes
Version 1.2 ....
Text...
Version 1.1 ....
Text...
...
Text...
Release notes
This is a couple of scripts to provide a "Did you mean" type suggestion based on spell checking search terms when no results are retrieved by a search.
Installation instructions
1) Nicely ask your system admin to install aspell for you on your Aleph machine. Aspell is a GNU library available from here.
2) Create a perl script called spell.pl in alephe/apache/cgi-bin as follows:
3. Chmod the script to be runable. This perl script is a wrapper which receives a word or phrase, runs it through aspell and returns a word or phrase with aspell's highest ranking spelling suggestion inserted over any misspellings.
4. Test it on the command line as follows perl -T spell.pl phrase=speling and it should reply xsuggest('spelling');. Please note the path to aspell specified in the script - if you have it installed elsewhere, this will need changing.
5. Look in head-1-nobor (or whatever file is your default file for where your no results message occurs) in your opac web file folder and find the placeholder for the no results message. In our case it appear as follows:
6. Add the following directly after.
7. To explain - this is composed of a div called Patrick (not very original I know
) which will hold the suggested spelling (which comes in the form of a link to a new search based on that spelling), a set of javascript to search the url for the query, pass it to the perl script and retrieve results from it. Please note the line:
This is the message displayed when no results are found in our catalogue - you will have to change it to whatever is displayed in yours, otherwise the script(s) will never be triggered. Also the var msg='$8000'; just above it will need changing if your placeholder is numbered differently.
It is also worth mentioning that this is running on the 3 indexes we allow to be searchable WAU, WTI, WSU - if you use different ones you will have to change the script.
8. Thats it - as ever after changing an OPAC page "touch" it to ensure the change is picked up.
TO DO list
My code works, but its rather inelegant - if anyone wants to make it neater, smaller and cleverer then please feel free.
Aspell is only as good as the dictionary it uses - this version uses the plain dictionary it was installed with. It would be nice to create a custom dictionary, say of authors names.
Known issues
Tested on firefox and IE - but no idea if it works on any other browsers. If you find any other problems or anything, feel free to drop me a line - my e-mail is in the perl script.
Comments
Text...


4 Comments
comments.show.hideOct 23, 2008
Daniel Forsman
GJ Patrick! I added the 00code00 tag hopefully that will put this page in the developerzone.
Oct 24, 2008
Sharon Adams
Daniel,
Basically if someone uses the contribute code from developer zone, the system automatically put this tag
Anyway, thanks for your attention.
Oct 25, 2008
Daniel Forsman
Sharon,
I know, but Patrick had deleted the tag so this wasn't showing up in the developer zone until i added it. I made the same error of deleting the 00code00 tag when i put stuff up and then wondering where it went. It was when I realised that the 00tag00 actually had a meaning and rescuing the page I created that I found Patricks page. Also with the 00tag00 missing and therefor not visible in the developer zone.
Apr 12, 2010
Jim Adamson
Thank you Patrick for sharing this. I have implemented this in our OPAC, with some modifications:
(a) In my implementation, the script fires when find-b-list-head or find-b-permute-head pages loads - the assumption being that if the user hasn't got any close matches, it could be that they entered mispelt search terms. Our version 19 OPAC does not display the message $8000 when no results are found for most of our indexes; it just shows the nearest matches in one of the two aforementioned pages.
(b) I inserted a small function, called when the above pages load, which decides which indexes to spell check. This results in less javascript code overall:
(c) I also changed the spellcheck function, using DOM syntax, as I had trouble getting your original function to work properly:
Our OPAC is located at http://libcatalogue.york.ac.uk .Thanks again!