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