module.exports = function (models) {
    const {
        Photo,
        User
    } = models;

    return {
        searchPhotos(pattern) {
            return new Promise((resolve, reject) => {
                Photo.find({
                        'title': new RegExp(pattern, 'i')
                    },
                    (err, photos) => {

                        if (err) {
                            reject(err);
                        }

                        resolve(photos);
                    })
            });
        },
        searchUsers(pattern) {
            return new Promise((resolve, reject) => {
                User.find({
                        'username': new RegExp(pattern, 'i')
                    },
                    (err, users) => {

                        if (err) {
                            reject(err);
                        }

                        resolve(users);
                    })
            });
        }
    };
};
module.exports = function (models) {
    const {
        Photo,
        User
    } = models;

    return {
        searchPhotos(pattern) {
            var regex = new RegExp(pattern, 'i');

            return new Promise((resolve, reject) => {
                Photo.find({
                        $or: [{
                            'title': regex
                        }, {
                            'description': regex
                        }]
                    },
                    (err, photos) => {

                        if (err) {
                            reject(err);
                        }

                        resolve(photos);
                    })
            });
        },
        searchUsers(pattern) {
            var regex = new RegExp(pattern, 'i');

            return new Promise((resolve, reject) => {
                User.find({
                        $or: [{
                            'username': regex
                        }, {
                            'description': regex
                        }, {
                            'name': regex
                        }]
                    },
                    (err, users) => {

                        if (err) {
                            reject(err);
                        }

                        resolve(users);
                    })
            });
        }
    };
};
Add more field to search