Ejemplo n.º 1
0
        public void SetWeight()
        {
            using (var context = new BloggingContext(ConnectionString))
            {
                context.Database.Log = Console.Out.WriteLine;

                var blog1 = new Blog
                {
                    Name = "The quick brown fox jumps over the lazy dog."
                };
                context.Blogs.Add(blog1);

                var post1 = new Post
                {
                    Blog    = blog1,
                    Title   = "Lorem ipsum",
                    Content = "Dolor sit amet",
                    Rating  = 5
                };
                context.Posts.Add(post1);

                var post2 = new Post
                {
                    Blog    = blog1,
                    Title   = "consectetur adipiscing elit",
                    Content = "Sed sed rhoncus",
                    Rating  = 4
                };
                context.Posts.Add(post2);
                context.SaveChanges();

                var foundPost = context.Posts.FirstOrDefault(
                    x => NpgsqlTextFunctions.Match(
                        NpgsqlTextFunctions.SetWeight(
                            NpgsqlTextFunctions.ToTsVector(x.Title ?? string.Empty),
                            NpgsqlWeightLabel.D)
                        + NpgsqlTextFunctions.SetWeight(
                            NpgsqlTextFunctions.ToTsVector(x.Content ?? string.Empty),
                            NpgsqlWeightLabel.C),
                        NpgsqlTextFunctions.PlainToTsQuery("dolor")));

                Assert.That(foundPost != null);
                Assert.That(foundPost.Title, Is.EqualTo(post1.Title));
            }
        }