Tuesday, June 26, 2012

WCM search and Integrating with portal search


1.       Creating the WCM search collection
        1) Login to Portal Administration
        2) Goto Search Administration > Manage Search
        3) Click on 'Search Collections' > New Collections and provide following information
                        Location of collection : MytechCollection
                        Name of collection : MytechCollection
                        Description of Collection : MytechCollection
        4) Once saved, click on MytechCollection
        5) Create following Content Sources (MytechContent, BlogContents)
        6) Click on 'New Content Source' and provide following details to create MytechContent content sources
a.       Content Source Type : WCMSITE
b.      Content Source Name : MytechContent
c.       Collect documents linked from this URL : http://portal.Mytech.com:10039/seedlist/myserver?SeedlistId=MytechContent/Internet&Source=com.ibm.workplace.wcm.plugins.seedlist.retriever.WCMRetrieverFactory&Action=GetDocuments
      Note - Replace portal.Mytech.com with your portal server host name and MytechContent/Internet with your wcm sitearea
d.      Levels of links to follow: Unlimited
e.      Number of documents to collect: Unlimited
f.        Force Complete Crawl: true
g.       Stop collecting after (min):60
h.      Stop fetching a document after (sec): 20
i.         Links expire after (days): Unlimited
j.        Remove broken links after (days): 10
k.       Click on Security tab and enter portal admin credentials
                User Name : wpsadmin
                Password : wpsadmin
                Host Name : portal.Mytech.com
                Click on 'Create' button
                Click on Save button
                Note - Provide actual portal host and wpsadmin credentails
l.         Once saved, click on 'Start Crawler' button next to created content source entry
7) Search anonymously - to allow anonymous users to access the portal search collections, you need to Add Anonymous user to your Search Collection
Assign Anonymous Permission to MytechCollection
a)      Login to portal administration
b)      Goto Access > Resource Permissions
c)       Click on PSE Sources
d)      Click on 'Assign Access' button next to MytechCollection entry
e)      Edit User Role
f)       Add ' Anonymous Portal User' and ' All Authenticated Portal Users'
g)      Apply and done

2.       Rendering WCM search component results
WCM search component can also be used to display WCM search results.
There are several reasons you may decide to do this instead of using search center out of box portlet, some reasons:
o   Only WCM results will be displayed, meaning any non WCM assets in the search collection will be filtered out when using WCM search component.
o   Full control over the HTML display of the results.
o   Integration within a WCM site being rendered from the servlet.

To accomplish this, we have to create a piece of content that will hold both the search form and the results of the search. When a search is submitted the form will submit to the page for the results, which the form is also deployed to.

1)      Creating the Authoring Template
First, an authoring template for the content is necessary. Create an authoring template named "AT_Search", and use manage elements to add the following 3 elements:
query_form - a Component Reference
search_results - a Component Reference
text - a Text Componentck
2)      Creating the presentation template
Next we need to set up the presentation template to display the elements. Create a new presentation template named "PT_Search", and in the HTML put the following:
<p>[Element context="current" type="content" key="text"]</p>
<p>[Element context="current" type="content" key="query_form"]</p>
<p>[Element context="current" type="content" key="search_results"]</p>
3)      Creating the WCM search form
Now, we need to create the HTML component that will hold the html for the search form. Create a new HTML component named "HTML - Adv Search form", and enter the following HTML:

<form action='[PathCmpnt type="servlet"]/MytechContent/Internet/Search/Results' method="post" onSubmit="this.search_query.value=addFilter(this.query.value)">
<table>
<tr>
        <td>Search : </td>
        <td>
                        <input type="text" name="query" />
                        <input type="submit" value="Search" />
        </td>
</tr>
</table>
<input type=hidden name="search_query"/>
</form>

What the code does is setting up the form to submit to the MytechContent/Internet/Search/Results content (which we will create later), and puts the search_query in the form. The search_query is what gets processed by the WCM Search component as the search. We also limit results to exclude content that is using a specific authoring template, you would append this to the end of the search_query field. This means that when the search is performed, we limit results based on the content's authoring template.

Constructing search_query can easily be done using Javascript that executes on the form submit.
<script language="Javascript">
function addFilter(queryIn){
return queryIn + ' -AuthoringTemplate::"AT_Banner" -AuthoringTemplate::"AT_Search"';
}
</script>

4)      Creating the WCM search component
Next, we need the WCM search component to be created in order to display the search results. Create a new search component named "Search-Search Results". In the search options, select the MytechCollection for the Search collection: field. Also, use 10 for the results per page, as we will use a page navigation to page through the search results.

In the header field, enter the following:
[Component name="Mytechtechnical/search-result-navigation"]
<table>

In the results field, enter the following:
<tr>
        <td>
                        [AttributeResource attributeName="titleLink" separator=","]
                Date: [AttributeResource attributeName="date" format="MM/dd/yyyy" separator=","]
                        Relevance: ([AttributeResource attributeName="relevance" format="##.#" separator=","])
                        <br>
                        [AttributeResource attributeName="summary" separator=","]
        </td>
