MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old June 13th, 2000, 07:42 AM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I've got a table with a load of plain text news articles in it, and I want to allow users to search for stories that contain particlar word(s).

So I'm doing something like:

SELECT *
FROM stories
WHERE text LIKE '%searchword%';

The problem is with the % wildcards. This will happily find the word I want, but not just a whole word but part of a word too, eg. it will find "park" even in "parked" and "parking".

And obviously this is what I'd expect because that's what the % wildcard means.

But is there a simple/easy/elegant way of finding a search term *only* when it's a whole word?

The obvious thing to do is to add spaces either side of the term:

LIKE '% searchterm %'

but of course some words are going to be followed by punctuation, some preceded by quotes, and of course there's always the first word in the field that doesn't have a preceding character at all.

Anyone ever done this?

And for an extra point....

Searching the full text of every story like this seems to work well enough at the moment when there's a small number of users and a small number of stories. However, I can see it getting very inefficient and slow with a large number of users and/or stories. Any pointers on the best way to index the stories allowing for a more efficient search, or has anyone successfully used this brute force method on a large scale?

Reply With Quote
  #2  
Old June 14th, 2000, 07:49 AM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I would suggest familiarizing yourself with and using MySQL's regexp()function to further refine your select criteria.

Example - to find all occurrences of "searchword" in your stories table, and taking into account that "searchword" may be preceded by a space or perhaps quotes AND followed by possibly either another space, quote or punctuation, something like this might work....

> SELECT *
> FROM stories
> WHERE text
> REGEXP '[ "]{1,}searchword[.!?"]?';

There's so many things you can do with regular expressions, it's impossible to do them justice in this simple example. I think DevShed or PHPBuilder has some good regex tutorials.

Kyuzo

Reply With Quote
  #3  
Old June 14th, 2000, 08:18 AM
Adrian2 Adrian2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: London, England
Posts: 251 Adrian2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Thanks for pointing that out.

I'm familiar with regexs from Perl so I'm sure I can work out a good solution from here.

:-)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Full text search using LIKE


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway