Beispiel #1
0
        public void TsRankCd()
        {
            using (var context = new BloggingContext(ConnectionString))
            {
                context.Database.Log = Console.Out.WriteLine;

                var blog1 = new Blog
                {
                    Name = "cooky cookie piano pianos"
                };
                context.Blogs.Add(blog1);
                context.SaveChanges();

                var rank = context
                           .Blogs
                           .Select(
                    x => NpgsqlTextFunctions.TsRankCd(
                        NpgsqlTextFunctions.ToTsVector(x.Name),
                        NpgsqlTextFunctions.PlainToTsQuery("cookie")))
                           .FirstOrDefault();
                Assert.That(rank, Is.GreaterThan(0));

                rank = context
                       .Blogs
                       .Select(
                    x => NpgsqlTextFunctions.TsRankCd(
                        NpgsqlTextFunctions.ToTsVector(x.Name),
                        NpgsqlTextFunctions.PlainToTsQuery("cookie"),
                        NpgsqlRankingNormalization.DivideByLength
                        | NpgsqlRankingNormalization.DivideByUniqueWordCount))
                       .FirstOrDefault();
                Assert.That(rank, Is.GreaterThan(0));

                rank = context
                       .Blogs
                       .Select(
                    x => NpgsqlTextFunctions.TsRankCd(
                        0.1f, 0.2f, 0.4f, 1.0f,
                        NpgsqlTextFunctions.ToTsVector(x.Name),
                        NpgsqlTextFunctions.PlainToTsQuery("cookie")))
                       .FirstOrDefault();
                Assert.That(rank, Is.GreaterThan(0));

                rank = context
                       .Blogs
                       .Select(
                    x => NpgsqlTextFunctions.TsRankCd(
                        0.1f, 0.2f, 0.4f, 1.0f,
                        NpgsqlTextFunctions.ToTsVector(x.Name),
                        NpgsqlTextFunctions.PlainToTsQuery("cookie"),
                        NpgsqlRankingNormalization.DivideByLength
                        | NpgsqlRankingNormalization.DivideByUniqueWordCount))
                       .FirstOrDefault();
                Assert.That(rank, Is.GreaterThan(0));
            }
        }