Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Site search finally available

I’ve finally got around to adding a search page to this site. It uses MySQL’s full text indexing, which is extremely fast and provides good results but comes at the expense of flexibility. Search terms less than 4 letters long are ignored, and multi-word searches are handled using OR rather than AND. This nearly put me off using it, but the relevancy algorithm is excellent which I think outweighs the disadvantage of not being able to use pure AND queries.

MySQL 4.0 introduces far more powerful boolean mode full text searches which allow all kinds of modifiers and extra syntax, but this site currently runs on 3.23.54 so I can’t play with those just yet. Jeremy Zawodny’s article on MySQL 4 explains boolean mode and describes many other exciting new MySQL features as well.

This is Site search finally available by Simon Willison, posted on 25th April 2003.

View blog reactions

Next: Experimental feature: Related entries

Previous: Show Computed Styles (yet again)

4 comments

  1. You can kludge AND searches in MySQL 3, it just takes a much longer query. Instead of doing MATCH (field) AGAINST (term1, term2) > 0 (which is an OR query), you do: MATCH (field) AGAINST (term1) > 0 AND MATCH (field) AGAINST (term2) > 0. Obviously this is going to be a little slower but it isn't noticeable.

    Tim - 25th April 2003 17:42 - #

  2. If you want to search for words less the 4 chars then check out this php code: http://davidaltherr.net/web/php_functions/boolean/ article.mysql.boolean. I use it and it does work. cheers

    Richard Hulse - 25th April 2003 22:42 - #

  3. Hurray!! :D

    michel v - 27th April 2003 12:59 - #

  4. How do you handle HTML-tags in the text?

    Pepino - 13th May 2003 20:51 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/04/25/siteSearch

A django site