Alfresco content services has supported structural queries for a long time. You can find documents by how they are filed in a folder structure, how they are categorised and how they have been tagged. You can add new types of category, add new categories of your own to existing hierarchies, decorate the base category object using aspects and these categories are all discoverable. Underneath the hood, categories and tags are implemented the same way. Tags are a flat category. Categories are treated as an additional path to a document in a category hierarchy. A document is linked to a category by setting a property to the node ref of one or more categories.
In Alfresco Search Services we added support to role-up and facet on some things that are effectively encoded into paths - the SITE and TAG fields. Via the 5.2 public API for search, there is now support for more advanced path based drill down, navigation and roll-up.
Just to be clear, TAG and SITE roll ups are available in Share; path and taxonomy faceting is not. You can roll up the node ref in the category property in Share but this is probably not what you want.
This post is about the public API for search.
So what's new?
There are 6 new bits of information in the index and fields that can be used in query, filter queries and facets. These are:
TAG - used to index all the lowercase tags that have been assigned to a node.
SITE - used to index the site short name for a node, in any site. Remember a node can be in more than one site, although this is unusual. If a node is not in any site it is assigned a value of "_REPOSITORY_" to reflect this.
NPATH - the "name path" to a node. See the example below for how it is indexed.
PNAME - the path from the node up through its parents - again, see the example below.
APATH - as NPATH but using UUID - the UUID can be used as the key for internationalisation (SOLR 6 only).
ANAME - as PNAME but using UUID - the UUID can be used as the key for internationalisation (SOLR 6 only).
The search public API in Alfresco Content Services 5.2 exposes filter queries and faceting by field with prefix restrictions. These, in combination with the additional data, supports new ways to drill-in and roll up data.
Example of what is in the index
Lets say we have uploaded the file CMIS-v1.1-cs01.pdf into the site woof we would have .....
It is great to do this in a filter query in the search API as filter queries are cached, reused and warmed.
Similarly for TAGs
SITE and TAG also support faceting.
The fun starts with drill down. NPATH can be used for navigation. You can get top level names by asking for a facet on NPATH starting with the prefix "0/". You can then remove the "0/" from the facets returned to get the names of the top level things. Here is the JSON body of the request:
The response contains, amongst many others, "0/categories". So lets drill into that another layer. We need the prefix "1/categories" and we filter stuff out based on where we want to drill-in "0/categories" - as below.
This gives us "1/categories/General" and "1/categories/Tags". So lets skip a step or two and count the stuff in the General/Languages category ... I have not added the prefix here to show how you can get counts for all nodes in the hierarchy.
In a clean repository, this will show the structure of Language and show how many sub-categories exist.
With UUIDs it is pretty much the same.
PNAME helps with some odd use cases. "I am sure I put it in a folder called .....". It gives faceting based on ancestry. It can highlight common structures for storing data or departure from such a structure: things in odd locations. If you have used folders to encode state you can roll up on this state. (Yes you should probably have used metadata or workflow).
PNAME can also be used to count direct members of a category - rather than everything in the category and below. So NPATH can count everything below and PNAME everything direct. The design uses the same prefix for each. So to get the next category layer with total and direct counts you would use something like:
SITE and TAG provide easy query time access to concepts in Share. NPATH and PNAME support queries that will progressively drill into a folder or category structure and support faceting to count the documents and folders in each part of the next layer. APATH and ANAME do the same job with a UUID key to aid internationalisation and a bridge to other public APIs where UUID is ubiquitous.
Clade is a term from biological classification that defines a grouping with a common ancestor.
The public API can not currently have a field facet on the same field with different configuration e.g. NPATH with a prefix and NPATH without a prefix. You have to choose one or the other.
We used something inspired by PathHierarchyTokenizer to support this functionality. In order to use doc values we parse internally and use a multi-valued string field. We are pre-analysing as doc values and tokenisation do not play well.
If you want to exclude the category nodes themselves from the counts add a filter query
Don't forget the workhorse support for structure provided by querying PATH, ANCESTOR and PARENT. You can also use PARENT and ANCESTOR for faceting on NodeRefs.
In SOLR 6, fields of type d:category are now indexed "as is" and you can facet on the NodeRef.