</tr>
For the footer:
</table>

For the Separator:
<tr>
        <td bgcolor="#FFFAA" colspand="2" />
</tr>

For No result design:
<div> No result found to display.</div>

5)      Creating the paging component
For the results to be paged, we create a simple paging component. Create a new 'page navigation' element named "Search-result-navigation". Use the following as a guide for the paging design for shuffle, paging, jump to page, and page size values to use.

Use the following as the guide for the value of the design elements of the paging component:


6)      Creating the necessary content and site framework
Now that the pieces are in place for the search components, all we have to do is create the content and site area to hold them. First, create a new site area in your MytechContent library. Name it "Search", and map the presentation and authoring template to the site area that you created.

Save and close the site area.

Secondly, create a new piece of content. Select the AT_Search authoring template, name the content "Results", For the Query Form item, select the HTML - Adv Search form component. For the Search Results, select the Search - Search Results component. In the text field, enter " Please select your search text and click the search button ":


Choose a workflow for your content, save and publish the content. As a last step, go back to the Search site area, and set this new content as the default content for the site area.

7)      Performing the search within the WCM search component
a) The easiest way to see the search in action is to preview the Results content. Click on the preview button, and the content will be displayed.
b) Create a portal page 'Search' and enter value 'wcmsearch' for friendly url. Click on 'Add Web Content Mapping' button and map your main sitearea as Web Content Folder.
Once page is created, click on edit page layout button and add ' Web Content Viewer (JSR 286)' portlet into this page. Configure 'Web Content Viewer (JSR 286)' portlet to wcm content 'Results'  from the edit shared settings option.

3.       Integrate WCM search component results with theme search box

Need to configure theme's themeSearchBox with WCM search component results.
Open the search.jsp of pagebuilder theme and modify ScopeSearchWidget as follows :
<div id="themeSearchBox" dojoType="ibm.portal.search.Enhanced.widgets.ScopeSearchWidget" displayScopes="false" submitUrl="?1dmy&urile=wcm%3apath%3a/MytechContent/Internet/Search/Results" resourceBundle="<portal-fmt:out><searchmenu:resourceBundle bundleName="com.ibm.lotus.search.taglib.ScopeSearchWidget"/></portal-fmt:out>" sourceContentNode="<searchmenu:currentContentNode/>" searchFeedUrl="'<searchmenu:generateSearchFeedUrl/>'" timeStamp="<searchmenu:scopesLastUpdateTime/>"></div>

Following javascript function is added to create search_query hidden input filed dynamically on submit of the themeSearchBox form. This filed store and forward user entered search query to WCM search component.

<script language="Javascript">
dojo.addOnLoad(function(){
        dojo.connect(dojo.byId("themeSearchBox"), "onsubmit", function(event){
                        search_query=dojo.doc.createElement("input");
                        dojo.attr(search_query, "name","search_query");
                        dojo.attr(search_query, "type","hidden");
                        dojo.attr(search_query, "value",addFilter(this.query.value));
                        this.appendChild(search_query);
        });
});
</script>

6 comments:

  1. Hi Shashi,

    Thanks for this article.

    I am having issue in search component.
    The search collection is working perfectly fine, able to search and browse but while mapping the collection to search component it does not work(always no result found).

    Please assist on this.

    Thanks
    Manish Soni

    ReplyDelete
    Replies
    1. The search_query is what gets processed by the WCM Search component as the search. I would suggest to try following: 1. run WCM search component independently
      2. Check the permission for search collections and wcm artifacts
      3. Look for possible filter options that you can specify https://www.ibm.com/support/knowledgecenter/en/SS3JLV_8.0.0/wcm/wcm_dev_search_form_query_filtering.html

      Delete
  2. Hi Shashi,

    I find this article very interesting and this is why I have a question:

    I am working with WCM 8.5 and I do not know how to implement a component to search in all of the content of my site, like the search magnifying glass that we see in lots of internet sites, because it does not seem to be an advanced search, but rather a search for all the content in general...
    Is this possible with WCM 8.5?

    Thanks

    ReplyDelete
    Replies
    1. There are few ways to achieve this. Try this simplest method and if this works then you can enhance it further.
      Add the search form with search txtfield in the theme and submit it to WCM search component.

      You can also use the portal out of box portlets 'Search/Search Center' to implement search capability. For more info look at this link: https://trueprogrammer.blogspot.com/2012/04/enabling-search-for-web-content-and.html

      Delete
    2. Thank you Shashi, I'm working on it and it seems that the first solution will work fine.
      While I am developing this component, it comes up a question about the user component, is there any way to show the user logged without creating a component? I look for something about this in ibm knowledge center and I do not find anything.
      I think that create a component only for a text like "Hello, Ted" is a little complex isn't it?

      I hope you can give me an answer, because the documentation I have, doesn't.

      Delete
    3. In WCM, username component would be needed to render different contents for authenticated vs anonymous users. In theme, there is few ways to achieve it via navigation spi, custom java code extra...

      Delete