lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shad Storhaug (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LUCENENET-602) Error using Lucene.Net.Facet 4.8.0-beta00005 with Xamarin.iOS
Date Thu, 11 Jul 2019 16:38:00 GMT

    [ https://issues.apache.org/jira/browse/LUCENENET-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16883155#comment-16883155
] 

Shad Storhaug commented on LUCENENET-602:
-----------------------------------------

Enrico,

Sorry for the long delay.

The issue here seems to be that we currently use Reflection to load the {{Codec}}, {{DocValuesFormat}},
and {{PostingsFormat}} types and apparently not all platforms have complete implementations
of Reflection and silently fail.

However, as the error message says, there is an API that can be used to load the types manually
by subclassing factories for each of those 3 types.
 # {{DefaultCodecFactory}}
 # {{DefaultDocValuesFormatFactory}}
 # {{DefaultPostingsFormatFactory}}

Here is an example of subclassing these types to provide codecs. It is meant to be able to
add your own codecs, but you can also use it to workaround the issue of the codecs not loading
until the next beta where this will be fixed.
{code}
private class MyCodecFactory : DefaultCodecFactory
{
    // These are all of the codec types that are in
    // Lucene.Net.dll. You only need the first one unless
    // you need legacy support for Lucene.Net 3.x or
    // want to build your own codec.
    private static Type[] localCodecTypes = new Type[] {
        typeof(Lucene46.Lucene46Codec),
#pragma warning disable 612, 618
        typeof(Lucene3x.Lucene3xCodec), // Optimize 3.x codec over < 4.6 codecs
        typeof(Lucene45.Lucene45Codec),
        typeof(Lucene42.Lucene42Codec),
        typeof(Lucene41.Lucene41Codec),
        typeof(Lucene40.Lucene40Codec),
#pragma warning restore 612, 618
    };

    protected override void Initialize()
    {
        foreach (var type in localCodecTypes)
        {
            base.PutCodecType(type);
        }
    }
}

private class MyDocValuesFormatFactory : DefaultDocValuesFormatFactory
{
    // These are all of the doc values types that are in
    // Lucene.Net.dll. You only need the first one unless
    // you need legacy support for Lucene.Net 3.x or
    // want to build your own doc values (a type used by codecs).
    private static Type[] localDocValuesFormatTypes = new Type[] {
        typeof(Lucene45.Lucene45DocValuesFormat),
#pragma warning disable 612, 618
        typeof(Lucene42.Lucene42DocValuesFormat),
        typeof(Lucene40.Lucene40DocValuesFormat),
#pragma warning restore 612, 618
    };

    protected override void Initialize()
    {
        foreach (var type in localDocValuesFormatTypes)
        {
            base.PutDocValuesFormatType(type);
        }
    }
}

private class MyPostingsFormatFactory : DefaultPostingsFormatFactory
{
    // These are all of the postings format types that are in
    // Lucene.Net.dll. You only need the first one unless
    // you need legacy support for Lucene.Net 3.x or
    // want to build your own postings format (a type used by codecs).
    private static Type[] localPostingsFormatTypes = new Type[]
    {
        typeof(Lucene41.Lucene41PostingsFormat),
#pragma warning disable 612, 618
        typeof(Lucene40.Lucene40PostingsFormat),
#pragma warning restore 612, 618
    };

    protected override void Initialize()
    {
        foreach (var type in localPostingsFormatTypes)
        {
            base.PutPostingsFormatType(type);
        }
    }
}


// At application startup (in your application's composition root),
// set your factories. These are static and will supply default codecs
// to your application.
Codec.SetCodecFactory(new MyCodecFactory());
DocValuesFormat.SetDocValuesFormatFactory(new MyDocValuesFormatFactory());
PostingsFormat.SetPostingsFormatFactory(new MyPostingsFormatFactory());

{code}
The pragma statements aren't strictly necessary, they are just to suppress the obsolete warnings
for those types.

