/** * PrefixController * * @description :: Server-side logic for managing prefixes * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers */ module.exports = { search: function(req, res) { var word = req.param('query'), prefixQuery = Prefix.find(); if (word != undefined) prefixQuery = Prefix.find({ where: { or: [ {english: {contains: word}}, {thai: {contains: word}}, ] }, sort: { thai: 1, english: 1 } }); prefixQuery.limit(10).exec(function(err, items) { if (err) { res.send(400); } else { res.send(items); } }); } };