Skip to content

Added the ability to full-text search for selected fields #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-server",
"version": "0.14.0",
"version": "0.14.1",
"description": "Serves JSON files through REST routes.",
"main": "./lib/server/index.js",
"bin": "./lib/cli/bin.js",
Expand Down
6 changes: 6 additions & 0 deletions src/server/router/plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = (db, name, opts) => {
// Remove q, _start, _end, ... from req.query to avoid filtering using those
// parameters
let q = req.query.q
const attr = req.query.attr
let _start = req.query._start
let _end = req.query._end
let _page = req.query._page
Expand All @@ -64,6 +65,7 @@ module.exports = (db, name, opts) => {
let _embed = req.query._embed
let _expand = req.query._expand
delete req.query.q
delete req.query.attr
delete req.query._start
delete req.query._end
delete req.query._sort
Expand Down Expand Up @@ -101,6 +103,10 @@ module.exports = (db, name, opts) => {

chain = chain.filter(obj => {
for (let key in obj) {
if (attr && attr.indexOf(key) === -1) {
// ignore key(field)
continue
}
const value = obj[key]
if (db._.deepQuery(value, q)) {
return true
Expand Down