Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to create full-text Index Pomelo.EFCore.MySql

Shulou Source: shulou.com Published: 2022-06-01 18:04:23 09月23日 Update

This article introduces the knowledge of "how to create a full-text index Pomelo.EFCore.MySql". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Background

Full-text index: MySQL full-text retrieval uses the correlation between query keywords and query column content for retrieval, and full-text index can be used to improve the speed of matching.

Pomelo.EntityFrameworkCore.MySql: a third-party MySQL EntityFrameworkCore driver that is open source in GitHub. Its performance, features and downloads all exceed the official version provided by Oracle. QQ group 522943763.

Use

Full-text indexing is supported on July 28th, and Pomelo.EntityFrameworkCore.MySql 2.0.0-preview3-10049 or later is required.

Create a TestModel class

Class TestModel {

Public Guid Id {get; set;}

Public string Text {get; set;}}

Create the TestContext class and use Fluent API to add indexes and full-text indexes to the Text fields in TestModel

Class TestContext: DbContext {

Public DbSet TestModels {get; set;}

Protected override void OnModelCreating (ModelBuilder modelBuilder) {base.OnModelCreating (modelBuilder); modelBuilder.Entity (e = > {e.HasIndex (x = > x.Text). IsFullText (); / / add full-text index});}

Protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) {base.OnConfiguring (optionsBuilder); optionsBuilder.UseMySql ("server=localhost;uid=root;pwd=123456;database=fttest");}}

That is, use .HasIndex (). IsFullText () on the field where you want to add a full-text index.

Next, call DbContext in the Main method to test:

Class Program {

Static void Main (string [] args) {

Var db = new TestContext (); db.Database.EnsureCreated (); Console.WriteLine ("Hello World!");}}

In Navicat, we can see that the full-text index was created successfully:

Matters needing attention

.IsFullText () cannot be used with .IsUnique ().

Users of the InnoDB engine require MySQL 5.6 or later to use this feature

This is the end of "how to create a full-text Index Pomelo.EFCore.MySql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Full-text index content version next functions fields more knowledge query retrieval practical successful learning between events full-text retrieval keywords keywords at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Microsoft Huawei MySQL