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

FTS extensions #1649

Merged
merged 29 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
edf4ff1
Fixes #386
MaceWindu Feb 17, 2019
831adac
Merge branch 'master' into issue_386
sdanyliv Feb 20, 2019
ccfd43a
Refactored FreeTextTableExpressionAttribute. Added possibly to genera…
sdanyliv Feb 20, 2019
d4bf48d
Improve custom query generation. Added a lot of ways to create dynami…
sdanyliv Feb 21, 2019
7a0970e
Merge remote-tracking branch 'origin/master' into issue_386
MaceWindu Mar 3, 2019
231d163
Merge branch 'master' into issue_386
MaceWindu Mar 10, 2019
96fa92b
fix tests build
MaceWindu Mar 10, 2019
40b4ac4
Merge branch 'master' into issue_386
MaceWindu Mar 10, 2019
4e37295
new FREETEXTTABLE extension, CONTAINSTABLE extension
MaceWindu Mar 16, 2019
fde7666
add more tests
MaceWindu Mar 16, 2019
62699a5
FREETEXT predicate
MaceWindu Mar 17, 2019
a59a491
disable FTS T4 generation by default
MaceWindu Mar 17, 2019
3033c6b
CONTAINS predicate (without PROPERTY support)
MaceWindu Mar 17, 2019
1697caf
CONTAINS(PROPERTY) extension and parameters inlining tests
MaceWindu Mar 17, 2019
1aa6115
SQLite FTS-related extensions part 1 (untested)
MaceWindu Mar 17, 2019
7cb5c9c
SQLite FTS3/4/5 support (except commands)
MaceWindu Mar 23, 2019
0c37411
SQLite FTS commands support
MaceWindu Mar 23, 2019
acd6cd6
mysql FTS extensions
MaceWindu Mar 24, 2019
47d23bd
move mysql extensions to Sql.Ext.MySql() endpoint
MaceWindu Mar 24, 2019
3456501
move sqlite extensions to sql.ext
MaceWindu Mar 24, 2019
3f224ee
move sqlserver extensions to sql.ext, fix northwind script
MaceWindu Mar 24, 2019
c1cca63
update fts obsolete messages
MaceWindu Mar 24, 2019
740b1ab
disable another test for netstandard1.6
MaceWindu Mar 24, 2019
f35fb8e
fix ITableMutable* implementation
MaceWindu Mar 24, 2019
d9b3efa
add tests failing over linqservice
MaceWindu Mar 24, 2019
191427a
hide new extensions for now
MaceWindu Mar 24, 2019
798669d
Merge branch 'master' into fts_extensions_v2
MaceWindu Apr 6, 2019
5ce931f
serialize SqlField.Table for remote service
MaceWindu Apr 6, 2019
d6b9722
move test attribute to proper method
MaceWindu Apr 6, 2019
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
11 changes: 9 additions & 2 deletions Data/Create Scripts/MySql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ GO

CREATE TABLE FullTextIndexTest (
id int UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
TestField TEXT(100),
FULLTEXT idx (TestField)
TestField1 TEXT(100),
TestField2 TEXT(200),
FULLTEXT idx_all (TestField1, TestField2),
FULLTEXT idx_field1 (TestField1),
FULLTEXT idx_field2 (TestField2)
)
-- SKIP MySql57 BEGIN
-- SKIP MariaDB BEGIN
Expand All @@ -470,3 +473,7 @@ CREATE TABLE FullTextIndexTest (
-- SKIP MySqlConnector END
;
GO
INSERT INTO FullTextIndexTest(TestField1, TestField2) VALUES('this is text1', 'this is text2');
INSERT INTO FullTextIndexTest(TestField1, TestField2) VALUES('looking for something?', 'found it!');
INSERT INTO FullTextIndexTest(TestField1, TestField2) VALUES('record not found', 'empty');
GO
Binary file modified Data/Create Scripts/Northwind.sql
Binary file not shown.
18 changes: 18 additions & 0 deletions Data/Create Scripts/SQLite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,21 @@ CREATE TABLE TEST_T4_CASING
snake_case INT NOT NULL,
camelCase INT NOT NULL
);

