其实 Lucene.net 对数据库建索引很简单,只要把数据表里面的记录读出来,然后对每个字段索引就行了.本文中数据库的内容是某个博客表-userblog表。

1.表结构:
字段名称         字段类型         字段含义
id                Varchar(11)          编号
title              Varchar(50)          标题
content         Text                    内容

2.程序流程
1)   打开数据库;
2)   建立索引;
3)    根据索引进行全文搜索.


4.附源码:
aspx文件:
<%@ 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 ,new ChineseAnalyzer());
                hits=mysea.Search(query);
            }
            catch(Exception e)
            {
               Response.Write(e);
            }
            return hits;
        }


        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
       
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {   
            this.Search.Click += new System.EventHandler(this.Search_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Search_Click(object sender, System.EventArgs e)

相关文章:

  • 2021-10-04
  • 2021-06-26
  • 2021-09-08
  • 2022-02-06
  • 2022-02-08
  • 2022-01-03
  • 2022-02-08
猜你喜欢
  • 2021-11-13
  • 2021-05-29
  • 2022-02-15
  • 2022-12-23
  • 2021-10-22
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案