cancel
Showing results for 
Search instead for 
Did you mean: 

totalItems missing in pagination search response

atef-zayati
Champ in-the-making
Champ in-the-making

Hello Alfresco Community,

 

I'm using alfresco-client-sdk. While doing some search queries (via Search API: search (POST)), I noticed that totalItems property is "sometimes" missing in pagination search response.

Here is a body request where totalItems property is present in the response (see response below) :

{
   "query": {
       "language": "afts",
       "userQuery": null,
       "query": "TYPE:'cm:folder'"
   },
   "paging": {
       "maxItems": 10,
       "skipCount": 0
   },
   "include": ["properties", "aspectNames"],
   "fields": null,
   "sort": [
        {
       "type": "FIELD",
       "field": "TYPE",
       "ascending": "false"
   }],
   "templates": null,
   "defaults": null,
   "filterQueries": null,
   "facetQueries": null,
   "facetFields": null,
   "spellcheck": null,
   "scope": null,
   "limits": null,
   "highlight": null,
   "pivots": null
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Response:

{
    "list": {
        "pagination": {
            "count": 10,
            "hasMoreItems": true,
            "totalItems": 217,
            "skipCount": 0,
            "maxItems": 10
        },
        "context": {},
        "entries": [
            ...
        ]
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Here is another body request where totalItems is not present in the response (see response below):

{
   "query": {
       "language": "afts",
       "userQuery": null,
       "query": "TYPE:'cm:folder'"
   },
   "paging": {
       "maxItems": 10,
       "skipCount": 0
   },
   "include": ["properties", "aspectNames"],
   "fields": null,
   "sort": [
        {
       "type": "FIELD",
       "field": "cm:created",
       "ascending": "false"
   }],
   "templates": null,
   "defaults": null,
   "filterQueries": null,
   "facetQueries": null,
   "facetFields": null,
   "spellcheck": null,
   "scope": null,
   "limits": null,
   "highlight": null,
   "pivots": null
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Response:

{
    "list": {
        "pagination": {
            "count": 10,
            "hasMoreItems": true,
            "skipCount": 0,
            "maxItems": 10
        },
        "entries": [
            ...
        ]
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Note: The only difference between the two body requests is sort field: TYPE vs. cm:created.

Is this the expected behaviour? Thanks.

UPDATE:

A quick and dirty workaround to always get totalItems property in pagination search response is to append a dummy type* field sub-query (-TYPE:'dummyType').

* this type as its name suggests it is dummy!

Body request:

{
   "query": {
       "language": "afts",
       "userQuery": null,
       "query": "TYPE:'cm:folder' AND -TYPE:'dummyType'"
   },
   "paging": {
       "maxItems": 10,
       "skipCount": 0
   },
   "include": ["properties", "aspectNames"],
   "fields": null,
   "sort": [
        {
       "type": "FIELD",
       "field": "TYPE",
       "ascending": "false"
   }],
   "templates": null,
   "defaults": null,
   "filterQueries": null,
   "facetQueries": null,
   "facetFields": null,
   "spellcheck": null,
   "scope": null,
   "limits": null,
   "highlight": null,
   "pivots": null
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Response:

{
    "list": {
        "pagination": {
            "count": 10,
            "hasMoreItems": true,
            "totalItems": 217,
            "skipCount": 0,
            "maxItems": 10
        },
        "entries": [
            ...
        ]
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Body request:

{
   "query": {
       "language": "afts",
       "userQuery": null,
       "query": "TYPE:'cm:folder' AND -TYPE:'dummyType'"
   },
   "paging": {
       "maxItems": 10,
       "skipCount": 0
   },
   "include": ["properties", "aspectNames"],
   "fields": null,
   "sort": [
        {
       "type": "FIELD",
       "field": "cm:created",
       "ascending": "false"
   }],
   "templates": null,
   "defaults": null,
   "filterQueries": null,
   "facetQueries": null,
   "facetFields": null,
   "spellcheck": null,
   "scope": null,
   "limits": null,
   "highlight": null,
   "pivots": null
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Response:

{
    "list": {
        "pagination": {
            "count": 10,
            "hasMoreItems": true,
            "totalItems": 217,
            "skipCount": 0,
            "maxItems": 10
        },
        "entries": [
            ...
        ]
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Regards,

Atef ZAYATI

2 REPLIES 2

janardhanc
Champ on-the-rise
Champ on-the-rise

Another observation:  

{"query":{"query":"name:*"}} --> totalItems retrieved

{"query":{"query":"TYPE:\"cm:content\""}} --> totalItems not retrieved

{"query":{"query":"name:* and TYPE:\"cm:content\""}} --> totalItems retrieved

mehe
Elite Collaborator
Elite Collaborator

This could be related to how the query is executed internally. Only solr queries will return „totalItems“, Maybe the Search Service is so intelligent, that it optimises queries to be executed as DB queries...