Ramesh
Ramesh

Reputation: 151

Alfresco : How to search a mimeType of file using 'lucensearch'

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.

Upvotes: 0

Views: 1009

Answers (2)

Heiko Robert
Heiko Robert

Reputation: 2707

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";
   }

Upvotes: 1

Vikash Patel
Vikash Patel

Reputation: 1348

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

Upvotes: 1

Related Questions