Document Filtering Best Practice

Hello, I want to get advice on filtering documents. We have a component that receives articles (different types of articles) and it is possible to filter (by type, creation date (custom field), date from, date to, + some more custom fields). Now it's all organized as follows. Array document.type for each type we make a separate request using predicates ( while ordering is carried out according to the custom field the date of creation of the document, the first page gets the correct result, but the second one gets an unordered sorting (this is understandable because according to fact, each type of document has its own request) and this needs to be corrected the main question is whether it is possible to use prismic api to perform an adequate selection from different document types and also perform filtering, or in this case use $prismic.predicates.any('document.type ', allNeedType 0) and already on the client to do filtering with sorting ?

Hello @goldstandartdev

Sorry for the delayed response.

You can use any predicate to filter documents. You need to pass the value of document types in an array. For e.g.:
prismic.predicate.any( path, values )
prismic.predicate.any('document.type', ['product', 'blog-post'])

The above query filter product and bog-post documents.

To sort, you need to use the orderings params. The orderings property defines how to order your search results. It accepts an ordering object or an array of ordering objects. The ordering object has a field (which accepts a path) and an optional direction property (which can be either desc or asc and defaults to asc ).
For eg: * The orderings param determines that results will be descending by their first publication date.

orderings: {
    field: 'document.first_publication_date',
    direction: 'desc'

Learn about more in the technical reference articles:
Rest API technical reference
Prismic Client technical reference.

Let me know if you have any further questions.