日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

Lucene.Net学习

發(fā)布時間:2024/8/5 asp.net 286 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Lucene.Net学习 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

????????? 很早就知道Lucene.Net但一直都沒時間認真實踐一下.最近項目需要.所以考慮學(xué)習(xí)一下Lucene.Net引擎.終于做出了第一個Demo感覺挺實用的.還不錯.代碼貼上.各位博友可參考學(xué)習(xí)一下.


??????? protected void btnAddIndex_Click(object sender, EventArgs e)
??????? {
??????????? writer = new IndexWriter(Server.MapPath("index"), new Lucene.Net.Analysis.SimpleAnalyzer(), false);
??????????? IndexDirectory(writer, new FileInfo(Server.MapPath("doc")));
??????????? writer.Close();
??????? }
??????? public void IndexDirectory(IndexWriter writer, FileInfo file)
??????? {
??????????? if (System.IO.Directory.Exists(file.FullName))
??????????? {
??????????????? String[] files = System.IO.Directory.GetFileSystemEntries(file.FullName);
??????????????? if (files != null)
??????????????? {
??????????????????? for (int i = 0; i < files.Length; i++)
??????????????????? {
??????????????????????? IndexDirectory(writer, new FileInfo(files[i]));?
??????????????????? }
??????????????? }
??????????? }
??????????? else if (file.Extension == ".txt" || file.Extension == ".htm" || file.Extension == ".html")
??????????? {
??????????????? IndexFile(file, writer);
??????????? }
??????? }

??????? private void IndexFile(FileInfo file, IndexWriter writer)
??????? {
??????????? try
??????????? {
??????????????? Document doc = new Document();
??????????????? txtListIndex.Text = txtListIndex.Text + "\n文件路徑:" + file.FullName;
??????????????? doc.Add(Field.Keyword("filename", Path.GetFileName(file.FullName).Replace(file.Extension,"")));
??????????????? //doc.Add(Field.Text("contents", new StreamReader(file.FullName, System.Text.Encoding.Default)));
??????????????? doc.Add(Field.Text("contents", file.FullName));
??????????????? writer.AddDocument(doc);
??????????? }
??????????? catch (FileNotFoundException fnfe)
??????????? {
??????????????? Response.Write(fnfe.Message);
??????????? }
??????? }

??????? protected void Button1_Click(object sender, EventArgs e)
??????? {
??????????? IndexSearcher searcher = new IndexSearcher(Server.MapPath("index"));

??????????? Query query = QueryParser.Parse("Linux", "filename", new Lucene.Net.Analysis.WhitespaceAnalyzer());

??????????? Hits hits = searcher.Search(query);

??????????? if (hits.Length() > 0)
??????????? {
??????????????? for (int num = 0; num <= hits.Length() - 1; num++)
??????????????? {
??????????????????? Document docNew = hits.Doc(num);
??????????????????? txtListIndex.Text = txtListIndex.Text + "\n" + docNew.Get("contents");
??????????????? }
??????????? }
??????? }

轉(zhuǎn)載于:https://www.cnblogs.com/witer666/archive/2008/04/26/1172597.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Lucene.Net学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。