Búsquedas con Java API

RECU-0059 (Recurso Ejemplo)

Descripción

Búsqueda con Lucene

Obtenemos el servicio de Registro,necesario para poder realizar cualquier acción. Declaramos los servicios necesarios.

ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

Obtenemos los servicios necesarios para poder realizar la búsqueda

TransactionService transactionService = serviceRegistry.getTransactionService();
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
SearchService searchService = serviceRegistry.getSearchService();
NodeService serviceNode=serviceRegistry.getNodeService();

El siguiente paso sera el de identificarnos en el sistema

authenticationService.authenticate("admin", "admin".toCharArray());

Realizamos la búsqueda y obtenemos los resultados

StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");        
        ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/*\" AND TYPE:\"cm:folder\"  ");
       
        QName QNamedoc = QName.createQName("{http://www.alfresco.org/model/content/1.0}name");
       
       
        List<NodeRef> spaces = resultSet.getNodeRefs();

Mostramos el resultado de la búsqueda

for(int i=0;i<spaces.size();i++)
        {
        NodeRef space=(NodeRef) spaces.get(i);
        String nombre=serviceNode.getProperty(space, QNamedoc).toString();
        System.out.println("Nombre:"+nombre);                       
        }

Búsqueda con XPath

Obtenemos el servicio de Registro,necesario para poder realizar cualquier acción. Declaramos los servicios necesarios.

ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

Obtenemos los servicios necesarios para poder realizar la búsqueda

TransactionService transactionService = serviceRegistry.getTransactionService();
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
SearchService searchService = serviceRegistry.getSearchService();
NodeService serviceNode=serviceRegistry.getNodeService();

El siguiente paso sera el de identificarnos en el sistema

authenticationService.authenticate("admin", "admin".toCharArray());

Realizamos la búsqueda y obtenemos los resultados

StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
       
        ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, "/*/*/.");
       
        List<NodeRef> spaces = resultSet.getNodeRefs();
        QName QNamedoc = QName.createQName("{http://www.alfresco.org/model/content/1.0}name");

Mostramos el resultado de la búsqueda

for(int i=0;i<spaces.size();i++)
        {
        NodeRef space=(NodeRef) spaces.get(i);
        String nombre=serviceNode.getProperty(space, QNamedoc).toString();
        System.out.println("Nombre:"+nombre);
        }