To ensure that your custom modules are indexed by search engines, you need to include the following in your module implementation:
An object that extends the AbstractIndexItem class and gathers the textual data of a module for indexing
An indexing portal service that extends the AbstractModuleIndexData class and obtains this object
The following examples illustrate how to prepare for indexing the textual data of a basic text editor module, and how to implement an indexing service.
public class IndexObject extends AbstractIndexItem { private IModuleContext moduleContext; private ItemInfo itemInfo; public static final String MY_CUSTOM_MODULE = "My custom module"; public IndexObject(IModuleContext moduleContext, ItemInfo itemInfo) { this.moduleContext = moduleContext; this.itemInfo = itemInfo; } public ItemInfo getItemInfo() { return this.itemInfo; } public String[] getTexts() throws WorkspacesRuntimeException { // Retrieve the text content of the module from the storage IWorkspacesRuntime workspacesRuntime = RuntimeFactory.getWorkspacesRuntime(); IModuleStorageFactory storageFactory = (IModuleStorageFactory) workspacesRuntime.getService(IModuleStorageFactory.class); IModuleStorage storage = storageFactory.getStorage(moduleContext); String[] allTexts = new String[1]; allTexts[0] = storage.getProperty( "com.sap.workspaces.textpad.htmlMarkup");; return allTexts; } public String getDescription() throws WorkspacesRuntimeException { // Retrieve the module's description return "Basic text editor"; } public String getName() throws WorkspacesRuntimeException { // Retrieve the module's name return moduleContext.getProperty("com.sap.portal.pcm.Title"); } public String getType() { // Retrieve the module's type return IndexObject.MY_CUSTOM_MODULE; } }
public class IndexDataService extends AbstractModuleIndexData implements IService { public AbstractIndexItem getIndexItem(IModuleContext moduleContext, ItemInfo itemInfo) { IndexObject indexObject = new IndexObject(moduleContext, itemInfo); return indexObject; } }
A search engine periodically indexes all workspace content. Additionally, it is possible to initiate an index update for a specific module when it is updated. To do this, add the following code to your module implementation:
public void raiseOnUpdateEvent(IModuleContext moduleContext) { // Retrieve the module events service IModuleEvents eventService = (IModuleEvents) RuntimeFactory.getWorkspacesRuntime().getService(IModuleEvents.class); // Raise an event when the specified module is updated eventService.moduleUpdated(moduleContext); }
The relevant APIs are contained in the com.sap.workspaces.indexing, com.sap.workspaces.module and com.sap.workspaces.module.extension packages.