Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of LINQ To Lucene

Shulou Source: shulou.com Published: 2022-06-02 09:02:11 11月17日 Update

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!

Tags: Publishing house article example analysis content Xinyi youth project thinking publishing famous not so much spokesperson work company crisis international most struggle history good news Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL Docker Shulou Technology NVidia