1: <%@ Page Language="C#" %>
2:
3: <%@ Import Namespace="Lucene.Net.Index" %>
4: <%@ Import Namespace="Lucene.Net.Analysis.Standard" %>
5: <%@ Import Namespace="Lucene.Net.Documents" %>
6: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7:
8: <script runat="server"> 1:
2:
3: protected void Page_Load(object sender, EventArgs e)
4: {
5: //索引位置
6: string sIndexLocation = MapPath("~/searchlucene/");
7: bool created;
8: //检测索引是否存在
9: IsIndexExists(out created, sIndexLocation);
10:
11: }
12: private void IsIndexExists(out bool created, string sIndexPath)
13: {
14: created = false;
15: if (!IndexReader.IndexExists(sIndexPath))
16: {
17: IndexWriter writer = new IndexWriter(sIndexPath, new StandardAnalyzer(), true);
18: created = true;
19: writer.Close();
20: }
21: }
22: //创建索引
23: protected void btnCreateIndex_Click(object sender, EventArgs e)
24: {
25: IndexWriter writer = new IndexWriter(MapPath("~/searchlucene/"), new StandardAnalyzer(), false);
26:
27: IndexDocument(writer, "中国", "China", "北京");
28: IndexDocument(writer, "美国", "USA", "密歇根");
29: IndexDocument(writer, "日本", "Jap", "小日本");
30: IndexDocument(writer, "中国", "China", "人均");
31: IndexDocument(writer, "2010", "情人节", "万维网");
32:
33: writer.Optimize();
34: writer.Close();
35:
36: }
37: //添加文件到索引
38: private void IndexDocument(IndexWriter writer, string sHeader, string sType, string sContent)
39: {
40: Document doc = new Document();
41:
42: doc.Add(new Field("header", sHeader, Field.Store.YES, Field.Index.TOKENIZED));
43: doc.Add(new Field("type", sType, Field.Store.YES, Field.Index.UN_TOKENIZED));
44: doc.Add(new Field("content", sContent, Field.Store.YES, Field.Index.TOKENIZED));
45:
46: writer.AddDocument(doc);
47:
48: }
49: //搜索
50: protected void btnSearch_Click(object sender, EventArgs e)
51: {
52: ListBox1.Items.Clear();
53:
54: var searcher = new Lucene.Net.Search.IndexSearcher(MapPath("~/searchlucene/"));
55: var oParser = new Lucene.Net.QueryParsers.QueryParser("content", new StandardAnalyzer());
56: string sHeader = " OR (header:" + TextBox1.Text + ")";
57: string sSearchQuery = "(" + TextBox1.Text + sHeader + ")";
58:
59: //解析搜索关键字
60: var oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
61: for (int i = 0; i < oHitColl.Length(); i++)
62: {
63: Document oDoc = oHitColl.Doc(i);
64: ListBox1.Items.Add(new ListItem(oDoc.Get("header") + oDoc.Get("type") + oDoc.Get("content")));
65: }
66:
67: searcher.Close();
68: }
script>
9:
10: <html xmlns="http://www.w3.org/1999/xhtml">
11: <head id="Head1" runat="server">
12: <title>Lucene例子title>
13: head>
14: <body>
15: <form id="form1" runat="server">
16: <div>
17: div>
18: 1-
19: <asp:Button ID="btnCreateIndex" runat="server" OnClick="btnCreateIndex_Click" Text="index create" />
20: <br />
21: <br />
22: 2- <asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
23: <asp:Button ID="btnSearch" runat="server" onclick="btnSearch_Click" Text="Search" />
24: <p>
25: p>
26: <p>
27: p>
28: <asp:ListBox ID="ListBox1" runat="server" Height="322px" Width="712px">asp:ListBox>
29: form>
30: body>
31: html>
相关推荐
在asp.net mvc里使用LucenceNet,有索引和搜索的例子,直接下载就可以使用!
【ASP.NET编程知识】基于ASP.NET的lucene.net全文搜索实现步骤.docx
lucene.net2.3.1开源项目 lucene是一个开源的全文检索项目,原本是java版的,后来就有了.net版,我上传的这个是.net的2.3.1版本,帮助大家解决全文检索引擎。
Lucene.Net.rar 2.0 ver asp.net 组件 功能强大放到 Bin 下面
说明:使用Lucene.NET技术实现搜索引擎范例 使用到的DLL插件包括: DictSeg.dll - 1.0.1.0 FredCK.FCKeditorV2.dll - 2.6.3.22451 FreeTextBox.dll - 3.3.1.12354 FTAlgorithm.dll - 1.0.1.0 Lucene.Net.dll - 1.9....
这里是计算机专业ASP.NET-毕业设计100套之一的ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文),希望能对大家有所帮助哦!
资源名字:基于C#+asp.net+sqlserver的搜索引擎设计与实现(源码+文档)_.net_ajax_lucene_搜索引擎.zip 资源内容:项目全套源码+完整文档 源码说明: 全部项目源码都是经过测试校正后百分百成功运行。 适合场景:...
asp代码ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文)本资源系百度网盘分享地址
ASP源码ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文)本资源系百度网盘分享地址
基于ASP.net+Ajax+Lucene的构建搜索引擎源码.zip
基于ASP.Net和Lucene.Net开发的站内搜索引擎Demo源码+项目说明+sln解决方案.zip 1)EDC.SearchEngine.Dao 顾名思义,数据访问层,与数据库进行交互,各种SQL! (2)EDC.SearchEngine.Service 业务逻辑层,对...
毕业设计完整版ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文).zip
lucene.net2.3.1开源项目 lucene是一个开源的全文检索项目,原本是java版的,后来就有了.net版,我上传的这个是.net的2.3.1版本。解决全文检索引擎。此为一部分,二部分打开地址...
ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+参考文献)
ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文).zip
ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现(源代码+论文).rar
ASP.NET毕业设计
ASP.NET基于Ajax+Lucene构建搜索引擎的设计和实现_project