这里介绍LINQ To Lucene,lucene是在JAVA中比较有名的开源项目,也有.NET移植版lucene.net,不过在apache的官方网站上还是一个孵化器项目,而且好像2007年就不更新了,现在codeplex上推出了LINQ To Lucene。
本文向咱们介绍LINQ To Lucene,或许好多人还不了解LINQ To Lucene,没有关系,看完本文你必定有不少收成,期望本文能教会你更多东西。
Lucene是在JAVA中比较有名的开源项目,也有.NET移植版lucene.net,不过在apache的官方网站上仍是一个孵化器项目,并且如同2007年就不更新了,现在codeplex上推出了LINQ To Lucene,真是一个好消息。
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingLucene.Linq.Mapping;
- usingLucene.Net.Analysis;
- usingLucene.Linq;
- namespaceLinqToLucene1
- {
- [Document]
- publicclassBook:IIndexable,IHit
- {
- [Field(FieldIndex.Tokenized,FieldStore.Yes,IsDefault=true)]
- publicstringTitle{get;set;}
- [Field(FieldIndex.Tokenized,FieldStore.Yes)]
- publicstringAuthor{get;set;}
- [Field(FieldIndex.Tokenized,FieldStore.Yes)]
- publicstringPubTime{get;set;}
- [Field(FieldIndex.Tokenized,FieldStore.Yes)]
- publicstringPublisher{get;set;}
- regionIHitMembers
- publicintDocumentId{get;set;}
- publicfloatRelevance{get;set;}
- endregion
- }
- }
LINQ To lucene选用attribute的办法,十分简略便利。
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingLucene.Net.Documents;
- usingLucene.Linq.Mapping;
- usingLucene.Linq;
- usingLucene.Net.Analysis;
- namespaceLinqToLucene1
- {
- publicclassProgram
- {
- staticvoidMain(string[]args)
- {
- IIndex<Book>bookIndex=newIndex<Book>();
- bookIndex.Add(newBook()
- {
- Title="谁都逃不掉的金融危机",
- Author="xxx",
- Publisher="东方出版社",
- PubTime="2008年12月"
- });
- bookIndex.Add(newBook()
- {
- Title="许我向你看(“暖伤芳华代言人”辛夷坞《致咱们终将逝去的芳华》***续作)",
- Author="辛夷坞",
- Publisher="河南文艺出版社",
- PubTime="2008年12月"
- });
- bookIndex.Add(newBook()
- {
- Title="大猫儿的TT奋斗史(都市小白领的爆雷囧事录)",
- Author="阿巳",
- Publisher="世界文明出版公司",
- PubTime="2008年12月"
- });
- bookIndex.Add(newBook()
- {
- Title="佳期如梦之海上繁花(匪我思存***著作上市)",
- Author="匪我思存",
- Publisher="新世界出版社",
- PubTime="2008年12月"
- });
- varresult=frombookinbookIndex
- wherebook.Author=="xxx"
- selectbook;
- foreach(Bookbookinresult)
- {
- System.Console.WriteLine(book.Title);
- }
- System.Console.ReadLine();
- }
- }
- }
不过有个bug,假如写成from Book book in bookIndex 的话,就会报反常。
【修改引荐】
- Linq成果集形状概述
- Linq存储进程回来详解
- Linq调用LoadProducts办法
- Linq运用数据表简略描绘
- Linq目标引证简略介绍
转载请说明出处
知优网 » LINQ To Lucene简略介绍
知优网 » LINQ To Lucene简略介绍