我正在尝试使用Adonis和PostgreSQL进行全文搜索,但是,我遇到了一些问题。
这就是我所拥有的代码
SearchController
'use strict'
const Post = use('App/Models/Post')
const Database = use('Database')
class SearchController {
async index ({ view, request, response }) {
let posts = await Post.query()
.forIndex()
.where('title', 'LIKE', request.input('q'))
.orWhere('body', 'LIKE', request.input('q'))
.paginate(request.input('page', 1), 10)
return view.render('index', {
posts
})
}
}
module.exports = SearchController
例如,我希望能够搜索Vue
或Rails
并显示相关帖子,因为用户当然不知道完整的帖子标题,所以我希望用户成为能够搜索任何内容,以及单词是否需要显示在帖子标题或正文中。
这里是GIF,用于说明我的意思和遇到的问题