DROP TABLE IF EXISTS FTS3_TABLE;
CREATE VIRTUAL TABLE FTS3_TABLE USING FTS3(text1 TEXT, text2 TEXT);

DROP TABLE IF EXISTS FTS4_TABLE;
CREATE VIRTUAL TABLE FTS4_TABLE USING FTS4(text1 TEXT, text2 TEXT);

INSERT INTO FTS3_TABLE(text1, text2) VALUES('this is text1', 'this is text2');
INSERT INTO FTS3_TABLE(text1, text2) VALUES('looking for something?', 'found it!');
INSERT INTO FTS3_TABLE(text1, text2) VALUES('record not found', 'empty');
INSERT INTO FTS3_TABLE(text1, text2) VALUES('for snippet testing', 'During 30 Nov-1 Dec, 2-3oC drops. Cool in the upper portion, minimum temperature 14-16oC and cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6-12oC. Northeasterly winds 15-30 km/hr. After that, temperature increases. Northeasterly winds 15-30 km/hr.');

INSERT INTO FTS4_TABLE(text1, text2) VALUES('this is text1', 'this is text2');
INSERT INTO FTS4_TABLE(text1, text2) VALUES('looking for something?', 'found it!');
INSERT INTO FTS4_TABLE(text1, text2) VALUES('record not found', 'empty');
INSERT INTO FTS4_TABLE(text1, text2) VALUES('for snippet testing', 'During 30 Nov-1 Dec, 2-3oC drops. Cool in the upper portion, minimum temperature 14-16oC and cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6-12oC. Northeasterly winds 15-30 km/hr. After that, temperature increases. Northeasterly winds 15-30 km/hr.');


2 changes: 1 addition & 1 deletion Source/LinqToDB.Templates/LinqToDB.SqlServer.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
#>
<#+
bool GenerateSqlServerFreeText = true; // Defines whether to generate extensions for Free Text search, or not
bool GenerateSqlServerFreeText = false; // Defines whether to generate extensions for Free Text search, or not

