Reputation: 17
Alfresco Version 3.3 -
I'm writing a JavaScript program in the Alfresco Repository to delete all the archived files (similar place to Windows' Recycle Bin). I've found that the Lucene search only returns 1000 nodes. So, my approach was to delete them and do the same search again to hopefully get another 1000 nodes and loop it until there were no search results. However, it returns the same 1000 results after I deleted from the first result. I've tried putting longer and longer pauses before doing the query again in case Lucene needed time to re-index after the deletes, even as long as five minutes. If I run the same script again it will successfully find 1000 existing nodes and delete them, but nothing past that.
My guess is that either there is a transaction linked to the entire JavaScript execution or that the search object caches the search and returns the same results when the same query is executed again.
Has anyone experienced this? Is there a way to get the search to work the second time in the same JavaScript execution?
Here's a snippet of trying to delete 2000 nodes:
var query = 'ASPECT:"sys:archived"';
var results = search.luceneSearch('archive://SpacesStore/',query);
for(var i=0;i<results.length;i++){
if(search.findNode(results[i].nodeRef)!=null){
results[i].remove();
}
}
results = search.luceneSearch('archive://SpacesStore/',query);
for(var i=0;i<results.length;i++){
if(search.findNode(results[i].nodeRef)!=null){
results[i].remove();
}
}
Upvotes: 0
Views: 816
Reputation: 415
You're running into how Alfresco deals with transactions when working in Javascript. It will bundle all of your changes that are done inside of your Javascript execution into a single transaction and until it exits, changes will not be committed and therefore the index will not be updated.
As far as I know, the only way to batch cleanup of the archive is to use something like Java, where you have explicit control of the transaction. This can be further complicated though if you are using something like SOLR because indexation is asynchronous. Since you said you're in 3.4 you must be using lucene, and this wouldn't be an issue, because the API wouldn't return control to you until the index changes are commited.
Two tips for trashcan management: apply the sys:temporary aspect if you're doing deletes programatically, so you can skip the trashcan step. There is also a wonderful AMP that's Java based which does trashcan cleanup in the background.
https://addons.alfresco.com/addons/trashcan-cleaner
It should work for your version.
Best regards, Matthew
Upvotes: 1