目前行业网站的全文检索的方式主要有两种
方式一:通过数据库自带的全文索引
方式二:通过程序来自建全文索引系统
以sql server 2005为例
2005本身就自带全文索引功能,你可以先对数据库表
建立索引,具体如何建索引网上搜索一下,建立完索引之后,你就可以用sql来实现检索功能,例如:select * from ytbxw where
contaiins(字段,' 中国');多个查询值之间可以用and 或
or来实现,在单表以及单表视图上建全文索引对2005来说根本不是问题,但在多表视图建全文索引2005目前还无法实现这个功能,拿
www.ytbxw.com为例,其每个栏目的信息都是分开存放的,所以在检索上就无法用该方法来解决这个问题.
下面重点说一下如何用程序来实现检索功能
如果你想自己开发一个全文检索系统,我想这是相当复杂事情,要想实现也不是那么容易的事情,所以在这里我推荐一套开源程序,那就是dotlucene,我想大家可能都听过这个东东吧,那我就讲讲如何来实现多表情况下的全文检索.
1、新建winform项目,把lucene.net.dll添加到该项目中来
2、创建一个类,类名可以自己取
public class indexer
{
private indexwriter writer;
//在指定路径下创建索引文件
public indexer(string directory)
{
writer = new indexwriter(directory, new standardanalyzer(), true);
writer.setusecompoundfile(true);
}
//将信息添加到索引文件中
/*
field.text:为索引+读取
field.unindexed:不需要做索引
*/
public void addhtmldocument(string path,string title,string content)
{
document doc = new document();
doc.add(field.text("text", content));
doc.add(field.unindexed("path", path));
doc.add(field.text("title", title));
writer.adddocument(doc);
}
//解析html,过滤html代码
private string parsehtml(string html)
{
string temp = regex.replace(html, "<[^>]*>", "");
return temp.replace(" ", " ");
}
//从页面中获取文章标题
private string gettitle(string html)
{
match m = regex.match(html, "