/** * Creates a new search index setup for this test. * * <p> * * @throws Exception in case the test fails */ public void testSearchIndexSetup() throws Exception { CmsSearchIndex searchIndex = new CmsSearchIndex(INDEX_SPECIAL); searchIndex.setProjectName("Online"); searchIndex.setLocale(Locale.ENGLISH); searchIndex.setRebuildMode(CmsSearchIndex.REBUILD_MODE_AUTO); // available pre-configured in the test configuration files opencms-search.xml searchIndex.addSourceName("source1"); searchIndex.addConfigurationParameter(CmsSearchIndex.BACKUP_REINDEXING, "true"); // initialize the new index searchIndex.initialize(); // add the search index to the manager OpenCms.getSearchManager().addSearchIndex(searchIndex); I_CmsReport report = new CmsShellReport(Locale.ENGLISH); // this call does not throws the rebuild index event OpenCms.getSearchManager().rebuildIndex(INDEX_SPECIAL, report); OpenCms.getSearchManager().rebuildIndex(INDEX_SPECIAL, report); // perform a search on the newly generated index CmsSearch searchBean = new CmsSearch(); List<CmsSearchResult> searchResult; searchBean.init(getCmsObject()); searchBean.setIndex(INDEX_SPECIAL); searchBean.setQuery(">>SearchEgg1<<"); // assert one file is found in the default site searchResult = searchBean.getSearchResult(); assertEquals(1, searchResult.size()); assertEquals("/sites/default/xmlcontent/article_0001.html", (searchResult.get(0)).getPath()); }
/** * Ensures the content and content blob fields are loaded lazy. * * <p> * * @throws Exception in case the test fails */ public void testLazyContentFields() throws Exception { echo("Testing lazy status of content fields in search index"); String fileName = "/sites/default/test/master.pdf"; CmsSearchIndex searchIndex = OpenCms.getSearchManager().getIndex(INDEX_SPECIAL); Document doc = searchIndex.getDocument(CmsSearchField.FIELD_PATH, fileName); assertNotNull("Document '" + fileName + "' not found", doc); assertNotNull("No 'content' field available", doc.getFieldable(CmsSearchField.FIELD_CONTENT)); assertTrue("Content field not lazy", doc.getFieldable(CmsSearchField.FIELD_CONTENT).isLazy()); assertNotNull( "No 'content blob' field available", doc.getFieldable(CmsSearchField.FIELD_CONTENT_BLOB)); assertTrue( "Content blob field not lazy", doc.getFieldable(CmsSearchField.FIELD_CONTENT_BLOB).isLazy()); }