Searching Text Content - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

You POST a search query to the following URL: http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search

The POST body for a basic query looks like:

{
  "query": {
    "query": "dog"
  }
}

This basic query searches only the text content for the files in the repository. Let’s say I got a file with the word dog in the text and another file with the word dog in the cm:title property. If I search with the following query I should only get one response:

$ curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' --header 'Authorization: Basic VElDS0VUXzA4ZWI3ZTJlMmMxNzk2NGNhNTFmMGYzMzE4NmNjMmZjOWQ1NmQ1OTM=' -d '{
  "query": {
    "query": "dog"
  }
}
' 'http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   711  100   671  100    40  23137   1379 --:--:-- --:--:-- --:--:-- 24517
{
  "list": {
    "pagination": {
      "count": 1,
      "hasMoreItems": false,
      "totalItems": 1,
      "skipCount": 0,
      "maxItems": 100
    },
    "context": {},
    "entries": [
      {
        "entry": {
          "isFile": true,
          "createdByUser": {
            "id": "admin",
            "displayName": "Administrator"
          },
          "modifiedAt": "2019-09-16T08:31:22.936+0000",
          "nodeType": "cm:content",
          "content": {
            "mimeType": "text/plain",
            "mimeTypeName": "Plain Text",
            "sizeInBytes": 48,
            "encoding": "ISO-8859-1"
          },
          "parentId": "5a858591-752f-49d0-b686-e2e1a830ea8d",
          "createdAt": "2019-09-05T08:52:16.785+0000",
          "isFolder": false,
          "search": {
            "score": 3.5323858
          },
          "modifiedByUser": {
            "id": "admin",
            "displayName": "Administrator"
          },
          "name": "somefile.txt",
          "location": "nodes",
          "id": "8f1c3f76-0eaf-452a-be66-c5405af67dbc"
        }
      }
    ]
  }
}

The response contains only minimal metadata for each entry. Use the include and fields parameters to return more metadata in the response.

The results should look familiar, for the most part they are the same as the results from /queries and from /nodes/{id}/children.

There are a couple of differences though, the search API returns two additional properties, search and location. The search property adds extra context for the individual result, in this case, the score. Explaining the full details is beyond the scope of this article but it is possible to search across “live” nodes, deleted nodes and versioned nodes, the location property shows from which area the result came from. By default only “live” nodes are included.

The example above used the default search language afts (Alfresco Full Text Search), however, cmis and lucene are also supported.