Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Google like searching
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Google like searching
Divers
Thread ID:
00680729
Message ID:
00680729
Vues:
49
I have a full text index set up on a database and everything works fine. What I'm wondering is, how can I implement a search similar to the google search, where the results contain a small clip of the page where your seach term was found. I have the rank and everything, I'm just having problems with grabbing the text out of the field that matches the search. This is what I have so far:
declare @searchTerm varchar(50)
set @searchTerm = 'tittie tassels'

select k.rank, s.storyid, s.issueID, s.title, substring(storyText, charindex(@searchterm, storyText)-15, 100) as storyText
   FROM story AS s INNER JOIN freetexttable(story, storytext, @searchTerm) AS k
   ON s.storyID=k.[KEY]
   order by k.rank desc
Now this query works fine. It grabs the first 100 characters from the story where the @searchTerm is found. The problem I'm haveing is if someone enters 'tittie and tassels' or 'tittie or tassels' for their searchTerm. The full text search finds the right articals but the charindex can't find that string in the field so only the first 100 chars of the field get returnd, (because charindex returns 0 if it can't find what its looking for). I have also tried to use patindex, but im not exactly sure how that works. It seems to return the same thing as charindex but I have to wrap the search term with '%' signs.

TIA

Eric
Répondre
Fil
Voir

Click here to load this message in the networking platform