How could I generate a contextual text extract from text returned from a SQL Server Full-Text Index?

耗尽温柔 提交于 2019-12-21 17:50:07

问题


I'm experimenting with an idea using SQL Server's Full Text Indexing. It seems perfect for the task, but what my client wants is a very Google-like results summary, where the results display an extract of the text around their search term.

If I search for "house"...

My House Is a Very, Very, Very Fine House
...thanks for coming to visit our house today...don't you like this house...hey, why are you setting fire to my house?...

This isn't too hard if their search term is an exact match for what the search hit on. You could simply do some tedious parsing of the text to generate the extract.

But what happens with inflectionals and stemming? If I search for "walk," the query may hit on "walking," "walked," etc. I would need to know exactly what word inside the search result it hit on, so I would know from where to base my extraction.

This area seems ripe for some commercial product add-on, or perhaps there's an elegant way to do it that I'm not considering?

(And, yes, we are aware of the the GSA and the Google Mini. There are some subtle reasons why they might not work in this case, so we're trying SQL FTI first.)


回答1:


If using SQL 2008 , I guess you could use the sys.dm_fts_parser - send in your final searching string (with any FORMSOF etc added) . This will return a list of words you can then use to highlight text on your page (using a jquery plugin to do the highlighting, any words it doesn't find just wont be highlighted)



来源:https://stackoverflow.com/questions/588528/how-could-i-generate-a-contextual-text-extract-from-text-returned-from-a-sql-ser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!