cancel
Showing results for 
Search instead for 
Did you mean: 

Lucene category search and isCategory return false

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi all,
I'm looking for search a category and if it doesn't exist I create it.
My code is this:

function searchRootCategory(categoryName) {
      logger.log("searchRootCategory, entrato");
      var categoryToReturn = null;
      var luceneQuery = "+TYPE:\"cm:category\" +@cm\\:name:\""+categoryName+"\"";
      logger.log("searchRootCategory, eseguo la query ["+luceneQuery+"]");
      var categories = search.luceneSearch(luceneQuery);
      if (categories.length > 0) {
         categoryToReturn = categories[0];
         logger.log("searchRootCategory, category " + categoryName + " trovata");
      } else {
         logger.log("searchRootCategory, category " + categoryName + " NON trovata");
      }
      logger.log("searchRootCategory, uscito");
      return categoryToReturn;
   }

function searchSubCategory(rootCategoryName, subCategoryName) {
      logger.log("searchSubCategory, entrato");
      var subCategoryToReturn = null;
      var rootCategoryNameToSearch = search.ISO9075Encode(rootCategoryName);
      var luceneQuery = "+PATH:\"/cm:generalclassifiable/cm:"+rootCategoryNameToSearch+"/*\" +@cm\\:name:\""+subCategoryName+"\"";
      logger.log("searchSubCategory, eseguo la query ["+luceneQuery+"]");
      var subCategories = search.luceneSearch(luceneQuery);
      if (subCategories.length > 0) {
         subCategoryToReturn = subCategories[0];
         logger.log("searchSubCategory, category " + subCategoryName + " trovata nella root category "+rootCategoryName);
      } else {
         logger.log("searchSubCategory, category " + subCategoryName + " NON trovata nella root category "+rootCategoryName);
      }
      logger.log("searchSubCategory, uscito");
      return subCategoryToReturn;
   }

function createSubCategory(rootCategoryName, subCategoryName) {
      logger.log("createSubCategory, entrato");
      var subCategoryToReturn = null;
      var rootCategory = searchRootCategory(rootCategoryName);
      if (rootCategory != null){
         var subCategoryFound = searchSubCategory(subCategoryName, rootCategory);
         if (subCategoryFound == null){
            subCategoryToReturn = rootCategory.createSubCategory(subCategoryName);
         } else {
            subCategoryToReturn = subCategoryFound;
         }
      } else {
         logger.log("createSubCategory, NON posso creare la subCategory ["+subCategoryName+"] perchè la root category ["+rootCategoryName+"] NON esiste");
      }
      logger.log("createSubCategory, uscito");
      return subCategoryToReturn;
   }
The lucene search query works fine ('ve tryed it in the node browser), but I can't execute the "rootCategory.createSubCategory" because the method is not set for a ScriptNode object, infact if I launch the:
rootCategory.isCategory
it returned me false, and for me this is strange because the returned node has set the cm:category aspect.

For me this is a bug because the category nodes returned from a lucene search must return true if the "isCategory" method is call on it.

It's right?
I hope that I'm wrong, or that you can give me an help, otherwise I'm blocked.

THANKS
1 REPLY 1

fstnboy
Champ on-the-rise
Champ on-the-rise
Hi,

In order to deal with categories in Javascript and use the methods provided by the CategoryNode object, you'll need to use the 'classification' root object.

Check Alfresco's wiki page for more info:

http://wiki.alfresco.com/wiki/3.4_JavaScript_API#Classification_API

Hope this helps, if so, please click Yes on the Post Rating on the right –>

Adei