public void Convert_select_many_will_keep_doc_id() { IndexDefinition indexDefinition = new IndexDefinitionBuilder <Order> { Map = orders => from order in orders from line in order.OrderLines select new { line.ProductId } }.ToIndexDefinition(new DocumentConvention { PrettifyGeneratedLinqExpressions = false }); indexDefinition.Name = "Index1"; var index = IndexAndTransformerCompiler.Compile(indexDefinition); var map = index.Maps.Values.First(); using (var context = JsonOperationContext.ShortTermSingleUse()) { var results = map(new[] { GetDocumentFromString( @" { '@metadata': {'Raven-Entity-Name': 'Orders', '@id': 1}, 'OrderLines': [{'ProductId': 2}, {'ProductId': 3}] }".Replace("\r\n", Environment.NewLine), context), GetDocumentFromString( @" { '@metadata': {'Raven-Entity-Name': 'Orders', '@id': 2}, 'OrderLines': [{'ProductId': 5}, {'ProductId': 4}] }".Replace("\r\n", Environment.NewLine), context) }).Cast <object>().ToArray(); var fields = index.OutputFields .Select(x => IndexField.Create(x, new IndexFieldOptions(), null)) .ToList(); var converter = new AnonymousLuceneDocumentConverter(fields); foreach (var result in results) { using (var lazyStringValue = context.GetLazyString("docs/1")) { bool shouldSkip; converter.SetDocument(lazyStringValue, result, context, out shouldSkip); Assert.Equal("docs/1", converter.Document.Get("__document_id")); } } } }
public void Sum_of_elements() { IndexAndTransformerCompiler.Compile(new IndexDefinition { Name = "test", Maps = { @"from order in docs.Orders select new { order.Company, Count = 1, Total = order.Lines.Sum(l => l.PricePerUnit) }" } }); }
public void CanCompileComplexQuery() { var indexDefinition = new IndexDefinitionBuilder <Person>() { Map = people => from person in people from role in person.Roles where role == "Student" select new { role } }.ToIndexDefinition(new DocumentConvention { PrettifyGeneratedLinqExpressions = false }); indexDefinition.Name = "Index1"; IndexAndTransformerCompiler.Compile(indexDefinition); }