For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2004 > MySQL - counting number of instances of a word in a field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author MySQL - counting number of instances of a word in a field
Gavin Amm

2004-04-28, 2:31 am

Hi guys,

I'm trying to find a MySQL function(s) that will allow me to count the
number of words in a field.

For eg:

[table: pages]
id - title - keywords - body
1 - Home - home, page - This is my home page. <p> Enjoy your stay.
2 - Feedback - feedback, form, contact - Please enter any feedback or
comments in the form below.<br>Your feedback will be used to improve our
service.

How do I, for example, count the number of instances of a word such as
"feedback" in say the BODY field?
I'm putting together a search engine & I'd like to 'rank' the results
based on the number of instances of each word found in a few fields.

In this example, if they search for the words "feedback" and "improve",
the count would result in the row id, word searched and the number of
instances of that word:
(formatting doesn't matter, it's just to give you an idea)
id 2: "feedback" count = 2
id 2: "improve" count = 1

I can play with the weightings later, just need to figure out the
counting...

Thanks guys,
Gav

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com