public CachedDistanceDocValues(IndexReader reader, ShapeFieldCacheDistanceValueSource enclosingInstance)
            {
                cache = enclosingInstance.provider.GetCache(reader);
                this.enclosingInstance = enclosingInstance;

                from       = enclosingInstance.from;
                calculator = enclosingInstance.ctx.GetDistCalc();
                nullValue  = (enclosingInstance.ctx.IsGeo() ? 180 : double.MaxValue);
            }
            public CachedDistanceFunctionValue(AtomicReader reader, ShapeFieldCacheDistanceValueSource enclosingInstance)
            {
                cache = enclosingInstance.provider.GetCache(reader);
                this.enclosingInstance = enclosingInstance;

                from       = enclosingInstance.from;
                calculator = enclosingInstance.ctx.DistCalc;
                nullValue  = (enclosingInstance.ctx.IsGeo ? 180 * enclosingInstance.multiplier : double.MaxValue);
            }
Esempio n. 3
0
 public CachedDistanceFunctionValue(ShapeFieldCacheDistanceValueSource outerInstance, AtomicReader reader)
 {
     // LUCENENET specific - added guard clauses
     this.outerInstance = outerInstance ?? throw new ArgumentNullException(nameof(outerInstance));
     if (reader is null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     cache      = outerInstance.provider.GetCache(reader);
     from       = outerInstance.from;
     calculator = outerInstance.ctx.DistanceCalculator;
     nullValue  = (outerInstance.ctx.IsGeo ? 180 * outerInstance.multiplier : double.MaxValue);
 }
        public virtual ShapeFieldCache <T> GetCache(AtomicReader reader)
        {
            lock (locker)
            {
                ShapeFieldCache <T> idx;
                if (sidx.TryGetValue(reader, out idx) && idx != null)
                {
                    return(idx);
                }

                /*long startTime = Runtime.CurrentTimeMillis();
                 *              log.Fine("Building Cache [" + reader.MaxDoc() + "]");*/
                idx = new ShapeFieldCache <T>(reader.MaxDoc, m_defaultSize);
                int       count = 0;
                DocsEnum  docs  = null;
                Terms     terms = reader.GetTerms(m_shapeField);
                TermsEnum te    = null;
                if (terms != null)
                {
                    te = terms.GetIterator(te);
                    BytesRef term = te.Next();
                    while (term != null)
                    {
                        T shape = ReadShape(term);
                        if (shape != null)
                        {
                            docs = te.Docs(null, docs, DocsFlags.NONE);
                            int docid = docs.NextDoc();
                            while (docid != DocIdSetIterator.NO_MORE_DOCS)
                            {
                                idx.Add(docid, shape);
                                docid = docs.NextDoc();
                                count++;
                            }
                        }
                        term = te.Next();
                    }
                }
                sidx[reader] = idx;

                /*long elapsed = Runtime.CurrentTimeMillis() - startTime;
                 * log.Fine("Cached: [" + count + " in " + elapsed + "ms] " + idx);*/
                return(idx);
            }
        }
        public ShapeFieldCache <T> GetCache(IndexReader reader)
        {
            lock (locker)
            {
                ShapeFieldCache <T> idx;
                if (sidx.TryGetValue(reader, out idx) && idx != null)
                {
                    return(idx);
                }

                //long startTime = System.CurrentTimeMillis();
                //log.fine("Building Cache [" + reader.MaxDoc() + "]");

                idx = new ShapeFieldCache <T>(reader.MaxDoc, defaultSize);
                var count = 0;
                var tec   = new TermsEnumCompatibility(reader, shapeField);

                var term = tec.Next();
                while (term != null)
                {
                    var shape = ReadShape(term);
                    if (shape != null)
                    {
                        var docs = reader.TermDocs(new Term(shapeField, tec.Term().Text));
                        while (docs.Next())
                        {
                            idx.Add(docs.Doc, shape);
                            count++;
                        }
                    }
                    term = tec.Next();
                }

                sidx.Add(reader, idx);
                tec.Close();

                //long elapsed = System.CurrentTimeMillis() - startTime;
                //log.fine("Cached: [" + count + " in " + elapsed + "ms] " + idx);
                return(idx);
            }
        }
        public virtual ShapeFieldCache <T> GetCache(AtomicReader reader)
        {
            // LUCENENET: ConditionalWeakTable allows us to simplify and remove locks
            return(sidx.GetValue(reader, (key) =>
            {
                /*long startTime = Runtime.CurrentTimeMillis();
                 * log.Fine("Building Cache [" + reader.MaxDoc() + "]");*/
                ShapeFieldCache <T> idx = new ShapeFieldCache <T>(key.MaxDoc, m_defaultSize);
                int count = 0;
                DocsEnum docs = null;
                Terms terms = ((AtomicReader)key).GetTerms(m_shapeField);
                TermsEnum te = null;
                if (terms != null)
                {
                    te = terms.GetIterator(te);
                    BytesRef term = te.Next();
                    while (term != null)
                    {
                        T shape = ReadShape(term);
                        if (shape != null)
                        {
                            docs = te.Docs(null, docs, DocsFlags.NONE);
                            int docid = docs.NextDoc();
                            while (docid != DocIdSetIterator.NO_MORE_DOCS)
                            {
                                idx.Add(docid, shape);
                                docid = docs.NextDoc();
                                count++;
                            }
                        }
                        term = te.Next();
                    }
                }

                /*long elapsed = Runtime.CurrentTimeMillis() - startTime;
                 * log.Fine("Cached: [" + count + " in " + elapsed + "ms] " + idx);*/
                return idx;
            }));
        }
Esempio n. 7
0
        public virtual ShapeFieldCache <T> GetCache(AtomicReader reader)
        {
            // LUCENENET: ConditionalWeakTable allows us to simplify and remove locks on the
            // read operation. For the create case, we use Lazy<T> to ensure atomicity.
            return(sidx.GetValue(reader, (key) => new Lazy <ShapeFieldCache <T> >(() =>
            {
                /*long startTime = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                 * log.Fine("Building Cache [" + reader.MaxDoc() + "]");*/
                ShapeFieldCache <T> idx = new ShapeFieldCache <T>(key.MaxDoc, m_defaultSize);
                int count = 0;
                DocsEnum?docs = null;
                Terms terms = ((AtomicReader)key).GetTerms(m_shapeField);
                TermsEnum?te = null;
                if (terms != null)
                {
                    te = terms.GetEnumerator(te);
                    while (te.MoveNext())
                    {
                        T?shape = ReadShape(te.Term);
                        if (shape != null)
                        {
                            docs = te.Docs(null, docs, DocsFlags.NONE);
                            int docid = docs.NextDoc();
                            while (docid != DocIdSetIterator.NO_MORE_DOCS)
                            {
                                idx.Add(docid, shape);
                                docid = docs.NextDoc();
                                count++;
                            }
                        }
                    }
                }

                /*long elapsed = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond - startTime; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results
                 * log.Fine("Cached: [" + count + " in " + elapsed + "ms] " + idx);*/
                return idx;
            })).Value);
        }