forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgjerster.cs
91 lines (80 loc) · 2.64 KB
/
gjerster.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
89
90
91
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Client.Linq;
using Raven.Tests.Common;
using Xunit;
using Xunit.Extensions;
namespace Raven.Tests.MailingList
{
public class gjerster : RavenTest
{
[Theory]
[InlineData("singa*")]
[InlineData("pte")]
[InlineData("ltd")]
[InlineData("*inga*")]
public void CanSearchWithPrefixWildcard(string query)
{
using (var store = NewDocumentStore())
{
new SampleDataIndex().Execute(store);
using (IDocumentSession session = store.OpenSession())
{
session.Store(new SampleData
{
Name = "Singapore",
Description = "SINGAPORE PTE LTD"
});
session.SaveChanges();
}
using (IDocumentSession session = store.OpenSession())
{
var rq = session
.Query<SampleDataIndex.ReducedResult, SampleDataIndex>()
.Customize(customization => customization.WaitForNonStaleResultsAsOfNow());
var result =
rq.Search(x => x.Query, query,
escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
.As<SampleData>()
.Take(10)
.ToList();
if(result.Count == 0)
{
}
Assert.NotEmpty(result);
}
}
}
}
public class SampleData
{
public string Name { get; set; }
public string Description { get; set; }
}
public class SampleDataIndex : AbstractIndexCreationTask<SampleData, SampleDataIndex.ReducedResult>
{
public SampleDataIndex()
{
Map = docs => from doc in docs
select new
{
Query = new object[]
{
doc.Name,
doc.Description
}
};
Indexes.Add(x => x.Query, FieldIndexing.Analyzed);
}
#region Nested type: ReducedResult
public class ReducedResult
{
public string Query { get; set; }
}
#endregion
}
}