V8-archive: Only under certain conditions can filter_count be returned.

Created on 2 Jul 2019  ·  3Comments  ·  Source: directus/v8-archive

Bug Report

Sometimes you can return filter_count, sometimes you can't.

Steps to Reproduce

1、
let searchkey = ""
let categories = ""

this.client.getItems("blog",{
    meta:"total_count,result_count,filter_count",
    sort: "-created_on",
    filter:{
        "category.id": {
            in:  category 
         },
         title:{
             logical: "or",
             contains: searchkey 
         },
         description:{
             logical: "or",
             contains: searchkey 
         },
     },
     limit: 10,
     fields: "*.*",
     status: "published"
})

At this point, because searchkey and categories are empty, no filter is passed, and filter_count cannot be returned.

image

image

2、
let searchkey = ""
let categories = "7,13,15,8,14,32"

this.client.getItems("blog",{
    meta:"total_count,result_count,filter_count",
    sort: "-created_on",
    filter:{
        "category.id": {
            in:  category 
         },
         title:{
             logical: "or",
             contains: searchkey 
         },
         description:{
             logical: "or",
             contains: searchkey 
         },
     },
     limit: 10,
     fields: "*.*",
     status: "published"
})

At this point, because the search key is empty and the categories have a value, the filter [category. id] [in]: 7, 13, 15, 8, 14, 32 is passed, and the filter_count is returned correctly.

image

image

3、
let searchkey = ""
let categories = "28,29,30"

this.client.getItems("blog",{
    meta:"total_count,result_count,filter_count",
    sort: "-created_on",
    filter:{
        "category.id": {
            in:  category 
         },
         title:{
             logical: "or",
             contains: searchkey 
         },
         description:{
             logical: "or",
             contains: searchkey 
         },
     },
     limit: 10,
     fields: "*.*",
     status: "published"
})

The filter [category. id] [in]: 7, 13, 15, 8, 14, 32 is passed, and no data is returned after filtering, so filter_count cannot be returned at this time.
image

image

Expected Behavior

Actual Behavior

Other Context & Screenshots

Technical Details

  • Device: [eg: Desktop]
  • OS: [Windows 10.1809]
  • Web Server: [Nginx:1.17.0]
  • PHP Version: [7.3.6]
  • Database: [5.7.26]
  • API Version: [2.2.1]
  • APP Version: [7.6.1]
  • Install Method: [cloned master branch]
bug

Most helpful comment

Fixed in #1088

All 3 comments

I'm doing this now, but it's not a good solution.

let searchkey = "", categories = "", page = 1, pagesize = 10, sort = '-created_on'
this.client.getItems("blog",{
    meta:"total_count,result_count,filter_count",
    sort:  sort,
    filter:{
        "category.id": {
            in:  category 
         },
         title:{
             logical: "or",
             contains: searchkey 
         },
         description:{
             logical: "or",
             contains: searchkey 
         },
     },
     offset: page * pagesize - pagesize,
     limit: pagesize,
     fields: "*.*",
     status: "published"
}).then((res) => {
    let filter_total = 0
    if(res.meta.result_count === 0){
        filter_total = 0
    }else if(res.meta.result_count > 0){
        if(res.meta.filter_count){
            filter_total = res.meta.filter_count
        }else {
            filter_total = res.meta.total_count
        }
    }
   this.total = filter_total 
})

Fixed in #1088

Fixed in #1088

Thank you very much :+1::+1::+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdwmhcc picture cdwmhcc  ·  3Comments

gitlabisbetterthangithub picture gitlabisbetterthangithub  ·  3Comments

cdwmhcc picture cdwmhcc  ·  3Comments

metalmarco picture metalmarco  ·  3Comments

maettyhawk picture maettyhawk  ·  3Comments