public static object ReadIndexDefinition(BlittableJsonReaderObject reader, BuildVersionType buildVersionType, out IndexType type) { switch (buildVersionType) { case BuildVersionType.V3: // pre 4.0 support var indexDefinition = ReadLegacyIndexDefinition(reader); type = indexDefinition.Type; Debug.Assert(type.IsStatic()); return(indexDefinition); case BuildVersionType.V4: type = ReadIndexType(reader, out reader); switch (type) { case IndexType.AutoMap: return(AutoMapIndexDefinition.LoadFromJson(reader)); case IndexType.AutoMapReduce: return(AutoMapReduceIndexDefinition.LoadFromJson(reader)); case IndexType.Map: case IndexType.MapReduce: return(JsonDeserializationServer.IndexDefinition(reader)); default: throw new NotSupportedException(type.ToString()); } default: throw new ArgumentOutOfRangeException(nameof(buildVersionType), buildVersionType, null); } }
public static void Import(BlittableJsonReaderObject indexDefinitionDoc, DocumentDatabase database, long buildVersion, bool removeAnalyzers) { if (buildVersion == 0) // pre 4.0 support { var indexDefinition = ReadLegacyIndexDefinition(indexDefinitionDoc); if (string.Equals(indexDefinition.Name, "Raven/DocumentsByEntityName", StringComparison.OrdinalIgnoreCase)) { // skipping not needed old default index return; } database.IndexStore.CreateIndex(indexDefinition); } //I think supporting only major version as a number should be here, //so we can use ServerVersion.Build to get the build and not hardcode it else if (buildVersion == 13 || (buildVersion >= 40000 && buildVersion <= 44999) || (buildVersion >= 40 && buildVersion <= 44)) { var indexType = ReadIndexType(indexDefinitionDoc, out indexDefinitionDoc); switch (indexType) { case IndexType.AutoMap: var autoMapIndexDefinition = AutoMapIndexDefinition.LoadFromJson(indexDefinitionDoc); database.IndexStore.CreateIndex(autoMapIndexDefinition); break; case IndexType.AutoMapReduce: var autoMapReduceIndexDefinition = AutoMapReduceIndexDefinition.LoadFromJson(indexDefinitionDoc); database.IndexStore.CreateIndex(autoMapReduceIndexDefinition); break; case IndexType.Map: case IndexType.MapReduce: var indexDefinition = JsonDeserializationServer.IndexDefinition(indexDefinitionDoc); if (removeAnalyzers) { foreach (var indexDefinitionField in indexDefinition.Fields) { indexDefinitionField.Value.Analyzer = null; } } database.IndexStore.CreateIndex(indexDefinition); break; default: throw new NotSupportedException(indexType.ToString()); } } else { throw new NotSupportedException($"We do not support importing indexes from '{buildVersion}' build."); } }