cancel
Showing results for 
Search instead for 
Did you mean: 

Script to search and extract meta data

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi all

We are trying to create a script to get all the objects in a specific space (called "Aprobados") where the created or last modified date is today. And I also want to get all metadata from the searchrd objects.

Can anyone help me please?

Let me explain you the process I need to execute

1) Search for all the pdf documents of a given space called "Aprobados" which have been modified "today".
2) I need to create a txt file with all the metadata of all of those modified pdf documents stored in this space that matched this search criteria.
3) Place the txt file in a given space so another process can get it by FTP

This is the code I have written, however I am not very sure of the search funcion, as I need to search in the "Aprobados" space but also inside its child nodes recursively.

Could you please take a look to my code and let me know if you think it is ok?

I will really appreciate it.

Cheers!!

// We create the folder to place the txt file
var subir = space.childByNamePath("Subir Facturas");
var recoger = subir.childByNamePath("Recoger");


// If there is already a txt file we must delete it
for each (var doc in recoger.children) {
   if (doc.mimetype == "text/plain");
      doc.remove();
}


// Get the path to the parent space where to look for the files
var revision = space.childByNamePath("Revisar");
var aprobados = revision.childByNamePath("Aprobadas");
var today = new Date();
var ano = today.getFullYear();
var buscarAno = aprobados.childByNamePath(ano);


// Now we firstly create the txt file
//String fecha = today.getDate() + "-" + today.getMonth() +1 + "-" + today.getFullYear();
file = recoger.createFile("metadatos_facturas.txt");

// We run the search for all the pdf files that have been modified today in the
// space of the current year
var docs = search.xpathSearch([cm:modified]=today,buscarAno);

// For each doc found matching the search clause we must write their metadata in the
// txt file - one row with metadata per file found

for each (docs) {

   if (docs!=null && docs.mimetype == "application/pdf")
   {
      workingcopy=file.checkout();
      workingcopy.content = "|"+docs.name+"|"+docs.start_date+"|"+docs.Private_Id+"|=";
      file = workingcopy.checkin();
   }
}
2 REPLIES 2

romschn
Star Collaborator
Star Collaborator
You may use PATH query to search from a specific folder based on a modified date and mimetype.
http://wiki.alfresco.com/wiki/Search#Path_Queries

kaynezhang
World-Class Innovator
World-Class Innovator
You can use following code to search content by path+modified+mimetype.

search.luceneSearch('+@cm\:modified:[2013-09-20T00:00:00.000 TO 2013-11-20T23:59:59.999] AND  +PATH:"//app:company_home//cm:Aprobados//*" AND +@cm\:content.mimetype:text/plain');

Or you can use modified date+PATH+name phrase search