Spelling Suggestions for WebVóyage with aspell and PHP
Disclaimer
Code and instructions for implementing aspell Spelling Suggestion features for WebVóyage.
Use at your own risk. TCC is not responsible for damage or problems caused by the use of this code.
No warranties or guarantees of any kind are implied or assumed.
For use with the WebVóyage product by Endeavor Systems, Inc. Ex Libris™ LTD.
"WebVóyage" is a trademark of Endeavor Information Systems, Inc. Ex Libris™ LTD.
Purpose: Javascript and PHP scripts use aspell
to check a user's spelling when no hits are found in OPAC.
No warranties or guarantees of any kind or implied. use at your own risk.
It works for us, so we thought we'd share... ;-)
By using this software the USER indicates that he or she
has read, understood and and will comply with the following:
TCC hereby grants USER permission to use, copy, modify, and
distribute this software and its documentation for any
purpose and without fee, provided that:
the above copyright notice appears in all copies of the
software and its documentation, or portions thereof, and
a full copy of this notice is included with the software
and its documentation, or portions thereof, and
neither the software nor its documentation, nor portions
thereof, is sold for profit. Any commercial sale or license
of this software, copies of the software, its associated
documentation and/or modifications of either is strictly
prohibited without the prior consent of TCC.
Title to copyright to this software and its associated
documentation shall at all times remain with TCC. No right
is granted to use in advertising, publicity or otherwise any
trademark, service mark, or the name of TCC.
This software and any associated documentation are provided
"as is," and TCC MAKES NO REPRESENTATIONS OR WARRANTIES,
EXPRESSED OR IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR
FITNESS FOR A PARTICULAR PURPOSE, OR THAT USE OF THE SOFTWARE,
MODIFICATIONS, OR ASSOCIATED DOCUMENTATION WILL NOT INFRINGE
ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER INTELLECTUAL
PROPERTY RIGHTS OF A THIRD PARTY. TCC, Tarrant County College,
its Regents, officers, and employees shall not be
liable under any circumstances for any direct, indirect, special,
incidental, or consequential damages with respect to any claim
by USER or any third party on account of or arising from the
use, or inability to use, this software or its associated
documentation, even if TCC has been advised of the possibility
of those damages.
This code is meant to be used with the WebVóyage product by Endeavor Systems, Inc. Ex Libris™ LTD.™
When a user search of the library catalog receives no hits, the user's search criteria is sent to aspell.
aspell will return a spelling suggestion if the word is misspelled.
The javascripts, php source, images, and html are enclosed in PHP_spellcheck.zip.
You can see these scripts in action at http://library.tccd.edu.
Enter a mispelled word, such as pikcle or "captian cook".
Requirements:
PHP must be installed on the WebVóyage server. If you do not have PHP
installed and don't wish to install it, feel free to rewrite this for Perl
(which is installed on your WebVóyage server) or ColdFusion or any other server-side processor you have available to you.
(There's a Perl interface available at CPAN or you can try my
Perl installation instructions.)
Due to JavaScript security issues, the server-side processing must be done on the same server unless you have a signed
security certificate installed, which I haven't done and can't help with... ;-)
The spelling suggestion uses JavaScript. Browsers with JavaScript disabled will not be able to take advantage of this code,
but it will not prevent them from using WebVóyage normally.
Download, compile and install aspell-0.60.2 in /usr/local (Note: When we purchased new hardware in August 2007, we also upgraded to Solaris 10 and Voyager 6.5.2. aspell was already installed.)
check /m1/voyager/shared/apache2/conf/httpd.conf for LoadModule php5_module modules/libphp5.so
If this line does not exist, backup httpd.conf and add it.
check /m1/voyager/shared/apache2/conf/httpd.conf for AddType application/x-httpd-php .php
If this line does not exist, backup httpd.conf and add it.
Install spellchecker PHP files
In /m1/voyager/tardb/webvoyage/html/, add the spellchecker folder included in the zip file.
In /m1/voyager/tardb/webvoyage/html/js/, add the spell.js file included in the zip file.
In /m1/voyager/tardb/webvoyage/html/images/, add the load.gif file included in the zip file.
Tell WebVóyage to check spelling
In /m1/voyager/tardb/etc/webvoyage/local/nohitsmsg.htm, add the following lines:
<img src="/images/load.gif" onload="spellCheck();" >
Your search resulted in no hits!
<div name="spellMessage" id="spellMessage">.</div>
In /m1/voyager/tardb/etc/webvoyage/local/badformmsg.htm, add the following lines:
<img src="/images/load.gif" onload="spellCheck();" >
Your search resulted in no hits!
<div name="spellMessage" id="spellMessage">.</div>
How It Works
When nohitsmsg.htm or badformmsg.htm are accessed (by the user not getting
any search results), the tiny GIF image is loaded, calling the spellCheck
javascript function found in /js/spell.js.
In spell.js, an XMLHttpRequest object is created and
all user search criteria is gathered together. This information is sent to
/spellcheck/spell.php.
In spell.php, aspell is consulted and returns spelling suggestions, then spell.php
outputs this information to the JavaScript.
While aspell is being consulted, the user sees the message "Searching for suggestions..."
When results are returned, the JavaScript then replaces this
message with the new information, where it is printed in nohitsmsg.htm,
which happens to be in the middle of the user's web page. Voila!
Changes
v1.2 - (2007.08.14) Changes Global Keyword searches to Command Searches for use with the AND, OR and NOT Booleans in the suggestions.
v1.1 - (2007.05.07) Added support for Simple and Combined Searches.
v1.0 - (2006.08.01) Initial release using PHP and aspell.
v0.1 - (2004.08.01) Used Google's SOAP interface (available here). Developer keys are no longer available from Google.
Troubleshooting
You must have root access to compile and install source code and packages.
If you are having problems installing PHP, the problem may lie in the Solaris libxml2 libraries. For some reason, even if you specifically tell PHP to use the new libxml2 install, it ignores it and looks for any and all old versions.
There a couple of ways to fix this, both of them involve installing new libxml2 libraries.
The correct way: remove all libxml2 packages and install a new one from sunfreeware.
The safe way: rename all current libxml2 libraries (e.g., libxml2.so-bak), then install the new libxml2 packages, then create symbolic links from all the re-named files to the newly installed files.
I could not configure PHP with the default configure file.
I received the error configure: error: You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropiate switch --with-apxs (without the 2), even though I knew it was apache2.
In order to get around it, I commented out lines 6552-6556 in the configure file, like so:
6552 #if test "$APACHE_VERSION" -le 2000000; then
6553 # { echo "configure: error: You have enabled Apache 2 support while your server is Apache 1.3. Please use the appropiate...
6554 #elif test "$APACHE_VERSION" -lt 2000044; then
6555 # { echo "configure: error: Please note that Apache version >= 2.0.44 is required" 1>&2; exit 1; }
6556 #fi
Questions and comments can be sent to Jim Robinson at Tarrant County College.