public void CreateMapReduceIndex() { var mapping = new Data.DynamicQueryMapping() { AggregationOperation = AggregationOperation.Count, Items = new[]{ new DynamicQueryMappingItem(){ From = "User.Name", To = "UserName" } } }; var definition = mapping.CreateIndexDefinition(); Assert.Equal(@"from doc in docs select new { UserName = doc.User.Name, Count = 1 }", definition.Map); Assert.Equal(@"from result in results group result by result.UserName into g select new { UserName = g.Key, Count = g.Sum(x=>x.Count) } ", definition.Reduce); }
public void CreateDefinitionSupportsArrayProperties() { Data.DynamicQueryMapping mapping = new Data.DynamicQueryMapping() { Items = new Data.DynamicQueryMappingItem[]{ new Data.DynamicQueryMappingItem(){ From = "Tags,Name", To = "docTagsName" } } }; var definition = mapping.CreateIndexDefinition(); Assert.Equal("from doc in docs\r\nfrom docTagsItem in (IEnumerable<dynamic>)doc.Tags\r\nselect new { docTagsName = docTagsItem.Name }", definition.Map); }
public void CreateDefinitionSupportsNestedProperties() { Data.DynamicQueryMapping mapping = new Data.DynamicQueryMapping() { Items = new Data.DynamicQueryMappingItem[]{ new Data.DynamicQueryMappingItem(){ From = "User.Name", To = "UserName" } } }; var definition = mapping.CreateIndexDefinition(); Assert.Equal("from doc in docs\r\nselect new { UserName = doc.User.Name }", definition.Map); }
public void CreateDefinitionSupportsSimpleProperties() { Data.DynamicQueryMapping mapping = new Data.DynamicQueryMapping() { Items = new Data.DynamicQueryMappingItem[]{ new Data.DynamicQueryMappingItem(){ From = "Name", To = "Name" } } }; var definition = mapping.CreateIndexDefinition(); Assert.Equal("from doc in docs\r\nselect new { Name = doc.Name }", definition.Map); }
private void CreateIndex(DynamicQueryMapping map, string indexName) { if (documentDatabase.GetIndexDefinition(indexName) != null) // avoid race condition when creating the index return; var definition = map.CreateIndexDefinition(); documentDatabase.PutIndex(indexName, definition); }