Example #1
0
        public void CanUseBasicMoreLikeThis()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Posts_ByTitleAndContent();
                index.Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Post { Id = "posts/1", Title = "doduck", Desc = "prototype" });
                    session.Store(new Post { Id = "posts/2", Title = "doduck", Desc = "prototype your idea" });
                    session.Store(new Post { Id = "posts/3", Title = "doduck", Desc = "love programming" });
                    session.Store(new Post { Id = "posts/4", Title = "We do", Desc = "prototype" });
                    session.Store(new Post { Id = "posts/5", Title = "We love", Desc = "challange" });
                    session.SaveChanges();

                    WaitForIndexing(store);

                    var list = session.Advanced.MoreLikeThis<Post, Posts_ByTitleAndContent>(new MoreLikeThisQuery 
                        { 
                            DocumentId = "posts/1",
                            MinimumDocumentFrequency = 1,
                            MinimumTermFrequency = 0
                        });

                    Assert.Equal(3, list.Length);
                    Assert.Equal("doduck", list[0].Title);
                    Assert.Equal("prototype your idea", list[0].Desc);
                    Assert.Equal("doduck", list[1].Title);
                    Assert.Equal("love programming", list[1].Desc);
                    Assert.Equal("We do", list[2].Title);
                    Assert.Equal("prototype", list[2].Desc);
                }
            }
        }
Example #2
0
        public void CanUseMoreLikeThisWithTransformer()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Posts_ByTitleAndContent();
                index.Execute(store);
                var transformer = new PostWithContentTransformer();
                transformer.Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Post { Id = "posts/1", Title = "doduck", Desc = "prototype" });
                    session.Store(new Post { Id = "posts/2", Title = "doduck", Desc = "prototype your idea" });
                    session.Store(new Post { Id = "posts/3", Title = "doduck", Desc = "love programming" });
                    session.Store(new Post { Id = "posts/4", Title = "We do", Desc = "prototype" });
                    session.Store(new Post { Id = "posts/5", Title = "We love", Desc = "challange" });
                    session.Store(new Post { Id = "posts/6", Title = "We love", Desc = "challange" });
                    session.Store(new PostContent { Id = "posts/1/content", Text = "transform1" });
                    session.Store(new PostContent { Id = "posts/2/content", Text = "transform2" });
                    session.Store(new PostContent { Id = "posts/3/content", Text = "transform3" });
                    session.Store(new PostContent { Id = "posts/4/content", Text = "transform4" });
                    session.Store(new PostContent { Id = "posts/5/content", Text = "transform5" });
                    session.Store(new PostContent { Id = "posts/6/content", Text = "transform6" });
                    session.SaveChanges();

                    WaitForIndexing(store);

                    var list = session.Advanced.MoreLikeThis<PostWithContentTransformer.Result>(index.IndexName, transformer.TransformerName, new MoreLikeThisQuery
                    {
                        DocumentId = "posts/1",
                        MinimumDocumentFrequency = 1,
                        MinimumTermFrequency = 0
                    });

                    Assert.Equal(3, list.Length);
                    Assert.Equal("doduck", list[0].Title);
                    Assert.Equal("prototype your idea", list[0].Desc);
                    Assert.Equal("transform2", list[0].Content);
                    Assert.Equal("doduck", list[1].Title);
                    Assert.Equal("love programming", list[1].Desc);
                    Assert.Equal("transform3", list[1].Content);
                    Assert.Equal("We do", list[2].Title);
                    Assert.Equal("prototype", list[2].Desc);
                    Assert.Equal("transform4", list[2].Content);
                }
            }
        }
Example #3
0
        public void CanUseBasicMoreLikeThis()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Posts_ByTitleAndContent();
                index.Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Post {
                        Id = "posts/1", Title = "doduck", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/2", Title = "doduck", Desc = "prototype your idea"
                    });
                    session.Store(new Post {
                        Id = "posts/3", Title = "doduck", Desc = "love programming"
                    });
                    session.Store(new Post {
                        Id = "posts/4", Title = "We do", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/5", Title = "We love", Desc = "challange"
                    });
                    session.SaveChanges();

                    WaitForIndexing(store);

                    var list = session.Query <Post, Posts_ByTitleAndContent>()
                               .MoreLikeThis(f => f.UsingDocument(x => x.Id == "posts/1").WithOptions(new MoreLikeThisOptions
                    {
                        MinimumDocumentFrequency = 1,
                        MinimumTermFrequency     = 0
                    }))
                               .ToList();

                    Assert.Equal(3, list.Count);
                    Assert.Equal("doduck", list[0].Title);
                    Assert.Equal("prototype your idea", list[0].Desc);
                    Assert.Equal("doduck", list[1].Title);
                    Assert.Equal("love programming", list[1].Desc);
                    Assert.Equal("We do", list[2].Title);
                    Assert.Equal("prototype", list[2].Desc);
                }
            }
        }
