AnsweredAssumed Answered

Integration testing using search service

Question asked by alex.lu on Oct 4, 2013
Hi,

I'm struggling to use search service in an integration test case. I've stripped down a lot of code that I've written just to show that search service doesn't seem to work in integration testing. The indexer is set to lucene.

For the test case below, I created a node called node 1 as a child node of the root node. Then I've built a path query to find the newly created node. You might suggest to use XPATH language. I actually need to build a composite query and part of the query requires a path. I've used both LUCENE and FTS languages and neither returned any result. Does anyone know why?


public class SearchServiceIT extends BaseAlfrescoSpringTest {

    @Override
    protected void onSetUpInTransaction() throws Exception {
        super.onSetUpInTransaction();
    }

    public void testSearchService() throws Exception {
        SearchService searchService = (SearchService) this.applicationContext.getBean("searchService");
        NamespaceService namespaceService = (NamespaceService) this.applicationContext.getBean("namespaceService");

        NodeRef node1 = createNode(rootNodeRef, "node 1", ContentModel.TYPE_CONTENT);
        assertTrue("Node 1 doesn't exist", nodeService.exists(node1));
        Path node1Path = nodeService.getPath(node1);
        String xpath = node1Path.toPrefixString(namespaceService);
        String query = "PATH:\"" + xpath + "\"";

        ResultSet luceneResultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, query);

        assertTrue("LUCENE: " + query, luceneResultSet.length() > 0);

        ResultSet ftsResultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_FTS_ALFRESCO, query);

        assertTrue("FTS: " + query, ftsResultSet.length() > 0);

    }

}

Outcomes