cancel
Showing results for 
Search instead for 
Did you mean: 

lucene search for one file

mangar
Star Contributor
Star Contributor
I am trying to add/update a file in Alfresco.  In order to do this I need to see if the file is already in alfresco so I can choose either CMLCreate vs CMLUpdate. I have been through the wiki tutorial, and i try this search:

+PATH:"/app:company_home/cmSmiley Surprisedperations/cm:Reports/cm:myReport"+@cm\:name:"myReport.xls"
(yes, the directory is called myReport, and in that space, the file myReport.xls resides.)

it returns nothing, but it's there. I can see it.

I know the path and the name of the file, what is the correct lucene search to return a ResultSet for that file?

Alternatively, is there any code example that would do this:

ParentReference contentReference = new ParentReference(storeRef,null,path,ASSOC_CONTAINS,ASSOC_CONTAINS);
CMLCreate createDoc = new CMLCreate("ref1", contentReference, null, null, null, Constants.createQNameString(NAMESPACE, "report"), contentProps);
cml.setCreate(new CMLCreate[]{createDoc});
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
Reference newContentNode = result[0].getDestination();
ContentFormat  format = new ContentFormat("application/excel", "UTF-8");
WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);

without that annoying  "Duplicate child name not allowed"
2 REPLIES 2

openpj
Elite Collaborator
Elite Collaborator
You have to add for your PATH token this string "/*" to allow Lucene to search for all the child nodes in that space:

String luceneQuery = "+PATH:\"/app:company_home/cm:Operations/cm:Reports/cm:myReport/*\" +@cm\\:name:\"myReport.xls\"";
You have to encode all the space names in the ISO 9075 format, this because Alfresco store paths in that format.
Try to encode the Lucene query in this way:

String luceneQuery = "+PATH:\"/app:company_home/cm:"+ISO9075.encode("Operations")+"/cm:"+ISO9075.encode("Reports")+"/cm:"+ISO9075.encode("myReport")+"/*\" +@cm\\:name:\"myReport.xls\"";
Hope this helps.

mangar
Star Contributor
Star Contributor
Thank you  so much!  Without that * I was looking for a specific directory with a filename, never going to happen.

Everything works great, thank you!