public void CanRoundtripIndexerWithFieldMappingFunctions() => Run(() => { Indexer expectedIndexer = new Indexer(SearchTestUtilities.GenerateName(), Data.DataSourceName, Data.TargetIndexName) { FieldMappings = new[] { // Try all the field mapping functions and parameters (even if they don't make sense in the context of the test DB). new FieldMapping("feature_id", "a", FieldMappingFunction.Base64Encode()), new FieldMapping("feature_id", "b", FieldMappingFunction.Base64Encode(useHttpServerUtilityUrlTokenEncode: true)), new FieldMapping("feature_id", "c", FieldMappingFunction.ExtractTokenAtPosition(delimiter: " ", position: 0)), new FieldMapping("feature_id", "d", FieldMappingFunction.Base64Decode()), new FieldMapping("feature_id", "e", FieldMappingFunction.Base64Decode(useHttpServerUtilityUrlTokenDecode: false)), new FieldMapping("feature_id", "f", FieldMappingFunction.JsonArrayToStringCollection()) } }; SearchServiceClient searchClient = Data.GetSearchServiceClient(); // We need to add desired fields to the index before those fields can be referenced by the field mappings Index index = searchClient.Indexes.Get(Data.TargetIndexName); string[] fieldNames = new[] { "a", "b", "c", "d", "e", "f" }; index.Fields = index.Fields.Concat(fieldNames.Select(name => new Field(name, DataType.String))).ToList(); searchClient.Indexes.CreateOrUpdate(index); searchClient.Indexers.Create(expectedIndexer); Indexer actualIndexer = searchClient.Indexers.Get(expectedIndexer.Name); AssertIndexersEqual(expectedIndexer, actualIndexer); });
public Indexer CreateTestIndexer() => new Indexer(SearchTestUtilities.GenerateName(), DataSourceName, TargetIndexName) { // We can't test startTime because it's an absolute time that must be within 24 hours of the current // time. That doesn't play well with recorded mock payloads. Schedule = new IndexingSchedule(interval: TimeSpan.FromDays(1)), FieldMappings = new[] { // Try all the field mapping functions (even if they don't make sense in the context of the test DB). new FieldMapping("feature_class", FieldMappingFunction.Base64Encode()), new FieldMapping("state_alpha", "state"), new FieldMapping("county_name", FieldMappingFunction.ExtractTokenAtPosition(" ", 0)), new FieldMapping("elev_in_m", "elevation"), new FieldMapping("map_name", FieldMappingFunction.Base64Decode()), new FieldMapping("history", FieldMappingFunction.JsonArrayToStringCollection()) } };