forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLargeQuery.cs
78 lines (63 loc) · 2.24 KB
/
LargeQuery.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Indexing;
using Raven.Client.Indexes;
using Raven.Client.Linq;
using Raven.Tests.Common;
using Raven.Tests.Helpers;
using Xunit;
namespace Raven.Tests.MailingList
{
public class LargeQuery : RavenTestBase
{
[Fact]
public void CanExecuteLargeQuery()
{
using (var store = NewDocumentStore())
{
store.Initialize();
new OrderIndex().Execute(store);
using (var session = store.OpenSession())
{
var elements = new List<string>();
for (int i = 0; i < 280; i++)
{
elements.Add("Orders/" + Guid.NewGuid().ToString());
}
var result = session.Query<OrderIndex.IndexResult, OrderIndex>()
.Where(p => p.Id.In(elements))
.Customize(customization => customization.WaitForNonStaleResultsAsOfNow())
.FirstOrDefault();
}
}
}
public class Order
{
public string Id { get; set; }
}
public class OrderIndex : AbstractMultiMapIndexCreationTask<OrderIndex.IndexResult>
{
public class IndexResult
{
public string Id { get; set; }
}
public OrderIndex()
{
AddMap<Order>(orders => from o in orders
select new
{
Id = o.Id,
});
Reduce = results => from result in results
group result by new { result.Id }
into gr
select new OrderIndex.IndexResult
{
Id = gr.Select(x => x.Id).FirstOrDefault(x => x != null),
};
StoreAllFields(FieldStorage.Yes);
}
}
}
}