How do you run Lucene on .net?(你如何在 .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 示例).只需将 System.Out
替换为 Console.Writeln
:).
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你如何在 .net 上运行 Lucene?


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01