Name-based autocategorization or tagging in Alfresco via content rule

I contributed in many threads in Alfresco Spanish Forum some time ago, and now I do it less frequently in English Forum. I read the autottager.js script and I found it very smart and simple. I prepared some new javascript code for name-based auto-tagging and categorizing under a defined space via content rule. For example, a file named "ECMReport.pdf" is automatically tagged as "ecm" and "report" when created or added, if these tags are previously used.


autotagger2.js

var docuname       = document.name;
var docuname_lower = docuname.toLowerCase();
var tagArray = [];
var taggable_array = ["PATH:\"/cm:categoryRoot/cm:taggable/*\""];
for each(var tag in taggable_array){
  var nodes = search.luceneSearch(tag);
  for each(var node in nodes) {
    var x = node.name.toLowerCase();
    var y = docuname_lower.indexOf(x);
    if (y >= 0) {
      tagArray.push(node.name);
    }
  }
}
document.addTags(tagArray);
document.save();

Consider now for example that you categorize your business documents with three main axis defined in categories (i.e: document type, product and technology). You can extend the main array with the three root paths for the correspoding vocabulary (known as parent category) and then adding tags or categories. Something like this:

autocategorizer.js

var docuname = document.name;
var docuname_lower = docuname.toLowerCase();
var catArray = [];
var category_array = ["PATH:\"cm:generalclassifiable/cm:DocumentType/*\"","PATH:\"cm:generalclassifiable/cm:Product/*\"","PATH:\"cm:generalclassifiable/cm:Technology/*\""];
for each(var cat in category_array){
  var nodes = search.luceneSearch(cat);
  for each(var node in nodes) {
    var x = node.name.toLowerCase();
    var y = docuname_lower.indexOf(x);
    if (y >= 0) {
      catArray.push(node);
    }
  }
}
document.addAspect("cm:generalclassifiable");
document.properties["cm:categories"] = catArray;
document.save();


Tested in Alfresco 4.2.c CE

00

Más entradas de blog

1 comentario(s)

JN
Juan Pablo Naranjo Hace 6 meses

Buen día Cesar, estoy utilizando tu código para el etiquetado, pero ahora tengo otra duda, como creo una regla, utilizando como criterio información dentro de un pdf? por ejemplo una factura y quiero utilizar la información de cliente dentro del documento....

00