Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DbFunctions extensions for websearch_to_tsquery (#629) #753

Merged
merged 5 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions QueryBaseline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4032,3 +4032,19 @@



System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) :
AssertSql(
@"SELECT websearch_to_tsquery('a OR b')
FROM ""Customers"" AS c
LIMIT 1");



System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) :
AssertSql(
@"SELECT websearch_to_tsquery('english', 'a OR b')
FROM ""Customers"" AS c
LIMIT 1");



Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,109 @@ public static class NpgsqlFullTextSearchDbFunctionsExtensions
{
/// <summary>
/// Convert <paramref name="lexemes" /> to a tsvector.
/// https://www.postgresql.org/docs/current/static/functions-textsearch.html
/// </summary>
/// <remarks>
/// https://www.postgresql.org/docs/current/static/functions-textsearch.html
/// </remarks>
public static NpgsqlTsVector ArrayToTsVector(this DbFunctions _, string[] lexemes) =>
throw new NotSupportedException();

/// <summary>
/// Reduce <paramref name="document" /> to tsvector.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
/// </remarks>
public static NpgsqlTsVector ToTsVector(this DbFunctions _, string document) =>
throw new NotSupportedException();

/// <summary>
/// Reduce <paramref name="document" /> to tsvector using the text search configuration specified
/// by <paramref name="config" />.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
/// </remarks>
public static NpgsqlTsVector ToTsVector(this DbFunctions _, string config, string document) =>
throw new NotSupportedException();

/// <summary>
/// Produce tsquery from <paramref name="query" /> ignoring punctuation.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string query) =>
throw new NotSupportedException();

/// <summary>
/// Produce tsquery from <paramref name="query" /> ignoring punctuation and using the text search
/// configuration specified by <paramref name="config" />.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery PlainToTsQuery(this DbFunctions _, string config, string query) =>
throw new NotSupportedException();

/// <summary>
/// Produce tsquery that searches for a phrase from <paramref name="query" /> ignoring punctuation.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string query) =>
throw new NotSupportedException();

/// <summary>
/// Produce tsquery that searches for a phrase from <paramref name="query" /> ignoring punctuation
/// and using the text search configuration specified by <paramref name="config" />.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery PhraseToTsQuery(this DbFunctions _, string config, string query) =>
throw new NotSupportedException();

/// <summary>
/// Normalize words in <paramref name="query" /> and convert to tsquery. If your input
/// contains punctuation that should not be treated as text search operators, use
/// <see cref="PlainToTsQuery(DbFunctions, string)" /> instead.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string query) => throw new NotSupportedException();

/// <summary>
/// Normalize words in <paramref name="query" /> and convert to tsquery using the text search
/// configuration specified by <paramref name="config" />. If your input contains punctuation
/// that should not be treated as text search operators, use
/// <see cref="PlainToTsQuery(DbFunctions, string, string)" /> instead.
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery ToTsQuery(this DbFunctions _, string config, string query) =>
throw new NotSupportedException();

/// <summary>
/// Convert <paramref name="query" /> tsquery using the simplified websearch syntax.
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string query) =>
throw new NotSupportedException();

/// <summary>
/// Convert <paramref name="query" /> tsquery using the simplified websearch syntax and the text
/// search configuration specified by <paramref name="config" />.
/// </summary>
/// <remarks>
/// http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
/// </remarks>
public static NpgsqlTsQuery WebSearchToTsQuery(this DbFunctions _, string config, string query) =>
throw new NotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class NpgsqlFullTextSearchMethodTranslator : IMethodCallTranslator
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.ToTsVector)] = "to_tsvector",
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.PlainToTsQuery)] = "plainto_tsquery",
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.PhraseToTsQuery)] = "phraseto_tsquery",
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.ToTsQuery)] = "to_tsquery"
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.ToTsQuery)] = "to_tsquery",
[nameof(NpgsqlFullTextSearchDbFunctionsExtensions.WebSearchToTsQuery)] = "websearch_to_tsquery"
};

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ SELECT to_tsquery(CAST(@__config_1 AS regconfig), 'a & b')
LIMIT 1");
}

[Fact]
public void WebSearchToTsQuery()
{
using (var context = CreateContext())
{
var tsquery = context.Customers.Select(c => EF.Functions.WebSearchToTsQuery("a OR b")).First();
Assert.NotNull(tsquery);
}

AssertSql(
@"SELECT websearch_to_tsquery('a OR b')
FROM ""Customers"" AS c
LIMIT 1");
}

[Fact]
public void WebSearchToTsQuery_With_Config()
{
using (var context = CreateContext())
{
var tsquery = context.Customers.Select(c => EF.Functions.WebSearchToTsQuery("english", "a OR b")).First();
Assert.NotNull(tsquery);
}

AssertSql(
@"SELECT websearch_to_tsquery('english', 'a OR b')
FROM ""Customers"" AS c
LIMIT 1");
}

[Fact]
public void TsQueryAnd()
{
Expand Down