Guest User

Untitled

a guest
Jun 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. [Fact]
  2. public void DefaultIndexingBehaviourDoesNotAllowStartsWith()
  3. {
  4. using (var store = this.NewDocumentStore())
  5. {
  6. var index = new IndexDefinition<Blog, BlogTagItem>()
  7. {
  8. Map = docs => from doc in docs
  9. from tag in doc.Tags
  10. select new
  11. {
  12. tag.Name
  13. },
  14. Reduce = results => from result in results
  15. group result by result.Name into g
  16. select new
  17. {
  18. Name = g.Key,
  19. Count = g.Count()
  20. }
  21.  
  22. }.ToIndexDefinition(store.Conventions);
  23.  
  24. store.DatabaseCommands.PutIndex("TagInfo", index);
  25.  
  26.  
  27. using (var session = store.OpenSession())
  28. {
  29. var newBlog = new Blog()
  30. {
  31. Tags = new BlogTag[]{
  32. new BlogTag() { Name = "SuperCallaFragalisticExpealadocious" }
  33. }
  34. };
  35. session.Store(newBlog);
  36. session.SaveChanges();
  37.  
  38. var result = session.Query<BlogTagItem>("TagInfo")
  39. .Customize(x => x.WaitForNonStaleResults())
  40. .Where(x => x.Name.StartsWith("Su"))
  41. .FirstOrDefault();
  42.  
  43. Assert.Null(result);
  44. }
  45. }
  46. }
  47.  
  48. public class BlogTagItem
  49. {
  50. public string Name { get; set; }
  51. public int Count { get; set; }
  52. }
  53.  
  54. public class Blog
  55. {
  56. public string Title
  57. {
  58. get;
  59. set;
  60. }
  61.  
  62. public string Category
  63. {
  64. get;
  65. set;
  66. }
  67.  
  68. public BlogTag[] Tags
  69. {
  70. get;
  71. set;
  72. }
  73. }
  74.  
  75. public class BlogTag
  76. {
  77. public string Name { get; set; }
  78. }
Add Comment
Please, Sign In to add comment