FlexSearch / FlexLucene

IKVM Build scripts
Apache License 2.0
16 stars 5 forks source link

GermanAnalyzer Exception #6

Closed kirtapatrik closed 8 years ago

kirtapatrik commented 8 years ago

G'Day

I get an error when I create a new instance of GermanAnalyzer.

var tmpAnalyzer = new GermanAnalyzer();

System.TypeInitializationException wurde nicht von Benutzercode behandelt. HResult=-2146233036 Message=Der Typeninitialisierer für "FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder" hat eine Ausnahme verursacht. Source=FlexLucene TypeName=FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder StackTrace: bei FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder.Access000() bei FlexLucene.Analysis.De.GermanAnalyzer..ctor() bei HWebbuilderSearch_Unittest.Wildcard_UnitTest._createAndFillIndex(TestContext inTestContext) in C:\Data\Projekte.TFS\FrameworkNewWinAG\Development\Tests\HWebbuilderSearch_Unittest\Wildcard_UnitTest.cs:Zeile 141. InnerException: HResult=-2146233088 Message (System.Exception)="" Message="" Source (System.Exception)=IKVM.OpenJDK.Core Source=IKVM.OpenJDK.Core StackTrace (System.Exception)= bei java.io.Reader..ctor(Object lock) bei java.io.InputStreamReader..ctor(InputStream in, CharsetDecoder dec) bei FlexLucene.Util.IOUtils.GetDecodingReader(InputStream is, Charset c) bei FlexLucene.Util.IOUtils.GetDecodingReader(Class c1, String str, Charset c2) bei FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder..cctor() StackTrace: bei java.io.Reader..ctor(Object lock) bei java.io.InputStreamReader..ctor(InputStream in, CharsetDecoder dec) bei FlexLucene.Util.IOUtils.GetDecodingReader(InputStream is, Charset c) bei FlexLucene.Util.IOUtils.GetDecodingReader(Class c1, String str, Charset c2) bei FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder..cctor() InnerException:

How can I fix that? I use the new 6.0 version.

Thx Patrik

vladnega commented 8 years ago

Hi Patrik,

The short explanation is that there is a classpath mismatch occurring when the GermanAnalyzer is being initialized. It's searching for the *german_stop.txt" resource in the wrong location.

This mismatch is occurring because when we are building the FlexLucene dll, we are renaming some namespaces to FlexLucene.*, CamelCasing some class names, etc, thus the classpaths are being changed. Unfortunately, it seems we aren't taking care of the resource paths.

Internally, the GermanAnalyzer constructor is calling the SnowballFilter to get the *german_stop.txt` resource. The code would be equivalent to something like this:

WordlistLoader.GetSnowballWordSet(IOUtils.GetDecodingReader(ClassLiteral<SnowballFilter>.Value, "german_stop.txt", StandardCharsets.UTF_8));

This code will fail because it can't find the "german_stop" resource. It's trying to find the resource at the /FlexLucene/Analysis/Snowball/german_stop.txt path.

Here is some code that will hopefully explain it better:

var cls = ClassLiteral<SnowballFilter>.Value;

var r1 = cls.getResource("german_stop.txt"); // returns null because it's using the /FlexLucene/Analysis/Snowball classpath
var r2 = cls.getResource("/org/apache/lucene/analysis/snowball/german_stop.txt"); // this works

// this doesn't work. It's trying to find the resource at the `/FlexLucene/Analysis/Snowball/german_stop` path
WordlistLoader.GetSnowballWordSet(IOUtils.GetDecodingReader(ClassLiteral<SnowballFilter>.Value, "german_stop.txt", StandardCharsets.UTF_8));

// this works
WordlistLoader.GetSnowballWordSet(IOUtils.GetDecodingReader(ClassLiteral<SnowballFilter>.Value, "/org/apache/lucene/analysis/snowball/german_stop.txt", StandardCharsets.UTF_8));

Hope this helps. I'll try finding a way to correct the resource paths.

vladnega commented 8 years ago

@kirtapatrik , could you please try using the FlexLucene.dll in the Artifacts folder?

Let me know if you face any other issues with it and if not, we'll push it to Nuget as well.

kirtapatrik commented 8 years ago

Hi, i used the new FlexLucene.dll from the Artifacts folder. Version 6.0.0?

But I get the same Error: FlexLucene.Analysis.De.GermanAnalyzerDefaultSetHolder"

My testmethode:

            var tmpClassLiteral = ClassLiteral<SnowballFilter>.Value;
            var tmpR1 = tmpClassLiteral.getResource("german_stop.txt");
            var tmpR2 = tmpClassLiteral.getResource("/FlexLucene/analysis/snowball/german_stop.txt");
            var tmpR3 = tmpClassLiteral.getResource("/org/apache/lucene/analysis/snowball/german_stop.txt");

            Assert.IsNotNull(tmpR1); // FALSE
            Assert.IsNotNull(tmpR2); // FALSE
            Assert.IsNotNull(tmpR3); // TRUE

I think that the resource should be at the new path /FlexLucene/snowball?

Thx, for your fast support Patrik

vladnega commented 8 years ago

Yes, that's the .dll I suggested using.

The fix I did is exactly as you've suggested - adding a new path for /FlexLucene/analysis/snowball.

I've just tried creating a new project and replacing the FlexLucene.dll with the new version and it worked. You don't have to use ClassLiteral or getResource, it's enough just to call:

var tmp = new GermanAnalyzer();

Are you sure you are replacing the FlexLucene.dll in the /bin/Debug of your project with the one in the repo's Artifacts folder? Be aware that rebuilding the project will overwrite the FlexLucene.dll with the version in the project's packages folder.

If you are sure you're using the correct dll, then could you please open the FlexLucene.dll with dotPeek, go to its Resources section and paste the FlexLucene.jar file in here so I can inspect it?

kirtapatrik commented 8 years ago

You are right. There was a problem with the dll replacemet. The German Analyzer is now working.

The Path is: {jar:file:/C:/.virtual-ikvm-home/assembly/FlexLucene/resources/FlexLucene.jar!/FlexLucene/Analysis/Snowball/german_stop.txt}