19 using System.Runtime.CompilerServices;
20 using Lucene.Net.Index;
21 using Spatial4n.Core.Shapes;
23 using Lucene.Net.Support;
26 namespace Lucene.Net.Spatial.Util
36 public abstract class ShapeFieldCacheProvider<T> where T : Shape
42 private readonly ConditionalWeakTable<IndexReader, ShapeFieldCache<T>> sidx =
43 new ConditionalWeakTable<IndexReader, ShapeFieldCache<T>>();
45 private readonly WeakDictionary<IndexReader, ShapeFieldCache<T>> sidx =
46 new WeakDictionary<IndexReader, ShapeFieldCache<T>>();
53 protected ShapeFieldCacheProvider(String shapeField,
int defaultSize)
55 this.shapeField = shapeField;
56 this.defaultSize = defaultSize;
59 protected abstract T ReadShape(
Term term);
61 private readonly
object locker =
new object();
68 if (sidx.TryGetValue(reader, out idx) && idx != null)
80 var term = tec.Next();
83 var shape = ReadShape(term);
86 var docs = reader.
TermDocs(
new Term(shapeField, tec.Term().Text));
89 idx.Add(docs.Doc, shape);
96 sidx.Add(reader, idx);