Skip to content

Commit 796da44

Browse files
committed
Add support for tsquery_phrase which was added in PostgreSQL 9.6
1 parent 11f1cbd commit 796da44

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/EntityFramework6.Npgsql/NpgsqlTextFunctions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,29 @@ public static string TsRewrite(string query, string target, string substitute)
370370
throw new NotSupportedException();
371371
}
372372

373+
/// <summary>
374+
/// Returns a tsquery that searches for a match to <paramref name="query1" /> followed by a match
375+
/// to <paramref name="query2" />.
376+
/// https://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY
377+
/// </summary>
378+
[DbFunction("Npgsql", "tsquery_phrase")]
379+
public static string TsQueryPhrase(string query1, string query2)
380+
{
381+
throw new NotSupportedException();
382+
}
383+
384+
/// <summary>
385+
/// Returns a tsquery that searches for a match to <paramref name="query1" /> followed by a match
386+
/// to <paramref name="query2" /> at a distance of <paramref name="distance" /> lexemes using
387+
/// the &lt;N&gt; tsquery operator
388+
/// https://www.postgresql.org/docs/current/static/textsearch-features.html#TEXTSEARCH-MANIPULATE-TSQUERY
389+
/// </summary>
390+
[DbFunction("Npgsql", "tsquery_phrase")]
391+
public static string TsQueryPhrase(string query1, string query2, int distance)
392+
{
393+
throw new NotSupportedException();
394+
}
395+
373396
/// <summary>
374397
/// Matches regular expression. Generates the "~" operator.
375398
/// http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

test/EntityFramework6.Npgsql.Tests/FullTextSearchTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,5 +602,31 @@ public void TsRewrite()
602602
Is.EqualTo(NpgsqlTsQuery.Parse("'b' & ( 'foo' | 'bar' )").ToString()));
603603
}
604604
}
605+
606+
[Test]
607+
public void TsQueryPhrase()
608+
{
609+
using (var context = new BloggingContext(ConnectionString))
610+
{
611+
context.Database.Log = Console.Out.WriteLine;
612+
613+
var blog1 = new Blog
614+
{
615+
Name = "_"
616+
};
617+
context.Blogs.Add(blog1);
618+
context.SaveChanges();
619+
620+
var newQuery = context
621+
.Blogs.Select(x => NpgsqlTextFunctions.TsQueryPhrase("b", "c"))
622+
.FirstOrDefault();
623+
Assert.That(newQuery, Is.EqualTo("'b' <-> 'c'"));
624+
625+
newQuery = context
626+
.Blogs.Select(x => NpgsqlTextFunctions.TsQueryPhrase("b", "c", 10))
627+
.FirstOrDefault();
628+
Assert.That(newQuery, Is.EqualTo("'b' <10> 'c'"));
629+
}
630+
}
605631
}
606632
}

0 commit comments

Comments
 (0)