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.
Version 1.2
Scripts by Jim Robinson
Tarrant County College
828 Harwood Rd.
Hurst, TX 76054-3299
(817) 515-4310
Email
Copyright © 2024, Tarrant County College ("TCC"). All rights reserved.

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.

PHP Copyright© 2001-2005 The PHP Group All rights reserved.

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:
  1. the above copyright notice appears in all copies of the software and its documentation, or portions thereof, and
  2. a full copy of this notice is included with the software and its documentation, or portions thereof, and
  3. 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.
  4. 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.
  5. 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.
  • aspell and a dictionary must be installed and working.

Instructions

    These instructions assume you have an up-to-date compiler installed and root access to your server.
  1. Log in to your webvoyage server, change to a source directory. I use /opt/sfw/src/. You can use /export/home/voyager if you like.
  2. su root (Use sudo if you have it set up)
  3. Download and install ncurses-5.6 package in /usr/local
    1. curl -O ftp://ftp.sunfreeware.com/pub/freeware/sparc/9/ncurses-5.6-sol9-sparc-local.gz
    2. gunzip ncurses-5.6-sol9-sparc-local.gz
    3. pkgadd -d ncurses-5.6-sol9-sparc-local
  4. Download and install libgcc-3.3 package in /usr/local/lib
    1. curl -O ftp://ftp.sunfreeware.com/pub/freeware/sparc/9/libgcc-3.3-sol9-sparc-local.gz
    2. gunzip libgcc-3.3-sol9-sparc-local.gz
    3. pkgadd -d libgcc-3.3-sol9-sparc-local
  5. 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.)
    1. curl -O ftp://ftp.sunfreeware.com/pub/freeware/sparc/9/aspell-0.60.2-sol9-sparc-local.gz
    2. gunzip aspell-0.60.2-sol9-sparc-local.gz
    3. pkgadd -d aspell-0.60.2-sol9-sparc-local
  6. Download and install an English dictionary in /usr/local/aspell-0.60
    1. curl -O ftp://ftp.gnu.org/gnu/aspell/dict/en/aspell6-en-6.0-0.tar.bz2
    2. bunzip2 aspell6-en-6.0-0.tar.bz2
    3. tar -xvf aspell6-en-6.0-0.tar
    4. cd aspell6-en-6.0-0
    5. ./configure
    6. make
    7. make install
  7. Test the aspell install.
    1. Create a file with a misspelled word or 2 and call it spelling_error.txt (or use the one in the zip file)
    2. /usr/local/bin/aspell -c spelling_error.txt
  8. Install PHP configured to use aspell
    1. curl -O http://us2.php.net/distributions/php-5.2.3.tar.gz
    2. gunzip php-5.2.3.tar.gz
    3. tar -xvf php-5.2.3.tar
    4. cd php-5.2.3
    5. ./configure --prefix=/usr/local/php --with-apxs2=/m1/shared/apache2/bin/apxs --with-pspell=/usr/local
    6. make
    7. make install
    8. cp php.ini-dist /usr/local/lib/php.ini
    9. 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.
    10. 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.
  9. Install spellchecker PHP files
    1. In /m1/voyager/tardb/webvoyage/html/, add the spellchecker folder included in the zip file.
    2. In /m1/voyager/tardb/webvoyage/html/js/, add the spell.js file included in the zip file.
    3. In /m1/voyager/tardb/webvoyage/html/images/, add the load.gif file included in the zip file.
  10. Tell WebVóyage to check spelling
    1. 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>
    2. 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.
    1. The correct way: remove all libxml2 packages and install a new one from sunfreeware.
    2. 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.

Last modified: August 14 2007.