0

I have written the following javascirpt code snipped in Alfresco CMS to find and print names of files whose mimetype is "image/png" into a book.txt file. This code creates the book.txt file successfully, but it is blank; it does not write any name of files whose mimeType is "image/png", though there are more than 100 png images files with mimetype 'image/png':

var logFile = space.childByNamePath("book.txt");
if (logFile == null)
{
   logFile = space.createFile("book.txt");
}
if (logFile != null)
{
  var docs = search.luceneSearch("content.mimetype:'image/png'");
   var log = "";
   for (var i=0; i<docs.length; i++)
   {
      log += "Name: " + docs[i].name + "\tPath: " + docs[i].displayPath + "\r\n";
   }
   logFile.content += log;
}

Any suggestion what is the wrong with this code. I have put this code inside "company home>Data Dictionary>script" and I am running this script from "company home>Sites" which is root of all contents. Hence it is the root of all folders which contains images files. Please advise.

Ramesh
  • 131
  • 1
  • 1
  • 10

2 Answers2

1

please try using this may help you

 search.luceneSearch('+PATH:"/app:company_home//*" +@\\{http\\://www.alfresco.org/model/content/1.0\\}content.mimetype:text/plain');

content.mimetype:text/plain

please specify your mimetype here

you can find more information from documentation

Vikash Patel
  • 1,328
  • 9
  • 28
  • Thanks Vikash , your search query runs perfectly and gives me the accurate search result - not matter from which folder I run this script . Thanks again !! – Ramesh Jun 07 '18 at 13:58
1

The namespace ("cm:") is missing in your query string. Try this:

  var docs = search.luceneSearch("@cm\\:content.mimetype:\"image/png\"");
   var log = "";
   for (var i=0; i<docs.length; i++)
   {
      log += "Name: " + docs[i].name + "\tPath: " + docs[i].displayPath + "\r\n";
   }
Heiko Robert
  • 2,488
  • 11
  • 12
  • 1
    you should check your query using node browser (/share/page/console/admin-console/node-browser) or java script console. – Heiko Robert Jun 07 '18 at 12:34
  • Hello Heiko, Your script is also perfectly fine as it returns the exact result. thank you for your help !! – Ramesh Jun 07 '18 at 15:01