mysql - Performing FULLTEXT search after JOIN operation in sequelize -
i have 2 tables category , events , want perform fulltext search on columns events.name,description,society , category.name after performing join operation on both tables in sequelize.
modals have been defined follows:
events.js
(function () { 'use strict'; module.exports = function(sequelize, datatypes) { var events = sequelize.define("events", { //must same table name id: { type: datatypes.integer, primarykey: true, autoincrement: true // automatically gets converted serial postgres }, name: { type: datatypes.string, notnull: true }, description: { type: datatypes.string, notnull: true }, venue: { type: datatypes.string, notnull: true }, starttime: { type: datatypes.string, notnull: true }, endtime: { type: datatypes.string, notnull: true }, startdate: { type: datatypes.string, notnull: true }, enddate: { type: datatypes.string, notnull: true }, currentround: { type: datatypes.string, notnull: true }, society: { type: datatypes.string, notnull: true }, categoryid: { type: datatypes.integer, notnull: true }, maxcontestants: { type: datatypes.integer, notnull: true }, status: { type: datatypes.string, notnull: true }, pdf: { type: datatypes.string, notnull: true } }, { timestamps: false, tablename: 'events', freezetablename: true }, { indexes: [ { type: 'fulltext', fields: 'name' } ] },{ classmethods: { associate: function(models) { events.belongsto(models.category); } } }); return events; }; }());
category.js
module.exports = function(sequelize, datatypes) { var category = sequelize.define("category", { id: { type: datatypes.integer, primarykey: true, autoincrement: true // automatically gets converted serial postgres }, name: datatypes.string }, { timestamps: false, tablename: 'category', freezetablename: true },{ indexes: [ { type: 'fulltext', fields: ['name'] } ] }, { classmethods: { associate: function(models) { category.hasmany(models.events); } } }); return category; };
query performing :
model.events.findall({ include: [{ model: model.category }],having: ['match(events.name,description,society,category.name) against(?)', query] }).then(function(data) { console.log(json.stringify(data)); r.status = statuscodes.success; r.data = json.stringify(data); return res.end(r.tostring()); }).catch(function(err){ console.log(err); r.status = statuscodes.server_error; r.data = err; return res.end(r.tostring()); });
errors getting :
- fulltext index not exits.
- incorrect arguments match.
- i not sure if foreign key has been created.
please me out correcting query.
Comments
Post a Comment