新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
LINQToLucene簡單介紹
本文向大家介紹LINQ To Lucene,可能好多人還不了解LINQ To Lucene,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。

創(chuàng)新互聯(lián)建站是一家以網(wǎng)站建設(shè)公司、網(wǎng)頁設(shè)計、品牌設(shè)計、軟件運維、網(wǎng)站推廣、小程序App開發(fā)等移動開發(fā)為一體互聯(lián)網(wǎng)公司。已累計為軟裝設(shè)計等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務。
lucene是在JAVA中比較有名的開源項目,也有.NET移植版lucene.net,不過在apache的官方網(wǎng)站上還是一個孵化器項目,而且好像2007年就不更新了,現(xiàn)在codeplex上推出了LINQ To Lucene,真是一個好消息。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Lucene.Linq.Mapping;
- using Lucene.Net.Analysis;
- using Lucene.Linq;
- namespace LinqToLucene1
- {
- [Document]
- public class Book : IIndexable, IHit
- {
- [Field(FieldIndex.Tokenized,FieldStore.Yes, IsDefault = true)]
- public string Title { get; set; }
- [Field(FieldIndex.Tokenized, FieldStore.Yes)]
- public string Author { get; set; }
- [Field(FieldIndex.Tokenized, FieldStore.Yes)]
- public string PubTime { get; set; }
- [Field(FieldIndex.Tokenized, FieldStore.Yes)]
- public string Publisher { get; set; }
- region IHit Members
- public int DocumentId { get; set; }
- public float Relevance { get; set; }
- endregion
- }
- }
linq to lucene采用attribute的方式,非常簡單方便。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Lucene.Net.Documents;
- using Lucene.Linq.Mapping;
- using Lucene.Linq;
- using Lucene.Net.Analysis;
- namespace LinqToLucene1
- {
- public class Program
- {
- static void Main(string[] args)
- {
- IIndex
bookIndex = new Index (); - bookIndex.Add(new Book()
- {
- Title = "誰都逃不掉的金融危機",
- Author = "xxx",
- Publisher = "東方出版社",
- PubTime = "2008年12月"
- });
- bookIndex.Add(new Book()
- {
- Title = "許我向你看(“暖傷青春代言人” 辛夷塢《致我們終將逝去的青春》***續(xù)作)",
- Author = "辛夷塢",
- Publisher = "河南文藝出版社",
- PubTime = "2008年12月"
- });
- bookIndex.Add(new Book()
- {
- Title = "大貓兒的TT奮斗史(都市小白領(lǐng)的爆雷囧事錄)",
- Author = "阿巳",
- Publisher = "國際文化出版公司",
- PubTime = "2008年12月"
- });
- bookIndex.Add(new Book()
- {
- Title = "佳期如夢之海上繁花(匪我思存***作品上市)",
- Author = "匪我思存",
- Publisher = "新世界出版社",
- PubTime = "2008年12月"
- });
- var result = from book in bookIndex
- where book.Author == "xxx"
- select book;
- foreach (Book book in result)
- {
- System.Console.WriteLine(book.Title);
- }
- System.Console.ReadLine();
- }
- }
- }
不過有個bug,如果寫成from Book book in bookIndex 的話,就會報異常。
網(wǎng)站題目:LINQToLucene簡單介紹
網(wǎng)頁路徑:http://fisionsoft.com.cn/article/cdpihpj.html


咨詢
建站咨詢
