Generating Custom Search SeedList for WCM contents

Scenarios where you need to generate custom XML seedlist (instead of the out of box ATOM search feed) for the third party search engines. Following is one way we can generate custom XML seedlist for all the contents in WCM repository.

Steps
1. Create Menu Component
2. Create JSP Component to access the component outside

Step 1:
Create a Menu Component where settings will be as follows

Search Criteria would
Authoring Template= Select all authoring templates that you use to create content

Header: <custom-metadata>

Design for each menu search result:
<record>
<content-path><PathCmpnt type="noprefixbase"/>/wps/mypoc?urile=wcm:path:<Placeholder tag="sitepath"/></content-path>
<crawlURL><PathCmpnt type="noprefixbase"/>/wps/wcm/connect<Placeholder tag="sitepath"/></crawlURL>
<title><IDCmpnt context="autoFill" type="content" field="title"/></title>
<region><Element context="autoFill" type="content" key="Organization"/></region>
<publish-date><WorkflowCmpnt context="autoFill" type="content" field="publishdate" format="MM/dd/yyyy"/></publish-date>
<keywords><ProfileCmpnt context="autoFill" type="content" field="categories"/></keywords>

</record>

Footer: </custom-metadata>



Step 2:
Write the following code in JSP and place it in External Web Application (use external application for customization for better flexibility)

<%@ page import="com.ibm.workplace.wcm.api.*" %>
<%@ page import="java.util.*" %>
<?xml version="1.0" encoding="UTF-8"?>
<%

String requestedURL= request.getRequestURL().toString();
String contextPath=request.getContextPath();
String baseURL="";
String compName = "MENU-Search-XML";
String html = "";
String libraryName = "";
String sitePath="wcmPath";

libraryName=sitePath.substring(0,sitePath.indexOf("/"));
Workspace workspace = WCM_API.getRepository().getWorkspace(userId, password);
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary(libraryName));
DocumentIdIterator docIds=workspace.findByName(DocumentTypes.LibraryComponent,compName);
if (docIds.hasNext()){
    DocumentId did = (DocumentId)docIds.next();
    LibraryComponent libComp = (LibraryComponent)workspace.getById(did);
    RenderingContext rcjsp = (RenderingContext)request.getAttribute(Workspace.WCM_RENDERINGCONTEXT_KEY);
    if(null == rcjsp)rcjsp = workspace.createRenderingContext(request,response,new HashMap(),baseURL,"connect");
    rcjsp.setRenderedContent(sitePath);
    html = workspace.render(rcjsp, libComp);
    out.println(html);
}
%>

Note:
a). If you want expose the component for directly producing the XML seedlist , include following additional information in above menu design

Header Design Component 
<?xml version="1.0" encoding="UTF-8"?>


Use the following link to access your component that produces the seedlist
http://localhost:10041/wps/wcm/myconnect/Library/site/sitearea/?srv=cmpnt&source=library&cmpntname=libraryName/Menu-Search-XML&WCM_Page.ResetAll=TRUE&CACHE=NONE&CONTENTCACHE=NONE&CONNECTORCACHE=NONE

b).  Make sure that your JSP (if you write JSP to produce XML seedlist) will return response MIME type as "text/XML" instead of "text/HTML". Place following line in JSP at top to return MIME type as XML.
<?xml version="1.0" encoding="UTF-8"?>

No comments:

Post a Comment