Ejemplo n.º 1
0
        protected override IEnumerable <string> GetKeysMatching <T>(Func <T, bool> predicate)
        {
            var allMatches = new List <string>();
            var allTerms   = new List <string>();

            var scopedReader = _indexController.GetScopedReader();

            var cachekey    = "CacheKey";
            var termScanner = scopedReader.InnerReader.Terms(new Term(cachekey, string.Empty));

            // Lucene doesn't start at -1 so can't just do "while termScanner.Next()"
            var termEnumerator = termScanner.Term();

            while (termEnumerator != null && termEnumerator.Field() == "CacheKey")
            {
                var asText = termEnumerator.Text();
                allTerms.Add(asText);

                var asKey = (CacheKey <T>)asText;
                if (asKey != null)
                {
                    var matches = predicate.Invoke(asKey.Original);
                    if (matches)
                    {
                        allMatches.Add(asText);
                    }
                }
                termEnumerator = termScanner.Next() ? termScanner.Term() : null;
            }
            return(allMatches);
        }