Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of LINQ To Lucene

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the example analysis of LINQ To Lucene, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Lucene is a well-known open source project in JAVA, and there is also a .NET portable version of lucene.net, but it is still an incubator project on apache's official website, and it seems not to have been updated in 2007. Now LINQ To Lucene is launched on codeplex, which is really good news.

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 adopts attribute method, which is very simple and convenient.

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 = "Financial crisis that no one can escape", Author = "xxx", Publisher = "Oriental Press", PubTime = "December 2008"}) BookIndex.Add (new Book () {Title = "allow me to see it for you"), Author = "Xin Yiwu", Publisher = "Henan Literature and Art Publishing House", PubTime = "December 2008"}) BookIndex.Add (new Book () {Title = "TT struggle History of Big Cats", Author = "Ashi", Publisher = "International Cultural Publishing Company", PubTime = "December 2008"}) BookIndex.Add (new Book () {Title = "blooming flowers on the sea like a dream", Author = "bandit thinking", Publisher = "New World Press", PubTime = "December 2008"}); 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 () }

However, there is a bug, if written as from Book book in bookIndex, it will report an exception.

The above is all the content of this article "sample Analysis of LINQ To Lucene". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report