Recherche erronée sur un champ

cancel
Showing results for 
Search instead for 
Did you mean: 
dranakan
Active Member

Re: Recherche erronée sur un champ

J'ai créé un webscript pour rechercher les documents perdus et les réparer.
Je le mets ici si un malheureux rencontre ce genre de problème (il faudra toutefois l'adapter en fonction de son modèle).

/**
* Search Lost document (exist in Alfresco but not found with Lucene).
*
* If message " Transactional update cache
* 'org.alfresco.nodeOwnerTransactionalCache' is full (20000).", increase maxCacheSize value
* of cache-context.xml.
*
* Support : https://forums.alfresco.com/fr/viewtopic.php?f=8&t=5189
*
* Sample Recursion : http://aboutalfresco.blogspot.ch/2009/12/javascript-api-in-alfresco.html
* @since 21.06.2012
*
*
*/
// *****************
// Arguments comming
// *****************
var repair = args.repair;

// Information about webscript
var nameWebscript = "Webscript SearchLostDocument";
var arguments = "Arguments : ";

// Init
var directoryPath="/ERP/Storage/";
var countDoc=0;
var countIC=0;
var countID=0;
var countFA=0;
var countCA=0;
var countPC=0;
var countPD=0;
var notFound=0;

// Constants
var TYPE_SG_DOC="sg:doc";
var TYPE_SGF_INVOICECREDITOR="sgf:invoiceCreditor";
var TYPE_SGF_INVOICEDEBTOR="sgf:invoiceDebtor";
var TYPE_SGF_FINANCIALACCOUNT="sgf:financialAccount";
var TYPE_SGF_CONDENSEDACCOUNT="sgf:condensedAccount";
var TYPE_SGF_PAYMENTCREDITOR="sgf:paymentCreditor";
var TYPE_SGF_PAYMENTDEBTOR="sgf:paymentDebtor";

var response = "";
script: {

   // Show arguments
   for (arg in args) {
      arguments += arg + "=" + args[arg] + ";";
   }
   logger.log(nameWebscript + ". " + arguments);

   searchLostDocuments();
   
   displayCount();
   
   logger.log("End "+nameWebscript);
}

function searchLostDocuments() {
   logger.log("searchLostDocuments");
   var log;
   var directory = companyhome.childByNamePath(directoryPath);
   if (directory == null){
      logger.debug("Directory not found : "+directoryPath);
      return;
   }
   logger.log("Search in : "+directoryPath);
   for (i = 0; i < directory.children.length; i++) {
      var childName = directory.children[i];
      if (childName != null) {
         if (childName.isContainer) {
            recursion(childName);
         } else {
            analyseDocument(childName);
         }
      }
   }
}
/**
* Search files and folder in all sub-directories
*
* @param node
*/
function recursion(node) {
   if (node != null) {
      for ( var j = 0; j < node.children.length; j++) {
         if (node.children[j] != null) {
            if (node.children[j].isContainer) {
               recursion(node.children[j]);
            } else {
               analyseDocument(node.children[j]);
            }
         }
      }
   }
}
/**
* Get details about current node.
*
* @param node
*/
function analyseDocument(node) {
   log = node.properties.name;
   var firmNb = node.properties["sg:firmNb"];
   var documentNb = node.properties["sg:documentNb"];
   var isAnnexe = node.hasAspect("sg:annexe");
   var isDeletable = node.hasAspect("sg:deletable");
   var created = node.properties["cm:created"];
   var modified = node.properties["cm:modified"];
   var type = node.typeShort
   log = log + " " + type + " " + firmNb + " " + documentNb+" " +created+" "+modified +" "+node.displayPath ;
   
   if (firmNb != null && !isAnnexe && !isDeletable) {
      countDocuments(type);
      var isFound = searchDocuments(type, firmNb, documentNb);
      if (isFound) {
         // logger.log("ok");
      } else {
         notFound++;
         logger.log("Not found " + log);
         // Repair document
         if (repair != null && repair == "true"){
            repairDocument(node);
         }
      }
   }
}

/**
* Search document using LuceneSearch
*
* @param docType
* @param firmNb
* @param documentNb
* @returns {Boolean}
*/
function searchDocuments(docType, firmNb, documentNb) {
   var type = "EXACTTYPE";
   var queryString = "(" + type + ":\"" + docType + "\")";
   queryString += " AND (@sg\\:documentNb:" + documentNb + ")";
   queryString += " AND (@sg\\:firmNb:" + firmNb + ")";
   queryString += " AND NOT (@sg\\:toDelete:true)";
   queryString += " AND NOT (@sg\\:isAnnexe:true)";
   // logger.log(queryString);

   var nodes = search.luceneSearch(queryString);

   var node = nodes[0];
   if (node != null && node.isDocument) {
      return true;
   } else {
      return false;
   }
}
/**
* Count the documents by types
* @param type
* @returns
*/
function countDocuments(type){
   if (type==TYPE_SG_DOC){
      countDoc=countDoc+1;
   }else if (type==TYPE_SGF_INVOICECREDITOR){
      countIC++;
   }else if (type==TYPE_SGF_INVOICEDEBTOR){
      countID++;
   }else if (type==TYPE_SGF_FINANCIALACCOUNT){
      countFA++;
   }else if (type==TYPE_SGF_CONDENSEDACCOUNT){
      countCA++;
   }else if (type==TYPE_SGF_PAYMENTCREDITOR){
      countPC++;
   }else if (type==TYPE_SGF_PAYMENTDEBTOR){
      countPD++;
   }else{
      logger.debug("Type not count : "+type);
   }
}
/**
* Give the total of all documents found (having firmNb, not annexe and not deleted).
*/
function displayCount(){
   logger.debug("total documents : ");
   logger.debug(TYPE_SG_DOC+countDoc);
   logger.debug(TYPE_SGF_INVOICECREDITOR+" "+countIC);
   logger.debug(TYPE_SGF_INVOICEDEBTOR+" "+countID);
   logger.debug(TYPE_SGF_FINANCIALACCOUNT+" "+countFA);
   logger.debug(TYPE_SGF_CONDENSEDACCOUNT+" "+countCA);
   logger.debug(TYPE_SGF_PAYMENTCREDITOR+" "+countPC);
   logger.debug(TYPE_SGF_PAYMENTDEBTOR+" "+countPD);
   logger.debug("Not found "+notFound);
}
/**
* The document has some properties but are not inside lucenece due to a bug ?
* To repair it's just need to save node.
* @param node
*/
function repairDocument(node){
   logger.debug("Repair by saving node: "+node.properties.name);
   node.save();
}
Sur tous les documents (>23'000), 89 sont perdus. Ils sont du même type (invoiceDebtor). Tous les fichiers perdus ont été ajoutés sur deux jours précis et en version 3.4D.
Je ne trouve rien de spécial dans les logs à ces dates… je vais continuer à chercher et vérifier sur les autres serveurs.