private SpanFilterResult GetCachedResult(IndexReader reader)
        {
            object coreKey    = reader.FieldCacheKey;
            object delCoreKey = reader.HasDeletions ? reader.DeletesCacheKey : coreKey;

            SpanFilterResult result = cache.Get(reader, coreKey, delCoreKey);

            if (result != null)
            {
                hitCount++;
                return(result);
            }

            missCount++;
            result = filter.BitSpans(reader);

            cache.Put(coreKey, delCoreKey, result);
            return(result);
        }
        private SpanFilterResult GetCachedResult(IndexReader reader)
        {
            SpanFilterResult result = null;

            if (cache == null)
            {
                cache = new SupportClass.WeakHashTable();
            }

            lock (cache.SyncRoot)
            {
                // check cache
                result = (SpanFilterResult)cache[reader];
                if (result == null)
                {
                    result        = filter.BitSpans(reader);
                    cache[reader] = result;
                }
            }
            return(result);
        }
Exemple #3
0
        private SpanFilterResult GetCachedResult(IndexReader reader)
        {
            SpanFilterResult result = null;

            if (cache == null)
            {
                cache = new System.Collections.Hashtable();
            }

            lock (cache.SyncRoot)
            {
                // check cache
                result = (SpanFilterResult)cache[reader];
                if (result == null)
                {
                    result        = filter.BitSpans(reader);
                    cache[reader] = result;
                }
            }
            return(result);
        }
        public virtual void  TestFilterWorks()
        {
            Directory   dir    = new RAMDirectory();
            IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED, null);

            for (int i = 0; i < 500; i++)
            {
                Document document = new Document();
                document.Add(new Field("field", English.IntToEnglish(i) + " equals " + English.IntToEnglish(i), Field.Store.NO, Field.Index.ANALYZED));
                writer.AddDocument(document, null);
            }
            writer.Close();

            IndexReader reader = IndexReader.Open(dir, true, null);

            SpanTermQuery    query    = new SpanTermQuery(new Term("field", English.IntToEnglish(10).Trim()));
            SpanQueryFilter  filter   = new SpanQueryFilter(query);
            SpanFilterResult result   = filter.BitSpans(reader, null);
            DocIdSet         docIdSet = result.DocIdSet;

            Assert.IsTrue(docIdSet != null, "docIdSet is null and it shouldn't be");
            AssertContainsDocId("docIdSet doesn't contain docId 10", docIdSet, 10);
            var spans = result.Positions;

            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
            int size = GetDocIdSetSize(docIdSet);

            Assert.IsTrue(spans.Count == size, "spans Size: " + spans.Count + " is not: " + size);
            for (System.Collections.IEnumerator iterator = spans.GetEnumerator(); iterator.MoveNext();)
            {
                SpanFilterResult.PositionInfo info = (SpanFilterResult.PositionInfo)iterator.Current;
                Assert.IsTrue(info != null, "info is null and it shouldn't be");
                //The doc should indicate the bit is on
                AssertContainsDocId("docIdSet doesn't contain docId " + info.Doc, docIdSet, info.Doc);
                //There should be two positions in each
                Assert.IsTrue(info.Positions.Count == 2, "info.getPositions() Size: " + info.Positions.Count + " is not: " + 2);
            }
            reader.Close();
        }
Exemple #5
0
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            SpanFilterResult result = BitSpans(reader);

            return(result.GetDocIdSet());
        }
Exemple #6
0
        public override DocIdSet GetDocIdSet(IndexReader reader, IState state)
        {
            SpanFilterResult result = BitSpans(reader, state);

            return(result.DocIdSet);
        }
        public override DocIdSet GetDocIdSet(IndexReader reader)
        {
            SpanFilterResult result = GetCachedResult(reader);

            return(result != null?result.DocIdSet:null);
        }
        public override System.Collections.BitArray Bits(IndexReader reader)
        {
            SpanFilterResult result = BitSpans(reader);

            return(result.GetBits());
        }
        public override System.Collections.BitArray Bits(IndexReader reader)
        {
            SpanFilterResult result = GetCachedResult(reader);

            return(result != null?result.GetBits() : null);
        }