Example #4
0
        public async Task CanGetIndexNames()
        {
            var index1 = new Users_ByName();
            var index2 = new Posts_ByTitleAndContent();

            using (var store = GetDocumentStore())
            {
                index1.Execute(store);
                index2.Execute(store);

                var indexes = await store.AsyncDatabaseCommands.GetIndexNamesAsync(0, 10);

                Assert.Equal(2, indexes.Length);
                Assert.Equal(index1.IndexName, indexes[1]);
                Assert.Equal(index2.IndexName, indexes[0]);
            }
        }
Example #5
0
        public async Task CanGetIndexNames()
        {
            var index1 = new Users_ByName();
            var index2 = new Posts_ByTitleAndContent();

            using (var store = GetDocumentStore())
            {
                index1.Execute(store);
                index2.Execute(store);

                var indexes = await store.Maintenance.SendAsync(new GetIndexNamesOperation(0, 10));

                Assert.Equal(2, indexes.Length);
                Assert.Equal(index1.IndexName, indexes[1]);
                Assert.Equal(index2.IndexName, indexes[0]);
            }
        }
Example #6
0
        public void CanUseBasicMoreLikeThis()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Posts_ByTitleAndContent();
                index.Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Post {
                        Id = "posts/1", Title = "doduck", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/2", Title = "doduck", Desc = "prototype your idea"
                    });
                    session.Store(new Post {
                        Id = "posts/3", Title = "doduck", Desc = "love programming"
                    });
                    session.Store(new Post {
                        Id = "posts/4", Title = "We do", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/5", Title = "We love", Desc = "challange"
                    });
                    session.SaveChanges();

                    WaitForIndexing(store);

                    var list = session.Advanced.MoreLikeThis <Post>(new MoreLikeThisQuery()
                    {
                        Query      = $"FROM INDEX '{new Posts_ByTitleAndContent().IndexName}'",
                        DocumentId = "posts/1",
                        MinimumDocumentFrequency = 1,
                        MinimumTermFrequency     = 0
                    });

                    Assert.Equal(3, list.Count);
                    Assert.Equal("doduck", list[0].Title);
                    Assert.Equal("prototype your idea", list[0].Desc);
                    Assert.Equal("doduck", list[1].Title);
                    Assert.Equal("love programming", list[1].Desc);
                    Assert.Equal("We do", list[2].Title);
                    Assert.Equal("prototype", list[2].Desc);
                }
            }
        }
Example #7
0
        public void CanUseMoreLikeThisWithTransformer()
        {
            using (var store = GetDocumentStore())
            {
                var index = new Posts_ByTitleAndContent();
                index.Execute(store);
                var transformer = new PostWithContentTransformer();
                transformer.Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Post {
                        Id = "posts/1", Title = "doduck", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/2", Title = "doduck", Desc = "prototype your idea"
                    });
                    session.Store(new Post {
                        Id = "posts/3", Title = "doduck", Desc = "love programming"
                    });
                    session.Store(new Post {
                        Id = "posts/4", Title = "We do", Desc = "prototype"
                    });
                    session.Store(new Post {
                        Id = "posts/5", Title = "We love", Desc = "challange"
                    });
                    session.Store(new Post {
                        Id = "posts/6", Title = "We love", Desc = "challange"
                    });
                    session.Store(new PostContent {
                        Id = "posts/1/content", Text = "transform1"
                    });
                    session.Store(new PostContent {
                        Id = "posts/2/content", Text = "transform2"
                    });
                    session.Store(new PostContent {
                        Id = "posts/3/content", Text = "transform3"
                    });
                    session.Store(new PostContent {
                        Id = "posts/4/content", Text = "transform4"
                    });
                    session.Store(new PostContent {
                        Id = "posts/5/content", Text = "transform5"
                    });
                    session.Store(new PostContent {
                        Id = "posts/6/content", Text = "transform6"
                    });
                    session.SaveChanges();

                    WaitForIndexing(store);

                    var list = session.Advanced.MoreLikeThis <PostWithContentTransformer.Result>(index.IndexName, transformer.TransformerName, new MoreLikeThisQuery
                    {
                        DocumentId = "posts/1",
                        MinimumDocumentFrequency = 1,
                        MinimumTermFrequency     = 0
                    });

                    Assert.Equal(3, list.Length);
                    Assert.Equal("doduck", list[0].Title);
                    Assert.Equal("prototype your idea", list[0].Desc);
                    Assert.Equal("transform2", list[0].Content);
                    Assert.Equal("doduck", list[1].Title);
                    Assert.Equal("love programming", list[1].Desc);
                    Assert.Equal("transform3", list[1].Content);
                    Assert.Equal("We do", list[2].Title);
                    Assert.Equal("prototype", list[2].Desc);
                    Assert.Equal("transform4", list[2].Content);
                }
            }
        }