void DoGenerateSqlServerFreeText()
{
Expand Down
5 changes: 4 additions & 1 deletion Source/LinqToDB.Templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ Func<string, bool, string> ConvertToCompilable = ConvertToCompilableDefault;

```cs
// Enables generation of extensions for Free Text Search
bool GenerateSqlServerFreeText = true;
//
// NOTE: this option is not needed anymore, as it generates old-style FTS support code and not recommeded for use
// use new extesions from this PR: https://github.com/linq2db/linq2db/pull/1649
bool GenerateSqlServerFreeText = false;
```

### PostgreSQL
Expand Down
119 changes: 119 additions & 0 deletions Source/LinqToDB/DataProvider/MySql/MySqlExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using LinqToDB.Expressions;
using LinqToDB.Linq;
using System;

namespace LinqToDB.DataProvider.MySql
{
public interface IMySqlExtensions
{
}

public static class MySqlExtensions
{
public static IMySqlExtensions MySql(this Sql.ISqlExtension ext) => null;

#region FTS
class ModifierBuilder : Sql.IExtensionCallBuilder
{
public void Build(Sql.ISqExtensionBuilder builder)
{
var modifier = builder.GetValue<MatchModifier>("modifier");

switch (modifier)
{
case MatchModifier.NaturalLanguage:
// default modifier, no need to add it to SQL
break;
case MatchModifier.Boolean:
builder.AddExpression("modifier", " IN BOOLEAN MODE");
break;
case MatchModifier.WithQueryExpansion:
// use short form without 'IN NATURAL LANGUAGE MODE' prefix
builder.AddExpression("modifier", " WITH QUERY EXPANSION");
break;
default:
throw new ArgumentOutOfRangeException("modifier");
}
}
}

/// <summary>
/// Search modifier for MATCH AGAINST full-text search predicate.
/// </summary>
public enum MatchModifier
{
/// <summary>
/// Applies 'IN NATURAL LANGUAGE MODE' (default value) search modifier.
/// </summary>
NaturalLanguage,
/// <summary>
/// Applies 'IN BOOLEAN MODE' (default value) search modifier.
/// </summary>
Boolean,
/// <summary>
/// Applies 'IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION'/'WITH QUERY EXPANSION' search modifier.
/// </summary>
WithQueryExpansion
}

/// <summary>
/// Applies full-text search condition using MATCH AGAINST predicate against specified full-text columns using default mode (IN NATURAL LANGUAGE MODE).
/// Example: MATCH(col1, col2) AGAINST('search query').
/// </summary>
/// <param name="ext">Extension point.</param>
/// <param name="search">Full-text search condition.</param>
/// <param name="columns">Full-text columns that should be queried.</param>
/// <returns>Returns <c>true</c> if full-text search found matching records.</returns>
[Sql.Extension("MATCH({columns, ', '}) AGAINST ({search})", IsPredicate = true, ServerSideOnly = true)]
public static bool Match(this IMySqlExtensions ext, [ExprParameter("search")] string search, [ExprParameter("columns")] params object[] columns)
Copy link
Member

Choose a reason for hiding this comment

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

There is no one place. But name of parameter is not required - original parameter name will be used

{
throw new LinqException($"'{nameof(Match)}' is server-side method.");
}

/// <summary>
/// Calculates relevance of full-text search for current record using MATCH AGAINST predicate against specified full-text columns using default mode (IN NATURAL LANGUAGE MODE).
/// Example: MATCH(col1, col2) AGAINST('search query').
/// </summary>
/// <param name="ext">Extension point.</param>
/// <param name="search">Full-text search condition.</param>
/// <param name="columns">Full-text columns that should be queried.</param>
/// <returns>Returns full-text search relevance value for current record.</returns>
[Sql.Extension("MATCH({columns, ', '}) AGAINST ({search})", ServerSideOnly = true)]
public static double MatchRelevance(this IMySqlExtensions ext, [ExprParameter("search")] string search, [ExprParameter("columns")] params object[] columns)
{
throw new LinqException($"'{nameof(MatchRelevance)}' is server-side method.");
}

/// <summary>
/// Applies full-text search condition using MATCH AGAINST predicate against specified full-text columns using specified search modifier.
/// Example: MATCH(col1, col2) AGAINST('search query' MODIFIER).
/// </summary>
/// <param name="ext">Extension point.</param>
/// <param name="modifier">Search modifier.</param>
/// <param name="search">Full-text search condition.</param>
/// <param name="columns">Full-text columns that should be queried.</param>
/// <returns>Returns <c>true</c> if full-text search found matching records.</returns>
[Sql.Extension("MATCH({columns, ', '}) AGAINST ({search}{modifier?})", IsPredicate = true, ServerSideOnly = true, BuilderType = typeof(ModifierBuilder))]
public static bool Match(this IMySqlExtensions ext, [SqlQueryDependent] MatchModifier modifier, [ExprParameter("search")] string search, [ExprParameter("columns")] params object[] columns)
{
throw new LinqException($"'{nameof(Match)}' is server-side method.");
}

/// <summary>
/// Calculates relevance of full-text search for current record using MATCH AGAINST predicate against specified full-text columns using specified search modifier.
/// Example: MATCH(col1, col2) AGAINST('search query' MODIFIER).
/// </summary>
/// <param name="ext">Extension point.</param>
/// <param name="modifier">Search modifier.</param>
/// <param name="search">Full-text search condition.</param>
/// <param name="columns">Full-text columns that should be queried.</param>
/// <returns>Returns full-text search relevance value for current record.</returns>
[Sql.Extension("MATCH({columns, ', '}) AGAINST ({search}{modifier?})", ServerSideOnly = true, BuilderType = typeof(ModifierBuilder))]
public static double MatchRelevance(this IMySqlExtensions ext, [SqlQueryDependent] MatchModifier modifier, [ExprParameter("search")] string search, [ExprParameter("columns")] params object[] columns)
{
throw new LinqException($"'{nameof(MatchRelevance)}' is server-side method.");
}

#endregion
}
}
Loading