用Lucene.net对数据库建立索引及搜索
最近我一直在研究
Lucene.net ,
发现
Lucene.net
对数据库方面建索引的文章在网上很少见
,
其实它是可以对数据库进行索引的
,
我闲着没事
,
写了个测试程序
,
竟然成功了
,
可以实现对数据另类查询的一种方式
(
通过建索引查询
),
发表出来
,
和大家共享
.
其实
Lucene.net
对数据库建索引很简单
,
只要把数据表里面的记录读出来
,
然后对每个字段索引就行了
.
本文中数据库的内容是某个博客表-
userblog
表。
1. 表结构 :
字段名称 字段类型 字段含义
id Varchar(11) 编号
title Varchar(50) 标题
content Text 内容
2. 程序流程
1) 打开数据库 ;
2) 建立索引 ;
3) 根据索引进行全文搜索 .
4. 附源码 :
aspx 文件 :
如转载请注明出处 , 谢谢 !!
wangkun by 2007-5-1
1. 表结构 :
字段名称 字段类型 字段含义
id Varchar(11) 编号
title Varchar(50) 标题
content Text 内容
2. 程序流程
1) 打开数据库 ;
2) 建立索引 ;
3) 根据索引进行全文搜索 .
4. 附源码 :
aspx 文件 :
如转载请注明出处 , 谢谢 !!
wangkun by 2007-5-1
<%
@ Page language
=
"
c#
"
Codebehind
=
"
WebForm1.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
WebApplication4.WebForm1
"
%>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > 使用Lucene.net建立简单的数据库搜索程序 </ title >
< meta content = " Microsoft Visual Studio .NET 7.1 " name = " GENERATOR " >
< meta content = " C# " name = " CODE_LANGUAGE " >
< meta content = " JavaScript " name = " vs_defaultClientScript " >
< meta content = " http://schemas.microsoft.com/intellisense/ie5 " name = " vs_targetSchema " >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< table width = " 100% " border = " 0 " >
< tr >
< td >& nbsp;
< asp:textbox id = " tj " runat = " server " ></ asp:textbox >< asp:button id = " Search " runat = " server " Text = " 搜索 " ></ asp:button ></ td >
</ tr >
</ table >
< table width = " 100% " border = "
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > 使用Lucene.net建立简单的数据库搜索程序 </ title >
< meta content = " Microsoft Visual Studio .NET 7.1 " name = " GENERATOR " >
< meta content = " C# " name = " CODE_LANGUAGE " >
< meta content = " JavaScript " name = " vs_defaultClientScript " >
< meta content = " http://schemas.microsoft.com/intellisense/ie5 " name = " vs_targetSchema " >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< table width = " 100% " border = " 0 " >
< tr >
< td >& nbsp;
< asp:textbox id = " tj " runat = " server " ></ asp:textbox >< asp:button id = " Search " runat = " server " Text = " 搜索 " ></ asp:button ></ td >
</ tr >
</ table >
< table width = " 100% " border = "