开发者

Displaying "Google like" search results

Working in ASP.NET (VB), I am trying to develop a simple search results page for my website.

The process is as follows:

  1. The site's user enters a search phrase;

  2. The search results page searches the site's database, returns the page title as a link, and a short snippet from each search "hit", with the search phrase highlighted.

I already have the search part done, and also the "highlighted" part done (using Regex). However, I want to be able to ret开发者_如何转开发urn a short snippet of text, which include the search phrase (a few words before the search phrase, a few after). Something like:

Page Title [as a link]

... yada yada yada search phrase yada yada yada....


Google displays a sentence in which keyword was found. Assuming you already found a keyword position in a text, I would do:

  1. Go backwards char by char from keyword position until you find . or ? or ! or beginning of a text.
  2. Return a substring of required length from that position.


(\b\S+\b(\s*)){3}search phrase((\s*)\b\S+\b){3}

This will select 3 words before "search phrase" and 3 words after.

If you have a sentence "search phrase lorum ipsum search phrase" it will probably only match the first search phrase

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