Skip to content

Fulltext index on a model property is not migrated to the datasource #466

@Kenny477

Description

@Kenny477

Steps to reproduce

  1. Add/modify a property on a model to enable fulltext search
@property({
    type: 'string',
    required: true,
    mysql: {
      index: {
        kind: 'FULLTEXT'
      },
      dataType: 'LONGTEXT'
    },
 })
 content: string;

Note: allowExtendedOperators has been enabled on this model.

@model({
  settings: {
    allowExtendedOperators: true
  }
})
  1. Migrate schema to datasource
    Include app.migrateSchema() in src/index.ts to migrate the schema when running the app.
  await app.boot();
  await app.migrateSchema();
  await app.start();
  1. Run app and test a query.

Current Behavior

Fulltext search query results in error
Query format:

where: {
      title: { match: "test" },
},

Resulting error:
Request GET /posts?filter=%7B%22where%22:%7B%22title%22:%7B%22match%22:%22test%22%7D%7D%7D failed with status code 500. Error: ER_FT_MATCHING_KEY_NOT_FOUND: Can't find FULLTEXT index matching the column list

Checking the MySQL database table in the Docker container:

Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
title varchar(512) NO NULL
author varchar(512) NO NULL
content longtext NO NULL
datetime datetime NO NULL

Checking indices using

SELECT TABLE_NAME, INDEX_TYPE FROM information_schema.STATISTICS
TABLE_NAME INDEX_TYPE
Post BTREE

Expected Behavior

That the title field is a fulltext index and I can perform fulltext search on the field using the match operator when querying a field.
I can fix this manually by running the SQL command:

ALTER TABLE Post ADD FULLTEXT(title);

Causing the table to be...

Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
title varchar(512) NO MUL NULL
author varchar(512) NO NULL
content longtext NO NULL
datetime datetime NO NULL

And indices to be...

TABLE_NAME INDEX_TYPE
Post BTREE
Post FULLTEXT

And then the fulltext query works on my frontend when fetching /posts with the previously mentioned params.

Link to reproduction sandbox

Additional information

darwin arm64 16.15.1

├── @loopback/boot@5.0.1
├── @loopback/booter-lb3app@4.0.1
├── @loopback/core@4.0.1
├── @loopback/repository@5.0.1
├── @loopback/rest-explorer@5.0.1
├── @loopback/rest@12.0.1
├── @loopback/service-proxy@5.0.1
├── loopback-boot@3.3.1
├── loopback-component-explorer@6.5.1
├── loopback-component-storage@3.7.0
├── loopback-connector-mysql@6.1.0
├── loopback-connector-sendgrid@2.2.4
├── loopback@3.28.0

Related Issues

See Reporting Issues for more tips on writing good issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions