Esempio n. 1
0
        internal static AbstractStaticIndexBase GenerateIndex(IndexDefinition definition, RavenConfiguration configuration, IndexType type, long indexVersion)
        {
            switch (type)
            {
            case IndexType.None:
            case IndexType.AutoMap:
            case IndexType.AutoMapReduce:
            case IndexType.Map:
            case IndexType.MapReduce:
            case IndexType.Faulty:
                return(IndexCompiler.Compile(definition));

            case IndexType.JavaScriptMap:
            case IndexType.JavaScriptMapReduce:
                return(AbstractJavaScriptIndex.Create(definition, configuration, indexVersion));

            default:
                throw new ArgumentOutOfRangeException($"Can't generate index of unknown type {definition.DetectStaticIndexType()}");
            }
        }
Esempio n. 2
0
        public static StaticIndexBase GetIndexInstance(IndexDefinition definition)
        {
            var list = new List <string>();

            list.AddRange(definition.Maps);
            if (definition.Reduce != null)
            {
                list.Add(definition.Reduce);
            }
            if (definition.AdditionalSources != null)
            {
                foreach (var kvp in definition.AdditionalSources.OrderBy(x => x.Key))
                {
                    list.Add(kvp.Key);
                    list.Add(kvp.Value);
                }
            }

            var key    = new CacheKey(list);
            var result = IndexCache.GetOrAdd(key, _ => new Lazy <StaticIndexBase>(() => IndexCompiler.Compile(definition)));

            try
            {
                return(result.Value);
            }
            catch (Exception)
            {
                IndexCache.TryRemove(key, out _);
                throw;
            }
        }