There are many more examples on setting up these factories in the tests [CodecFactory|https://github.com/apache/lucenenet/blob/7c96de946e403176d02fa5d94e534f10bf34f64b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultCodecFactory.cs],
[DocValuesFormatFactory|https://github.com/apache/lucenenet/blob/7c96de946e403176d02fa5d94e534f10bf34f64b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultDocValuesFormatFactory.cs],
[PostingsFormatFactory|https://github.com/apache/lucenenet/blob/7c96de946e403176d02fa5d94e534f10bf34f64b/src/Lucene.Net.Tests/Support/Codecs/TestDefaultPostingsFormatFactory.cs].

> Error using Lucene.Net.Facet 4.8.0-beta00005  with Xamarin.iOS
> --------------------------------------------------------------
>
>                 Key: LUCENENET-602
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-602
>             Project: Lucene.Net
>          Issue Type: Bug
>          Components: Lucene.Net.Facet
>    Affects Versions: Lucene.Net 4.8.0
>         Environment: Xamarin Forms 3.0.0.561731
> Ios 10.3.3 and Higher
> Lucene.Net.Facet 4.8.0-beta00005
>            Reporter: Enrico Caltran
>            Priority: Blocker
>              Labels: AOT, Xamarin.iOS, lucene.net.facet
>             Fix For: Lucene.Net 4.8.0
>
>         Attachments: AppTestLucene.zip
>
>   Original Estimate: 120h
>  Remaining Estimate: 120h
>
> I'm using Lucene.Net.Facet 4.8.0-beta00005 in a big Xamarin project.
> +With Xamarin.Android and Xamarin.UWP it's all right.+
> *+But With Xamarin.iOS on device (Ipad)+*, i'm receiving this error:
>  _Attempting to JIT compile method 'Lucene.Net.Support.LurchTable2&lt;Lucene.Net.Facet.Taxonomy.FacetLabel,
Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class&gt;:InternalInsert&lt;Lucene.Net.Support.LurchTable2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel,
Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>> (int,Lucene.Net.Facet.Taxonomy.FacetLabel,int&,Lucene.Net.Support.LurchTable`2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel,
Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>&)' while running
in aot-only mode. See [https://developer.xamarin.com/guides/ios/advanced_topics/limitations/]
for more information._
> _{color:#d04437}at Lucene.Net.Support.LurchTable2[TKey,TValue].Insert[T] (TKey key, T&amp;
value) &lt;0x2570f48 + 0x000e0&gt; in &lt;063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83bf2e9713bb8ea&gt;:0
at (wrapper unknown) System.Object.gsharedvt_in() at Lucene.Net.Support.LurchTable2[TKey,TValue].AddOrUpdate
(TKey key, TValue addValue, Lucene.Net.Support.KeyValueUpdate2[TKey,TValue] fnUpdate) &lt;0x232824c
+ 0x0013b&gt; in &lt;063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83bf2e9713bb8ea&gt;:0
at Lucene.Net.Facet.Taxonomy.LRUHashMap2[TKey,TValue].Put (TKey key, TValue value) <0x2c487f8
+ 0x0015b> in <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
at Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader.GetOrdinal (Lucene.Net.Facet.Taxonomy.FacetLabel
cp) <0x2c51970 + 0x0019b> in <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
at Lucene.Net.Facet.Taxonomy.Int32TaxonomyFacets.GetTopChildren{color} (System.Int32 topN,
System.String dim, System.String[] path) <0x2c481dc + 0x0008f> in <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
at Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloXRicercaAvanzataConRicercaSemplice
(System.Collections.Generic.List1[T] listParametri) &lt;0x224add0 + 0x001bb&gt; in
&lt;8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea&gt;:0 at Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloConRicercaSemplice
(System.Collections.Generic.List1[T] listParametri) <0x224afbc + 0x0009f> in <8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
at MyMB.Forms.RicercaLucene.RicercaArticoloLucene.GetListaArticoliXRicercaSemplice (Login.MyMB.Interface.IAmbiente
ambiente, Login.MyMB.Lucene.Client.LuceneArticoliSearcher las, System.Collections.Generic.List`1[T]
ListParametri, System.Boolean isAbilitataRicercaBarcode) <0xe47fc0 + 0x000e7> in <f1bb3149abe145459612794f1a096634#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0
..............................._
> At the link [https://docs.microsoft.com/it-it/xamarin/ios/internals/limitations] , I
found the problem cause (I suppose...):
> _Value types as Dictionary Keys Using a value type as a Dictionary<TKey, TValue>
key is problematic, as the default Dictionary constructor attempts to use EqualityComparer<TKey>.Default.
EqualityComparer<TKey>.Default, in turn, attempts to use Reflection to instantiate a
new type which implements the IEqualityComparer<TKey> interface. This works for reference
types (as the reflection+create a new type step is skipped), but for value types it crashes
and burns rather quickly once you attempt to use it on the device. Workaround: Manually implement
the IEqualityComparer<TKey> interface in a new type and provide an instance of that
type to the Dictionary<TKey, TValue> (IEqualityComparer<TKey>) constructor._
> So, what can I do? Thank you in advance, Enrico Caltran +393357485560 [enrico.caltran@timegroup.it|mailto:enrico.caltran@timegroup.it]



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Mime
View raw message