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
Another observation:
{"query":{"query":"name:*"}} --> totalItems retrieved
{"query":{"query":"TYPE:\"cm:content\""}} --> totalItems not retrieved
{"query":{"query":"name:* and TYPE:\"cm:content\""}} --> totalItems retrieved
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...
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.