AnsweredAssumed Answered

Problem searching for aspect with Lucene

Question asked by turgayz on Sep 26, 2006
Latest reply on Sep 26, 2006 by turgayz
Hi,
I have the following test case, which searches for nodes that have the "Auditable" aspect. I know that at least the "guest_home" node has this aspect, after checking with the Node Browser. But the search cannot find any nodes. Please help, what is wrong with my search?
Note: I am using the latest repository code.

import java.util.List;

import junit.framework.TestCase;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcher;
import org.alfresco.repo.search.impl.lucene.LuceneSearcherImpl;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;

public class LuceneTest extends TestCase{
   static NodeService nodeService = null;
   static DictionaryService dictionaryService = null;
   static AuthenticationComponent authenticationComponent = null;
   static LuceneIndexerAndSearcher indexerAndSearcher = null;
   static boolean setupCompleted = false;
   
   @Override
   protected void setUp() throws Exception {
      if(!setupCompleted) {
      // initialise app content
      ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
      // get registry of services
      ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

      // get required services
      nodeService = serviceRegistry.getNodeService();
      dictionaryService = serviceRegistry.getDictionaryService();

      indexerAndSearcher = (LuceneIndexerAndSearcher) ctx.getBean("luceneIndexerAndSearcherFactory");

      authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
      authenticationComponent.setSystemUserAsCurrentUser();
      setupCompleted = true;
      }
   }

   public void testFindAllAuditableAspectsInTheRepository() {
      LuceneSearcherImpl searcher = LuceneSearcherImpl.getSearcher(getCompanyHome().getStoreRef(), indexerAndSearcher);
      String queryStr = "ASPECT:\"" + ContentModel.ASPECT_AUDITABLE.toString() + "\"";
      searcher.setDictionaryService(dictionaryService);
      ResultSet results = searcher.query(getCompanyHome().getStoreRef(), "lucene", queryStr, null, null);
      assertTrue(results.getNodeRefs().size()>0);
   }

   
   private NodeRef getCompanyHome() {
      StoreRef spacesStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");

      NodeRef rootNodeRef = nodeService.getRootNode(spacesStoreRef);
      List<ChildAssociationRef> childRefs = nodeService.getChildAssocs(rootNodeRef,
            RegexQNamePattern.MATCH_ALL, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "company_home"));
      ChildAssociationRef companyHomeRef = childRefs.get(0);
      NodeRef companyHome = companyHomeRef.getChildRef();

      return companyHome;
   }

}

Outcomes