RE: totalItems with pagination and filtering

On 14 Nov 2015 at 20:59, Tomasz Pluskiewicz wrote:
> On 2015-11-14 20:09, Maik Riechert wrote:
>>> I would turn this around. Where does /users go when the @id is
>>> /users?name=Bob? How about sth like that
>>> 
>>> GET /users?name=Bob&p=1
>>> {
>>>    "@id": "/users?name=Bob",
>>>    "partOf": "/users"
>>>    "@type": "Collection",
>>>    "member": [ ...10 Bob items... ],
>>>    "totalItems": 50,
>>>    "view": { .. the page links ... }
>>> }

I think the main to keep in mind thing here is that there's only one collection resource and we are trying to describe various views of that resource. As such, we could model it as follows

  {
    "@id": "/users",
    "@type": "Collection",
    "member": [ ...10 Bob items... ],
    "totalItems": 10000,
    "view": [
      {
        "@id": "/users?name=Bob",
        "@type": "PartialCollectionView",
        "totalItems": 50
      },
      {
        "@id": "/users?name=Bob&p=1",
        "@type": "PartialCollectionView",
        "first": "/users?name=Bob&p=1",
        "next": "/users?name=Bob&p=2",
        "last": "/users?name=Bob&p=5"
      }
    ]
  }

I don't think we should support a hierarchy of view.

The tricky aspect here though is that /users?name=Bob isn't an accessible view, which makes it a bit awkward. Or how do you folks think about that?

An alternative would be to allow to attach totalItems to PartialCollectionView in case it differs from the underlying collection:

  {
    "@id": "/users",
    "@type": "Collection",
    "member": [ ...10 Bob items... ],
    "totalItems": 10000,
    "view": 
      "@id": "/users?name=Bob&p=1",
      "@type": "PartialCollectionView",
      "totalItems": 50,
      "first": "/users?name=Bob&p=1",
      "next": "/users?name=Bob&p=2",
      "last": "/users?name=Bob&p=5"
    }
  }

... which looks much simpler but may be conceptually ambiguous.


>>> My idea would be to always use the parametrized @id (so that you can
>>> bookmark it) and add a link to the unfiltered collection, here
>>> "partOf" as an example.
>> 
>> After I sent the email I had the same thoughts and I agree, it makes
>> more sense to browse through the filtered collection, especially because
>> totalItems works then. I also thought about how to link to the
>> unfiltered collection, that's tricky.

I think both are valid but the main question is we want to treat the filtered view as a separate collection or not.

 
> To complete this train of thought, I would point out that this is how
> this works in HTML. You normally see a summary similar to "displaying 10
> out of 50 items" and that total number usually (always?) means the
> number of filtered results.

Right, you typically get the total number of items of the filtered view but not the total number of items of the complete collection.


>> To help think about it, let's imagine we subclass Collection and use
>> something like FilteredCollection which could then include some custom
>> predicates like "appliedFilter": {"name": "Bob"}, and the link to the
>> unfiltered collection which should be unambiguous. 

How would a FilteredCollection differ from a PartialCollectionView?


> Your idea seems sound. I'd have to defer that to other on this list for
> detailed discussion. My thought is that the "appliedFilter" is
> essentially an instance of a IriTemplate with variables filled in. I
> would model it with the IriTemplate in mind.

+1


Cheers,
Markus


--
Markus Lanthaler
@markuslanthaler

Received on Thursday, 26 November 2015 15:31:27 UTC