forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQueryingIntArray.cs
88 lines (77 loc) · 2.68 KB
/
QueryingIntArray.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
79
80
81
82
83
84
85
86
87
88
// -----------------------------------------------------------------------
// <copyright file="QueryingIntArray.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Tests.Common;
using Raven.Tests.Helpers;
using Xunit;
namespace Raven.Tests.MailingList
{
public class QueryingIntArray : RavenTestBase
{
[Fact]
public void Test()
{
using (EmbeddableDocumentStore store = NewDocumentStore())
{
new FooIndex().Execute(store);
using (IDocumentSession session = store.OpenSession())
{
session.Store(new FooDocument
{
Name = "Test 1",
Resolutions = new[] {1, 3, 5, 7, 9}
});
session.Store(new FooDocument
{
Name = "Test 2",
Resolutions = new[] {5, 7, 9, 11, 13}
});
session.SaveChanges();
}
WaitForIndexing(store);
using (IDocumentSession session = store.OpenSession())
{
List<IndexEntry> results = session.Query<IndexEntry, FooIndex>()
.Customize(customization => customization.WaitForNonStaleResultsAsOfNow())
.Search(o => o.Name, "Test")
.Where(o => o.Resolutions.Any(x => x >= 5 && x <= 9))
.ProjectFromIndexFieldsInto<IndexEntry>()
.ToList();
Assert.Equal(2, results.Count);
}
}
}
}
public class FooDocument
{
public string Name { get; set; }
public int[] Resolutions { get; set; }
}
public class IndexEntry
{
public string Name { get; set; }
public int[] Resolutions { get; set; }
}
public class FooIndex : AbstractIndexCreationTask<FooDocument, IndexEntry>
{
public FooIndex()
{
Map = docs => from doc in docs
select new IndexEntry
{
Name = doc.Name,
Resolutions = doc.Resolutions
};
Indexes.Add(x => x.Name, FieldIndexing.Analyzed);
Stores.Add(x => x.Resolutions, FieldStorage.Yes);
}
}
}