View Full Version : select substring in search
bitbob
04-23-2007, 03:40 PM
I have a table with a text-field that i do fulltext searches on. If I get a hit when I search I would like to retrive a short excerpt from the text where my searchwords where found. Can this be done in the same query or do I have to retive the whole text and fix it with php?
Fumigator
04-23-2007, 05:18 PM
You can use MySQL's substring() (http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_substring) function within the query...
bitbob
04-24-2007, 07:53 AM
yes, i know... but I think you missunderstood. I want to be able to get n number of substrings with one or more of my searchwords in them.
What I do now is:
Get the text into php
tokenize my search string
wrap span-tags around all found searchwords in the text
starting from the beginning of the text; get a substring with the first found span tag in the middle of the substring.
countinue to get the substrings untill i get an excerpt that is 255 characters long
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.