I have a table in SQL Server with structure:
Students
(
StudentId bigint,
FullName nvarchar(100),
DegreeId smallint,
Articel nvarchar(max)
)
i have created a full text index and enabled it for "students" table.
in my asp.net page ,users type words and i call a stored proc filter students using these words.
Create Procedure GetStudents(@Article nvarchar(200)=typed words)
AS
BEGIN
SET NOCOUNT开发者_JAVA技巧 ON
SELECT StudentId,FullName,DegreeId,Article
FROM Students
WHERE WHERE FREETEXT(Article,'''+ @Article+''')
END
The search works fine ,now i need to highlight(yellow background)the "articles" of returned stuents in my asp.net page(by jquery,or asp.net).
Any suggestions.
Thanks StackOverFlow
See here Highlight a word with jQuery
I think you're going to have a hard time getting a perfect highlighting system since SQL Server will match word variations in a FREETEXT
query. If you wanted to be nearly perfect, you could do your own (or use someone's) stemming algorithm to generate word variations.
If you wanted to do a best-efforts, you could embed the query (in a hidden input field or as a hash on the querystring), then do a javascript search-and-replace like this:
$(document).ready(function() {
// Set up words, either as a list you loop through or a JSON collection
$("#resultsContainer").innerHTML.replace(word, "<span class='highlight'>" + word + "</span>");
});
You could probably just as easily do this server-side and not have to worry about jQuery picking up elements of your page that might match the query words. In that case, you would simply do a search-and-replace similar to the javascript, only on your server code (VB or C#).
Try this this might help you
highlight words
精彩评论