How do you run Lucene on .net?

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).

How do you get around this?

Asked by: Dominik239 | Posted: 28-01-2022

Answer 1

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>

which generates a .NET dll like this: lucene-core-2.4.0.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);

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

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 :).


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

Answered by: John846 | Posted: 01-03-2022

Answer 2

Download the source and build it. I did this just last weekend and it was easy. No problem at all. The source is at version 2.3.1.

I'm subscribed to the mailing list and judging from it, Lucene.Net is being developed actively.

Answered by: Steven633 | Posted: 01-03-2022

Answer 3 is under development and now has three committers

Answered by: Haris418 | Posted: 01-03-2022

Answer 4

I converted the Lucene 2.4 from jar to dll through this way but now it gives me an error that 'Type or namespace Lucene could not be found'. I removed the old dll from the project and added reference for the new one. I really want to get rid of the old version as it took around 2 days and in the end during optimization it gave some error and now the index is not updateable :S. I read somewhere that Lucene 2.4 indexing speed is many times faster than the old versions, if I use 2.3.1 from SVN will that be faster too?

Answered by: Aida726 | Posted: 01-03-2022

Similar questions

java - Query in Lucene

The structure of the table "testtable" is id int primary key productid int attributeid int value varchar(250) where productid is the unique id of a product, attributeid is the unique id of attribute of a product e.g. size, quality,height, color and 'value' is the value for the attribute i have to filter a result. I achieve the re...

php - Does Zend Lucene need Java Lucene?

When implementing Zend Lucene, do we need to install Java on our server or not?

java - lucene set boost on fields at search time

Is it possible to adjust the boost of a field with the Query object before running the search? I know the proper way to do it is to change the fields boost during indexing, but it takes about 4 days to make an index and was just wondering if there's a quick hack i can do for now. also i have tried hardcoding in the boost to the search query, ie AND field(this that other)^7 and that works, and it would be t...

java - lucene larger than

Does anybody of you guys know how to search all the numbers larget than a specified one? for example: all the document number > 65 i tried like: documentNumber: [65 TO *] but i receive exception, as lucene expected to parse a number there not a *. Thanks in advance!

java - Using lucene in Tomcat

Background I am assuming the following code is completely thread safe: // Called from a servlet when a user action results in the index needing to be updated public static void rebuildIndex() { FSDirectory dir = new NIOFSDirectory(new File(Configuration.getAttachmentFolder()), null); IndexWriter w = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED); .... build index ... w.optimi...

java - Different lucene search results using different search space size

I have an application that uses lucene for searching. The search space are in the thousands. Searching against these thousands, I get only a few results, around 20 (which is ok and expected). However, when I reduce my search space to just those 20 entries (i.e. I indexed only those 20 entries and disregard everything that development would be easier), I get the same 20 results but in different order (and ...

java - How to read a Lucene index?

I'm working on a project for which I want to build a tag cloud by reading a Lucene index and pruning it down. I didn't set up the Lucene engine, it was someone else in the team, now I just want to read its index. Do you how to do that in Java?

lucene - Search for short words with SOLR

I am using SOLR along with NGramTokenizerFactory to help create search tokens for substrings of words NGramTokenizer is configured with a minimum word length of 3 This means that I can search for e.g. "unb" and then match the word "unbelievable". However I have a problem with short words like "I" and "in". These are not indexed by SOLR (I suspect it is because of NGramTokenizer) and therefore I cann...

java - Word importance in lucene index

hmmm, i need to get how important is the word in entire document collection that is indexed in the lucene index. I need to extract some "representable words", lets say concepts that are common and can be representable to whole collection. Or collection "keywords". I did the fulltext indexing and the only field i am using are text contents, because titles of the documents are mostly not re...

java - Lucene search - score higher if word or similar are in a Field

I need to know when a word or words are inside a field in my index, and have that document swith greater score. My problem is that if i search for "Sherton Hotel" I get this as greatest results Petit Hotel Crzy cow Simmonss And i would like this ones to have the greatest results Maui Sheraton Hotel near the moon A fantastic hotel that looks like ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)