MySQL FullText Search with Sequelize

I want to implement MySQL full-text search with sequelize. Version of "sequelize": "^ 3.23.6". I tried to research this, but could not find = documentation that describes how to implement this. Here is a link saying that FullText is supported by sequelize: https://github.com/sequelize/sequelize/issues/2979

But there is no exact documentation on how to do this, and how to do a full text search query with sequelize.

Any recommendations on links will be helpful.

Thank!

+4
source share
2 answers

Sequelize . FULLTEXT , . , MATCH (column) AGAINST (value).

:

module.exports = (sequelize, DataTypes) => {
  const Book = sequelize.define('Book', {
    title: DataTypes.STRING,
    description: DataTypes.TEXT,
    isActive: DataTypes.BOOLEAN
  }, {
    indexes: [
      // add a FULLTEXT index
      { type: 'FULLTEXT', name: 'text_idx', fields: ['description'] }
    ]
  });

  return Book;
};

:

const against = 'more or less';

models.Book.find({
  where: ['isActive = 1 AND MATCH (description) AGAINST(?)', [against]]
}).then((result) => {
  console.log(result.title);
});

MySQL, , , .. MySQL (https://dev.mysql.com/worklog/task/?id=2428), , .

MySQL, Sphinx. .

+4

Sequelize, :

Unhandled rejection Error: Support for literal replacements in the where object has been removed.

,

Payments.findAll({
  where: Sequelize.literal('MATCH (SomeField) AGAINST (:name)'),
  replacements: {
    name: 'Alex'
  }
});

:

Payments.findAll({
  where: [
    { State: 'Paid' },
    Sequelize.literal('MATCH (SomeField) AGAINST (:name)')
  ],
  replacements: {
    name: 'Alex'
  }
});
0

Source: https://habr.com/ru/post/1652332/


All Articles