panosc-eu / search-api

PaN search api for WP3 and WP4
BSD 2-Clause "Simplified" License
4 stars 4 forks source link

Count of items returned for a specific query #46

Open jirzi0 opened 4 years ago

jirzi0 commented 4 years ago

Is your feature request related to a problem? Please describe. Implementing pagination using skip & limit, only total resource count is available though (to my knowlage at least). Describe the solution you'd like It would feel more graceful on the frontend side if a total of items returned by specific query was also provided. Describe alternatives you've considered It's all right, I just check for an empty array to come and stop there...

zjttoefs commented 4 years ago

@henrikjohansson712 is that not part of the default loopback functionality? If yes, we should add this to the documentation.

henrikjohansson712 commented 4 years ago

The count endpoints have support for the "where" part of the filter, e.g, if you send a request to GET /documents with the filter:

{
  "where": {
    "type": "publication"
  },
  "include": [
    {
      "relation": "datasets",
      "scope": {
        "include": [
          {
            "relation": "techniques",
            "scope": {
              "where": {
                "name": "small-angle neutron scattering"
              }
            }
          }
        ]
      }
    }
  ]
}

then the GET /documents/count query filter would be:

{
  "type":"publication"
}

which would give you all documents of type publication.

So the functionality of the count endpoints is limited, at least when it comes to queries where you filter on related models.

The count endpoints documentation states that they only accept a where query, but maybe it needs some clarification?

jirzi0 commented 3 years ago

Bumping this issue. Thanks for the clarification. Obviously it would be great if the count also took account for the include key query stuff as at is quite a limitation.