Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 952101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:50:18+00:00 2026-05-15T23:50:18+00:00

We have a web application that uses SQL Server 2008 as the database. Our

  • 0

We have a web application that uses SQL Server 2008 as the database. Our users are able to do full-text searches on particular columns in the database. SQL Server’s full-text functionality does not seem to provide support for hit highlighting. Do we need to build this ourselves or is there perhaps some library or knowledge around on how to do this?

BTW the application is written in C# so a .Net solution would be ideal but not necessary as we could translate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:50:19+00:00Added an answer on May 15, 2026 at 11:50 pm

    Expanding on Ishmael’s idea, it’s not the final solution, but I think it’s a good way to start.

    Firstly we need to get the list of words that have been retrieved with the full-text engine:

    declare @SearchPattern nvarchar(1000) = 'FORMSOF (INFLECTIONAL, " ' + @SearchString + ' ")' 
    declare @SearchWords table (Word varchar(100), Expansion_type int)
    insert into @SearchWords
    select distinct display_term, expansion_type
    from sys.dm_fts_parser(@SearchPattern, 1033, 0, 0)
    where special_term = 'Exact Match'
    

    There is already quite a lot one can expand on, for example the search pattern is quite basic; also there are probably better ways to filter out the words you don’t need, but it least it gives you a list of stem words etc. that would be matched by full-text search.

    After you get the results you need, you can use RegEx to parse through the result set (or preferably only a subset to speed it up, although I haven’t yet figured out a good way to do so). For this I simply use two while loops and a bunch of temporary table and variables:

    declare @FinalResults table 
    while (select COUNT(*) from @PrelimResults) > 0
    begin
        select top 1 @CurrID = [UID], @Text = Text from @PrelimResults
        declare @TextLength int = LEN(@Text )
        declare @IndexOfDot int = CHARINDEX('.', REVERSE(@Text ), @TextLength - dbo.RegExIndexOf(@Text, '\b' + @FirstSearchWord + '\b') + 1)
        set @Text = SUBSTRING(@Text, case @IndexOfDot when 0 then 0 else @TextLength - @IndexOfDot + 3 end, 300)
    
        while (select COUNT(*) from @TempSearchWords) > 0
        begin
            select top 1 @CurrWord = Word from @TempSearchWords
            set @Text = dbo.RegExReplace(@Text, '\b' + @CurrWord + '\b',  '<b>' + SUBSTRING(@Text, dbo.RegExIndexOf(@Text, '\b' + @CurrWord + '\b'), LEN(@CurrWord) + 1) + '</b>')
            delete from @TempSearchWords where Word = @CurrWord
        end
    
        insert into @FinalResults
        select * from @PrelimResults where [UID] = @CurrID
        delete from @PrelimResults where [UID] = @CurrID
    end
    

    Several notes:
    1. Nested while loops probably aren’t the most efficient way of doing it, however nothing else comes to mind. If I were to use cursors, it would essentially be the same thing?
    2. @FirstSearchWord here to refers to the first instance in the text of one of the original search words, so essentially the text you are replacing is only going to be in the summary. Again, it’s quite a basic method, some sort of text cluster finding algorithm would probably be handy.
    3. To get RegEx in the first place, you need CLR user-defined functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Let me suggest you a slight simplification of your code:… May 16, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer Pretty lame: changing the environment variable ORACLE_SID to lowercase, fixed… May 16, 2026 at 1:58 pm
  • Editorial Team
    Editorial Team added an answer i have updated my answer! to avoid the "-1´s" =P… May 16, 2026 at 1:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

We have developed a .NET web application that uses SQL Server as a backend.
I have a web application set up on our intranet that uses windows authentication
I have a web application that uses two databases. DB1 Users perform their CRUD
I'm deploying a web application into a server (hosting company). The application uses Sql
I have a C# application that uses several web services which were added to
I have a web application that works fine in IIS 6.0. I have modified
I have an existing application that has some parts of formatted text-blocks (standard formats
Background I have a BLL DLL that uses NHibernate. I share the same BLL
I am writing a web application that will serve as a configuration for a
I have just received a requirement to implement spell checking on a web application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.