mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
Fix search in content-manager
This commit is contained in:
parent
04d4b60056
commit
1d09999586
@ -210,7 +210,11 @@ module.exports = function createQueryBuilder({ model, modelKey, strapi }) {
|
||||
}
|
||||
|
||||
function countSearch(params) {
|
||||
return model.query(qb => buildSearchQuery(qb, model, params)).count();
|
||||
return model
|
||||
.query(qb => {
|
||||
buildSearchQuery(qb, model, params);
|
||||
})
|
||||
.count();
|
||||
}
|
||||
|
||||
async function createGroups(entry, values, { transacting }) {
|
||||
@ -497,13 +501,13 @@ const buildSearchQuery = (qb, model, params) => {
|
||||
|
||||
if (!_.isNaN(_.toNumber(query))) {
|
||||
searchInt.forEach(attribute => {
|
||||
qb.orWhereRaw(attribute, _.toNumber(query));
|
||||
qb.orWhere(attribute, _.toNumber(query));
|
||||
});
|
||||
}
|
||||
|
||||
if (query === 'true' || query === 'false') {
|
||||
searchBool.forEach(attribute => {
|
||||
qb.orWhereRaw(attribute, _.toNumber(query === 'true'));
|
||||
qb.orWhere(attribute, _.toNumber(query === 'true'));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ module.exports = {
|
||||
strapi.plugins['content-manager'].services['contentmanager'];
|
||||
|
||||
let entities = [];
|
||||
if (!_.isEmpty(ctx.request.query._q)) {
|
||||
if (_.has(ctx.request.query, '_q')) {
|
||||
entities = await contentManagerService.search(
|
||||
ctx.params,
|
||||
ctx.request.query
|
||||
@ -51,7 +51,7 @@ module.exports = {
|
||||
strapi.plugins['content-manager'].services['contentmanager'];
|
||||
|
||||
let count;
|
||||
if (!_.isEmpty(ctx.request.query._q)) {
|
||||
if (_.has(ctx.request.query, '_q')) {
|
||||
count = await contentManagerService.countSearch(
|
||||
ctx.params,
|
||||
ctx.request.query
|
||||
|
||||
@ -127,23 +127,15 @@ module.exports = {
|
||||
},
|
||||
|
||||
search(params, query) {
|
||||
const { limit, skip, sort, source, _q, populate = [] } = query; // eslint-disable-line no-unused-vars
|
||||
const filters = strapi.utils.models.convertParams(params.model, query);
|
||||
const { model } = params;
|
||||
const { source } = query;
|
||||
|
||||
// Find entries using `queries` system
|
||||
return strapi.query(params.model, source).search(
|
||||
{
|
||||
limit: limit || filters.limit,
|
||||
skip: skip || filters.start || 0,
|
||||
sort: sort || filters.sort,
|
||||
search: _q,
|
||||
},
|
||||
populate
|
||||
);
|
||||
return strapi.query(model, source).search(query);
|
||||
},
|
||||
|
||||
countSearch(params, query) {
|
||||
const { model } = params;
|
||||
const { source, _q } = query;
|
||||
return strapi.query(params.model, source).countSearch({ search: _q });
|
||||
return strapi.query(model, source).countSearch({ _q });
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user