Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FieldCacheImpl.cs « Search « core « src - github.com/mono/Lucene.Net.Light.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c24dcc521b7d16bd6e40cdc0fa7a4edcafd19c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/* 
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lucene.Net.Support;
using NumericField = Lucene.Net.Documents.NumericField;
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
using TermDocs = Lucene.Net.Index.TermDocs;
using TermEnum = Lucene.Net.Index.TermEnum;
using FieldCacheSanityChecker = Lucene.Net.Util.FieldCacheSanityChecker;
using Single = Lucene.Net.Support.Single;
using StringHelper = Lucene.Net.Util.StringHelper;

namespace Lucene.Net.Search
{
    
    /// <summary> Expert: The default cache implementation, storing all values in memory.
    /// A WeakDictionary is used for storage.
    /// 
    /// <p/>Created: May 19, 2004 4:40:36 PM
    /// 
    /// </summary>
    /// <since>   lucene 1.4
    /// </since>
    class FieldCacheImpl : FieldCache
    {
        private IDictionary<Type, Cache> caches;

        internal FieldCacheImpl()
        {
            Init();
        }
        private void  Init()
        {
            lock (this)
            {
                caches = new HashMap<Type, Cache>(7);
                caches[typeof(sbyte)] = new ByteCache(this);
                caches[typeof(short)] = new ShortCache(this);
                caches[typeof(int)] = new IntCache(this);
                caches[typeof(float)] = new FloatCache(this);
                caches[typeof(long)] = new LongCache(this);
                caches[typeof(double)] = new DoubleCache(this);
                caches[typeof(string)] = new StringCache(this);
                caches[typeof(StringIndex)] = new StringIndexCache(this);
            }
        }

        // lucene.net: java version 3.0.3 with patch in rev. 912330 applied:
        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in FieldCacheImpl.getCacheEntries() that used 
        //                     WeakHashMap incorrectly and lead to ConcurrentModificationException
        public virtual void  PurgeAllCaches()
        {
            lock (this)
            {
                Init();
            }
        }

        // lucene.net: java version 3.0.3 with patch in rev. 912330 applied:
        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in FieldCacheImpl.getCacheEntries() that used 
        //                     WeakHashMap incorrectly and lead to ConcurrentModificationException
        public void Purge(IndexReader r)
        {
            lock (this)
            {
                foreach (Cache c in caches.Values)
                {
                    c.Purge(r);
                }
            }
        }

        // lucene.net: java version 3.0.3 with patch in rev. 912330 applied:
        // uschindler 21/02/2010 12:16:42 LUCENE-2273: Fixed bug in FieldCacheImpl.getCacheEntries() that used 
        //                     WeakHashMap incorrectly and lead to ConcurrentModificationException
        public virtual CacheEntry[] GetCacheEntries()
        {
            lock (this)
            {
                IList<CacheEntry> result = new List<CacheEntry>(17);
                foreach (var cacheEntry in caches)
                {
                    var cache = cacheEntry.Value;
                    var cacheType = cacheEntry.Key;
                    lock (cache.readerCache)
                    {
                        foreach (var readerCacheEntry in cache.readerCache)
                        {
                            var readerKey = readerCacheEntry.Key;
                            var innerCache = readerCacheEntry.Value;
                            foreach (var mapEntry in innerCache)
                            {
                                Entry entry = mapEntry.Key;
                                result.Add(new CacheEntryImpl(readerKey, entry.field, cacheType, entry.custom, mapEntry.Value));
                            }
                        }
                    }
                }
                return result.ToArray();
            }
        }
        
        private sealed class CacheEntryImpl : CacheEntry
        {
            private System.Object readerKey;
            private System.String fieldName;
            private System.Type cacheType;
            private System.Object custom;
            private System.Object value;
            internal CacheEntryImpl(System.Object readerKey, System.String fieldName, System.Type cacheType, System.Object custom, System.Object value)
            {
                this.readerKey = readerKey;
                this.fieldName = fieldName;
                this.cacheType = cacheType;
                this.custom = custom;
                this.value = value;
                
                // :HACK: for testing.
                //         if (null != locale || SortField.CUSTOM != sortFieldType) {
                //           throw new RuntimeException("Locale/sortFieldType: " + this);
                //         }
            }

            public override object ReaderKey
            {
                get { return readerKey; }
            }

            public override string FieldName
            {
                get { return fieldName; }
            }

            public override Type CacheType
            {
                get { return cacheType; }
            }

            public override object Custom
            {
                get { return custom; }
            }

            public override object Value
            {
                get { return value; }
            }
        }
        
        /// <summary> Hack: When thrown from a Parser (NUMERIC_UTILS_* ones), this stops
        /// processing terms and returns the current FieldCache
        /// array.
        /// </summary>
        [Serializable]
        internal sealed class StopFillCacheException:System.SystemException
        {
        }
        
        /// <summary>Expert: Internal cache. </summary>
        internal abstract class Cache
        {
            internal Cache()
            {
                this.wrapper = null;
            }
            
            internal Cache(FieldCache wrapper)
            {
                this.wrapper = wrapper;
            }
            
            internal FieldCache wrapper;

            internal IDictionary<object, IDictionary<Entry, object>> readerCache = new WeakDictionary<object, IDictionary<Entry, object>>();
            
            protected internal abstract System.Object CreateValue(IndexReader reader, Entry key);

            /* Remove this reader from the cache, if present. */
            public void Purge(IndexReader r)
            {
                object readerKey = r.FieldCacheKey;
                lock (readerCache)
                {
                    readerCache.Remove(readerKey);
                }
            }
            
            public virtual System.Object Get(IndexReader reader, Entry key)
            {
                IDictionary<Entry, object> innerCache;
                System.Object value;
                System.Object readerKey = reader.FieldCacheKey;
                lock (readerCache)
                {
                    innerCache = readerCache[readerKey];
                    if (innerCache == null)
                    {
                        innerCache = new HashMap<Entry, object>();
                        readerCache[readerKey] = innerCache;
                        value = null;
                    }
                    else
                    {
                        value = innerCache[key];
                    }
                    if (value == null)
                    {
                        value = new CreationPlaceholder();
                        innerCache[key] = value;
                    }
                }
                if (value is CreationPlaceholder)
                {
                    lock (value)
                    {
                        CreationPlaceholder progress = (CreationPlaceholder) value;
                        if (progress.value_Renamed == null)
                        {
                            progress.value_Renamed = CreateValue(reader, key);
                            lock (readerCache)
                            {
                                innerCache[key] = progress.value_Renamed;
                            }
                            
                            // Only check if key.custom (the parser) is
                            // non-null; else, we check twice for a single
                            // call to FieldCache.getXXX
                            if (key.custom != null && wrapper != null)
                            {
                                System.IO.StreamWriter infoStream = wrapper.InfoStream;
                                if (infoStream != null)
                                {
                                    PrintNewInsanity(infoStream, progress.value_Renamed);
                                }
                            }
                        }
                        return progress.value_Renamed;
                    }
                }
                return value;
            }
            
            private void  PrintNewInsanity(System.IO.StreamWriter infoStream, System.Object value_Renamed)
            {
                FieldCacheSanityChecker.Insanity[] insanities = FieldCacheSanityChecker.CheckSanity(wrapper);
                for (int i = 0; i < insanities.Length; i++)
                {
                    FieldCacheSanityChecker.Insanity insanity = insanities[i];
                    CacheEntry[] entries = insanity.GetCacheEntries();
                    for (int j = 0; j < entries.Length; j++)
                    {
                        if (entries[j].Value == value_Renamed)
                        {
                            // OK this insanity involves our entry
                            infoStream.WriteLine("WARNING: new FieldCache insanity created\nDetails: " + insanity.ToString());
                            infoStream.WriteLine("\nStack:\n");
                            infoStream.WriteLine(new System.Exception());
                            break;
                        }
                    }
                }
            }
        }
        
        /// <summary>Expert: Every composite-key in the internal cache is of this type. </summary>
        protected internal class Entry
        {
            internal System.String field; // which Fieldable
            internal System.Object custom; // which custom comparator or parser

            /// <summary>Creates one of these objects for a custom comparator/parser. </summary>
            internal Entry(System.String field, System.Object custom)
            {
                this.field = StringHelper.Intern(field);
                this.custom = custom;
            }
            
            /// <summary>Two of these are equal iff they reference the same field and type. </summary>
            public  override bool Equals(System.Object o)
            {
                if (o is Entry)
                {
                    Entry other = (Entry) o;
                    if (other.field == field)
                    {
                        if (other.custom == null)
                        {
                            if (custom == null)
                                return true;
                        }
                        else if (other.custom.Equals(custom))
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
            
            /// <summary>Composes a hashcode based on the field and type. </summary>
            public override int GetHashCode()
            {
                return field.GetHashCode() ^  (custom == null?0:custom.GetHashCode());
            }
        }
        
        // inherit javadocs
        public virtual sbyte[] GetBytes(IndexReader reader, System.String field)
        {
            return GetBytes(reader, field, null);
        }
        
        // inherit javadocs
        public virtual sbyte[] GetBytes(IndexReader reader, System.String field, ByteParser parser)
        {
            return (sbyte[]) caches[typeof(sbyte)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class ByteCache:Cache
        {
            internal ByteCache(FieldCache wrapper):base(wrapper)
            {
            }
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                ByteParser parser = (ByteParser) entry.custom;
                if (parser == null)
                {
                    return wrapper.GetBytes(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_BYTE_PARSER);
                }
                sbyte[] retArray = new sbyte[reader.MaxDoc];
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        sbyte termval = parser.ParseByte(term.Text);
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                return retArray;
            }
        }
        
        
        // inherit javadocs
        public virtual short[] GetShorts(IndexReader reader, System.String field)
        {
            return GetShorts(reader, field, null);
        }
        
        // inherit javadocs
        public virtual short[] GetShorts(IndexReader reader, System.String field, ShortParser parser)
        {
            return (short[]) caches[typeof(short)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class ShortCache:Cache
        {
            internal ShortCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                ShortParser parser = (ShortParser) entry.custom;
                if (parser == null)
                {
                    return wrapper.GetShorts(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_SHORT_PARSER);
                }
                short[] retArray = new short[reader.MaxDoc];
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        short termval = parser.ParseShort(term.Text);
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                return retArray;
            }
        }
        
        
        // inherit javadocs
        public virtual int[] GetInts(IndexReader reader, System.String field)
        {
            return GetInts(reader, field, null);
        }
        
        // inherit javadocs
        public virtual int[] GetInts(IndexReader reader, System.String field, IntParser parser)
        {
            return (int[]) caches[typeof(int)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class IntCache:Cache
        {
            internal IntCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                IntParser parser = (IntParser) entry.custom;
                if (parser == null)
                {
                    try
                    {
                        return wrapper.GetInts(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_INT_PARSER);
                    }
                    catch (System.FormatException)
                    {
                        return wrapper.GetInts(reader, field, Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_INT_PARSER);
                    }
                }
                int[] retArray = null;
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        int termval = parser.ParseInt(term.Text);
                        if (retArray == null)
                        // late init
                            retArray = new int[reader.MaxDoc];
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                if (retArray == null)
                // no values
                    retArray = new int[reader.MaxDoc];
                return retArray;
            }
        }
        
        
        
        // inherit javadocs
        public virtual float[] GetFloats(IndexReader reader, System.String field)
        {
            return GetFloats(reader, field, null);
        }
        
        // inherit javadocs
        public virtual float[] GetFloats(IndexReader reader, System.String field, FloatParser parser)
        {
            
            return (float[]) caches[typeof(float)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class FloatCache:Cache
        {
            internal FloatCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                FloatParser parser = (FloatParser) entry.custom;
                if (parser == null)
                {
                    try
                    {
                        return wrapper.GetFloats(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_FLOAT_PARSER);
                    }
                    catch (System.FormatException)
                    {
                        return wrapper.GetFloats(reader, field, Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_FLOAT_PARSER);
                    }
                }
                float[] retArray = null;
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        float termval = parser.ParseFloat(term.Text);
                        if (retArray == null)
                        // late init
                            retArray = new float[reader.MaxDoc];
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                if (retArray == null)
                // no values
                    retArray = new float[reader.MaxDoc];
                return retArray;
            }
        }
        
        
        
        public virtual long[] GetLongs(IndexReader reader, System.String field)
        {
            return GetLongs(reader, field, null);
        }
        
        // inherit javadocs
        public virtual long[] GetLongs(IndexReader reader, System.String field, Lucene.Net.Search.LongParser parser)
        {
            return (long[]) caches[typeof(long)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class LongCache:Cache
        {
            internal LongCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                Lucene.Net.Search.LongParser parser = (Lucene.Net.Search.LongParser) entry.custom;
                if (parser == null)
                {
                    try
                    {
                        return wrapper.GetLongs(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_LONG_PARSER);
                    }
                    catch (System.FormatException)
                    {
                        return wrapper.GetLongs(reader, field, Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_LONG_PARSER);
                    }
                }
                long[] retArray = null;
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        long termval = parser.ParseLong(term.Text);
                        if (retArray == null)
                        // late init
                            retArray = new long[reader.MaxDoc];
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                if (retArray == null)
                // no values
                    retArray = new long[reader.MaxDoc];
                return retArray;
            }
        }
        
        
        // inherit javadocs
        public virtual double[] GetDoubles(IndexReader reader, System.String field)
        {
            return GetDoubles(reader, field, null);
        }
        
        // inherit javadocs
        public virtual double[] GetDoubles(IndexReader reader, System.String field, Lucene.Net.Search.DoubleParser parser)
        {
            return (double[]) caches[typeof(double)].Get(reader, new Entry(field, parser));
        }
        
        internal sealed class DoubleCache:Cache
        {
            internal DoubleCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                Entry entry = entryKey;
                System.String field = entry.field;
                Lucene.Net.Search.DoubleParser parser = (Lucene.Net.Search.DoubleParser) entry.custom;
                if (parser == null)
                {
                    try
                    {
                        return wrapper.GetDoubles(reader, field, Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);
                    }
                    catch (System.FormatException)
                    {
                        return wrapper.GetDoubles(reader, field, Lucene.Net.Search.FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
                    }
                }
                double[] retArray = null;
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        double termval = parser.ParseDouble(term.Text);
                        if (retArray == null)
                        // late init
                            retArray = new double[reader.MaxDoc];
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                catch (StopFillCacheException)
                {
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                if (retArray == null)
                // no values
                    retArray = new double[reader.MaxDoc];
                return retArray;
            }
        }
        
        
        // inherit javadocs
        public virtual System.String[] GetStrings(IndexReader reader, System.String field)
        {
            return (System.String[]) caches[typeof(string)].Get(reader, new Entry(field, (Parser) null));
        }
        
        internal sealed class StringCache:Cache
        {
            internal StringCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String field = StringHelper.Intern(entryKey.field);
                System.String[] retArray = new System.String[reader.MaxDoc];
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || (System.Object) term.Field != (System.Object) field)
                            break;
                        System.String termval = term.Text;
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = termval;
                        }
                    }
                    while (termEnum.Next());
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                return retArray;
            }
        }
        
        
        // inherit javadocs
        public virtual StringIndex GetStringIndex(IndexReader reader, System.String field)
        {
            return (StringIndex) caches[typeof(StringIndex)].Get(reader, new Entry(field, (Parser) null));
        }
        
        internal sealed class StringIndexCache:Cache
        {
            internal StringIndexCache(FieldCache wrapper):base(wrapper)
            {
            }
            
            protected internal override System.Object CreateValue(IndexReader reader, Entry entryKey)
            {
                System.String field = StringHelper.Intern(entryKey.field);
                int[] retArray = new int[reader.MaxDoc];
                System.String[] mterms = new System.String[reader.MaxDoc + 1];
                TermDocs termDocs = reader.TermDocs();
                TermEnum termEnum = reader.Terms(new Term(field));
                int t = 0; // current term number
                
                // an entry for documents that have no terms in this field
                // should a document with no terms be at top or bottom?
                // this puts them at the top - if it is changed, FieldDocSortedHitQueue
                // needs to change as well.
                mterms[t++] = null;
                
                try
                {
                    do 
                    {
                        Term term = termEnum.Term;
                        if (term == null || term.Field != field || t >= mterms.Length) break;
                        
                        // store term text
                        mterms[t] = term.Text;
                        
                        termDocs.Seek(termEnum);
                        while (termDocs.Next())
                        {
                            retArray[termDocs.Doc] = t;
                        }
                        
                        t++;
                    }
                    while (termEnum.Next());
                }
                finally
                {
                    termDocs.Close();
                    termEnum.Close();
                }
                
                if (t == 0)
                {
                    // if there are no terms, make the term array
                    // have a single null entry
                    mterms = new System.String[1];
                }
                else if (t < mterms.Length)
                {
                    // if there are less terms than documents,
                    // trim off the dead array space
                    System.String[] terms = new System.String[t];
                    Array.Copy(mterms, 0, terms, 0, t);
                    mterms = terms;
                }
                
                StringIndex value_Renamed = new StringIndex(retArray, mterms);
                return value_Renamed;
            }
        }
        
        private volatile System.IO.StreamWriter infoStream;

        public virtual StreamWriter InfoStream
        {
            get { return infoStream; }
            set { infoStream = value; }
        }
    }
}