这里介绍LINQ To Lucene,lucene是在JAVA中比较有名的开源项目,也有.NET移植版lucene.net,不过在apache的官方网站上还是一个孵化器项目,而且好像2007年就不更新了,现在codeplex上推出了LINQ To Lucene。

本文向咱们介绍LINQ To Lucene,或许好多人还不了解LINQ To Lucene,没有关系,看完本文你必定有不少收成,期望本文能教会你更多东西。

LINQ To Lucene简略介绍  Lucene 第1张

Lucene是在JAVA中比较有名的开源项目,也有.NET移植版lucene.net,不过在apache的官方网站上仍是一个孵化器项目,并且如同2007年就不更新了,现在codeplex上推出了LINQ To Lucene,真是一个好消息。

  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.Linq;
  4. usingSystem.Text;
  5. usingLucene.Linq.Mapping;
  6. usingLucene.Net.Analysis;
  7. usingLucene.Linq;
  8. namespaceLinqToLucene1
  9. {
  10. [Document]
  11. publicclassBook:IIndexable,IHit
  12. {
  13. [Field(FieldIndex.Tokenized,FieldStore.Yes,IsDefault=true)]
  14. publicstringTitle{get;set;}
  15. [Field(FieldIndex.Tokenized,FieldStore.Yes)]
  16. publicstringAuthor{get;set;}
  17. [Field(FieldIndex.Tokenized,FieldStore.Yes)]
  18. publicstringPubTime{get;set;}
  19. [Field(FieldIndex.Tokenized,FieldStore.Yes)]
  20. publicstringPublisher{get;set;}
  21. regionIHitMembers
  22. publicintDocumentId{get;set;}
  23. publicfloatRelevance{get;set;}
  24. endregion
  25. }
  26. }

LINQ To lucene选用attribute的办法,十分简略便利。

  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.Linq;
  4. usingSystem.Text;
  5. usingLucene.Net.Documents;
  6. usingLucene.Linq.Mapping;
  7. usingLucene.Linq;
  8. usingLucene.Net.Analysis;
  9. namespaceLinqToLucene1
  10. {
  11. publicclassProgram
  12. {
  13. staticvoidMain(string[]args)
  14. {
  15. IIndex<Book>bookIndex=newIndex<Book>();
  16. bookIndex.Add(newBook()
  17. {
  18. Title="谁都逃不掉的金融危机",
  19. Author="xxx",
  20. Publisher="东方出版社",
  21. PubTime="2008年12月"
  22. });
  23. bookIndex.Add(newBook()
  24. {
  25. Title="许我向你看(“暖伤芳华代言人”辛夷坞《致咱们终将逝去的芳华》***续作)",
  26. Author="辛夷坞",
  27. Publisher="河南文艺出版社",
  28. PubTime="2008年12月"
  29. });
  30. bookIndex.Add(newBook()
  31. {
  32. Title="大猫儿的TT奋斗史(都市小白领的爆雷囧事录)",
  33. Author="阿巳",
  34. Publisher="世界文明出版公司",
  35. PubTime="2008年12月"
  36. });
  37. bookIndex.Add(newBook()
  38. {
  39. Title="佳期如梦之海上繁花(匪我思存***著作上市)",
  40. Author="匪我思存",
  41. Publisher="新世界出版社",
  42. PubTime="2008年12月"
  43. });
  44. varresult=frombookinbookIndex
  45. wherebook.Author=="xxx"
  46. selectbook;
  47. foreach(Bookbookinresult)
  48. {
  49. System.Console.WriteLine(book.Title);
  50. }
  51. System.Console.ReadLine();
  52. }
  53. }
  54. }

不过有个bug,假如写成from Book book in bookIndex 的话,就会报反常。

【修改引荐】

  1. Linq成果集形状概述
  2. Linq存储进程回来详解
  3. Linq调用LoadProducts办法
  4. Linq运用数据表简略描绘
  5. Linq目标引证简略介绍
转载请说明出处
知优网 » LINQ To Lucene简略介绍

发表评论

您需要后才能发表评论