views:

481

answers:

3

We have a project where we need to provide search over a collection of Word documents through a web-based interface. The client would like for the search terms to be highlighted when a user opens a document.

Is there a way to do this directly in Word when opening a document? The only alternative we can come up with is to convert the Word documents to HTML and display that.

Just for background, we're currently using Windows SharePoint Services for document searching.

+1  A: 

You could do that using Word's Highlight feature. However, to use the feature you will have to use Word automation on either server-side or client-side.

A script in VBA for highlighting a search term could look like this:

Sub Highlight(oDoc As Word.Document, term As String)

    With oDoc.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Highlight = True
        .Text = term
        .Replacement.Text = term
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With

End Sub

The script does a search-and-replace and applies highlighting to the found text. If you have any questions on how to automate Word best, e.g. in a server environment, don't hesitate to ask.

0xA3
A: 

There is a product from Kwizcom that satisfies this need - I haven't tried it, your mileage may vary! SharePoint Search String Highlighter - http://www.kwizcom.com/ProductPage.asp?ProductID=28

Also if converting the Word documents to PDF is acceptable (and assuming you have a PDF iFilter installed so that these can be indexed), then search term highlighting within the resulting document is available by appending parametes to the URL. The Adobe Viewer client can interpret these and basically does a client-side search of the document. See http://www.novolocus.com/2008/05/15/hit-highlighting-inside-adobe-pdfs-using-sharepoint-search/ for more details.

Hope this helps!

Harv
A: 

how could i do this in client site ....

Pradipta