You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entity-framework/core/providers/sql-server/full-text-search.md
+74-4Lines changed: 74 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,12 +13,82 @@ EF Core's SQL Server provider supports both full-text search *predicates* (for f
13
13
14
14
## Setting up full-text search
15
15
16
-
Before using full-text search, you must:
16
+
Before using full-text search, you must create a [full-text catalog](/sql/t-sql/statements/create-fulltext-catalog-transact-sql) on your database, and a [full-text index](/sql/t-sql/statements/create-fulltext-index-transact-sql) on the columns you want to search.
17
17
18
-
1.**Create a full-text catalog** on your database
19
-
2.**Create a full-text index** on the columns you want to search
18
+
### [EF Core 11+](#tab/ef-core-11)
20
19
21
-
This setup is done at the SQL Server level and is outside the scope of EF Core. For more information, see the [SQL Server full-text search documentation](/sql/relational-databases/search/get-started-with-full-text-search).
20
+
> [!NOTE]
21
+
> Full-text catalog and index management in migrations was introduced in EF Core 11.
22
+
23
+
You can configure full-text catalogs and indexes directly in your EF model. When you add a [migration](xref:core/managing-schemas/migrations/index), EF will generate the appropriate SQL to create (or alter) the catalog and index for you.
24
+
25
+
First, define a full-text catalog on the model, then configure a full-text index on your entity type:
The `HasKeyIndex()` method specifies the unique, non-nullable, single-column index used as the full-text key for the table (typically the primary key index). `OnCatalog()` assigns the full-text index to a specific catalog.
40
+
41
+
You can also configure multiple columns and additional options such as per-column languages and change tracking:
The full-text catalog can also be configured as the default catalog, and with accent sensitivity:
54
+
55
+
```csharp
56
+
modelBuilder.HasFullTextCatalog("ftCatalog")
57
+
.IsDefault()
58
+
.IsAccentSensitive(false);
59
+
```
60
+
61
+
### [Older versions](#tab/older-versions)
62
+
63
+
On older versions of EF Core, you can set up full-text search by adding raw SQL to a migration. Add an empty migration and then edit it to include the full-text catalog and index creation SQL:
Copy file name to clipboardExpand all lines: entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -260,9 +260,34 @@ This translates to the SQL Server [`VECTOR_SEARCH()`](/sql/t-sql/functions/vecto
260
260
261
261
For more information, see the [full documentation on vector search](xref:core/providers/sql-server/vector-search).
262
262
263
-
<aname="sqlserver-full-text-tvf"></a>
263
+
<aname="sqlserver-full-text"></a>
264
264
265
-
### Full-text search table-valued functions
265
+
### Full-text search improvements
266
+
267
+
#### Full-text search catalog and index creation
268
+
269
+
SQL Server's [full-text search](/sql/relational-databases/search/full-text-search) requires a full-text catalog and index to be set up on your database before you can use it. EF 11 now allows configuring full-text catalogs and indexes in your model, so that [EF migrations](xref:core/managing-schemas/migrations/index) can automatically create and manage them for you:
270
+
271
+
```csharp
272
+
// In your OnModelCreating:
273
+
modelBuilder.HasFullTextCatalog("ftCatalog");
274
+
275
+
modelBuilder.Entity<Blog>()
276
+
.HasFullTextIndex(b=>b.FullName)
277
+
.HasKeyIndex("PK_Blogs")
278
+
.OnCatalog("ftCatalog");
279
+
```
280
+
281
+
This generates the following SQL in a migration:
282
+
283
+
```sql
284
+
CREATE FULLTEXT CATALOG [ftCatalog];
285
+
CREATE FULLTEXT INDEX ON [Blogs]([FullName]) KEY INDEX [PK_Blogs] ON [ftCatalog];
286
+
```
287
+
288
+
Previously, full-text catalog and index creation had to be managed manually by adding SQL to migrations. For full details on setting up full-text catalogs and indexes, see the [full-text search documentation](xref:core/providers/sql-server/full-text-search#setting-up-full-text-search).
289
+
290
+
#### Full-text search table-valued functions
266
291
267
292
EF Core has long provided support for SQL Server's full-text search predicates `FREETEXT()` and `CONTAINS()`, via `EF.Functions.FreeText()` and `EF.Functions.Contains()`. These predicates can be used in LINQ `Where()` clauses to filter results based on search criteria.
0 commit comments