你如何在.net上运行Lucene? [英] How do you run Lucene on .net?

查看:108
本文介绍了你如何在.net上运行Lucene?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Lucene是一个出色的搜索引擎,但.NET版本是官方Java版本的背后(最新的稳定.NET版本是2.0,但最新的Java Lucene版本是2.4,它有更多功能)。

Lucene is an excellent search engine, but the .NET version is behind the official Java release (latest stable .NET release is 2.0, but the latest Java Lucene version is 2.4, which has more features).

你怎么解决这个问题?

推荐答案

我找到的一种方式,这很惊讶可以工作:从Java .jar文件创建一个.NET DLL!使用 IKVM ,您可以下载Lucene ,获取.jar文件,然后运行:

One way I found, which was surprised could work: Create a .NET DLL from a Java .jar file! Using IKVM you can download Lucene, get the .jar file, and run:

ikvmc -target:library <path-to-lucene.jar>

生成这样的.NET dll:lucene-core-2.4.0.dll

which generates a .NET dll like this: lucene-core-2.4.0.dll

然后你可以从项目中引用这个DLL,你就可以开始了!您需要一些Java类型,因此也请参考IKVM.OpenJDK.ClassLibrary.dll。您的代码可能看起来像这样:

You can then just reference this DLL from your project and you're good to go! There are some java types you will need, so also reference IKVM.OpenJDK.ClassLibrary.dll. Your code might look a bit like this:

QueryParser parser = new QueryParser("field1", analyzer);
java.util.Map boosts = new java.util.HashMap();
boosts.put("field1", new java.lang.Float(1.0));
boosts.put("field2", new java.lang.Float(10.0));

MultiFieldQueryParser multiParser = new MultiFieldQueryParser
                      (new string[] { "field1", "field2" }, analyzer, boosts);
multiParser.setDefaultOperator(QueryParser.Operator.OR);

Query query = multiParser.parse("ABC");
Hits hits = isearcher.search(query);

我从来不知道你可以如此轻松地实现Java到.NET的互操作性。最好的部分是C#和Java几乎兼容源代码(关注Lucene示例)。只需用 Console.Writeln 替换 System.Out :)。

I never knew you could have Java to .NET interoperability so easily. The best part is that C# and Java is "almost" source code compatible (where Lucene examples are concerned). Just replace System.Out with Console.Writeln :).

=======

更新:在构建像Lucene荧光笔这样的库时,请确保引用核心组件(否则你会得到关于缺课)。所以荧光笔是这样构建的:

Update: When building libraries like the Lucene highlighter, make sure you reference the core assembly (else you'll get warnings about missing classes). So the highlighter is built like this:

ikvmc -target:library lucene-highlighter-2.4.0.jar -r:lucene-core-2.4.0.dll

这篇关于你如何在.net上运行Lucene?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