Skip to content

Implementation of FreeText translation for SqlServer - #10480

Merged
smitpatel merged 2 commits into
devfrom
smit/prcleanup
Dec 5, 2017
Merged

smitpatel merged 2 commits into
devfrom
smit/prcleanup

Conversation

@smitpatel

Copy link
Copy Markdown
Contributor

Adding some cleanup.

{
/// <summary>
/// <para>
/// A method to call T-SQL FREEETEXT method. It is used to perform full text searches on full text indexed columns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divega @anpete @ajcvickers - Need doc comments for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A DbFunction method stub that can be used in LINQ queries to target the SQL Server FREETEXT store function.
Remarks: This DbFunction method has no in-memory implementation and may throw when the querying is executing in memory. This can happen if the query contains one or more expressions that could not be translated to the store.

/// <param name="languageTerm">Language ID from sys.syslanguages table</param>
public static bool FreeText(
[CanBeNull] this DbFunctions _,
[NotNull] string columnName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"propertyName"


return Equals(methodCallExpression.Method, _methodInfo)
? new SqlFunctionExpression(
"FREETEXT",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY this string?

{
get
{
var isFullTextInstalled = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no "is"

isFullTextInstalled = result == 1;
}

sqlConnection.Close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant.


private static bool FreeTextCore(string columnName, string freeText, int? languageTerm)
{
throw new NotImplementedException();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an error message and probably InvalidOperation

@smitpatel

Copy link
Copy Markdown
Contributor Author

Updated.

@smitpatel
smitpatel requested review from anpete and maumar December 5, 2017 05:29
@smitpatel

Copy link
Copy Markdown
Contributor Author

Ping!

<value>The specified table '{table}' is not valid. Specify tables using the format '[schema].[table]'.</value>
</data>
<data name="FreeTextFunctionOnClient" xml:space="preserve">
<value>FreeText function is not supported when query is being executed in memory.</value>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The 'FreeText' method is not supported because the query has switched to client-evaluation. Inspect the log to determine which query expressions are triggering client-evaluation."

/// </para>
/// </summary>
/// <remarks>
/// This DbFunction method has no in-memory implementation and may throw when the querying is executing in memory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and will throw if the query switches to client-evaluation."

/// This can happen if the query contains one or more expressions that could not be translated to the store.
/// </remarks>
/// <param name="_">DbFunctions instance</param>
/// <param name="propertyName">The column on which the search will be performed</param>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

column -> property

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Period at end of param sentences.

/// <param name="_">DbFunctions instance</param>
/// <param name="propertyName">The column on which the search will be performed</param>
/// <param name="freeText">The text that is to be searched</param>
/// <param name="languageTerm">Language ID from sys.syslanguages table</param>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Language ID from the sys.syslanguages table

/// </remarks>
/// <param name="_">DbFunctions instance</param>
/// <param name="propertyName">The column on which the search will be performed</param>
/// <param name="freeText">The text that is to be searched</param>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The text that will be searched for in the property."


public static bool IsTeamCity => Environment.GetEnvironmentVariable("TEAMCITY_VERSION") != null;

public static bool SupportsFullTextSearch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsFullTextSearchSupported :trollface:

@elepner elepner left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question regarding SqlServerQuerySqlGenerator

/// </returns>
protected override Expression VisitBinary(BinaryExpression binaryExpression)
{
if (binaryExpression.Left is SqlFunctionExpression sqlFunctionExpression

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please look at the issue #11316? Don't you think it's better to add more generic if statement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants