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.

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:
<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>


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="*" %>
<%@ 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";

Workspace workspace = WCM_API.getRepository().getWorkspace(userId, password);
DocumentIdIterator docIds=workspace.findByName(DocumentTypes.LibraryComponent,compName);
if (docIds.hasNext()){
    DocumentId did = (DocumentId);
    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");
    html = workspace.render(rcjsp, libComp);

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

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