Advanced WCM Search Integration
Overview
For basic info, see: Developerworks WCM Search. This article discusses advanced topics.
When the WCM search seed servlet provides the XML to the portal search crawler, the following metadata is associated:
Name Name field of the content Title Title field of the object Descr Description field Authors Authors of the object, in the full distinguished name form Keywords Keywords of the object Lastmodifieddate Last modified date of the document. AuthoringTemplate Title of the authoring template for the object, assuming content Category Titles of the categories associated with the content Modifier Last modifier, in full distinguished name format Owners Owners of the document, in full distinguished name format ExpirationDate Expiration date of the document, EffectiveDate Effective date of the document CONTENT_UUID UUID of the document. UUID is the unique identifier within JCR/WCM CONTENT_PATH Path to the content within WCM How to search WCM content using this metadata
The WCM infocenter and the WCM Search whitepaper document how to do simple searching against WCM metadata by submitting WCM defined search attributes in an HTML form to a WCM Search Component:
- Create HTML form
- Include the search_query to include the query string
- Add any of the above attributes by adding form elements with those names
Search parameters
The following parameters can be used in a search query in this format:
<input name="search_parameter" />
Parameter Searches search_query Content of any elements stored in a content item. search_authoringtemplate Authoring template, if available, that was used to create the content item. search_authors Name or names of the authors for the content item, if any are defined. search_categories Categories of the content item if any are defined. search_description Description of the content item. search_effectivedate Effective date of the content item. Only works with the format MMM DD YYYY. For example, Sep 20 2006. To change the format, Set SearchService.DataFormString in SearchService.properties. search_expirationdate Search the expiration date of the content item. Only works with the format MMM DD YYYY. For example, Sep 20 2006. To change the format, Set SearchService.DataFormString in SearchService.properties. search_keywords Keywords of the content item if any are defined. search_lastmodifieddate Last modified date of the content item. Only works with the format MMM DD YYYY. For example, Sep 20 2006. To change the format, Set SearchService.DataFormString parameter in SearchService.properties. search_modifier Name of the last person to modify the content item. search_name Name of the content item. search_owners Name or names of the owners of the content item, if any are defined. search_title Title of the content item. For example, to search for content that includes the term foo and is tagged with a category title of bar:
<form action='<PathCmpnt type="servlet"/>/path/to/content/with/searchcmpnt method="post"> <table> <tr><td> Search Query: <input type="text" name="search_query"/><br> Search Category: <input type="text" name="search_categories"/><br> </td></tr> <tr><td align="right"> <input type="submit" value="Search"/> </td></tr> </table> </form>In the form, you would enter for search_query foo, and for search_categories bar. WCM takes the information from the request, and translates to a search query to issue against the Search and Indexing API (SIAPI)
foo ^category:bar
The tilde (^.) tells the underlying portal search that we want content that contains "foo" and is categorized with "bar". Out of the box, this is the way that WCM treats additional attributes that are passed through the HTML form.
To build more complex search strings we need to know what SIAPI attributes the WCM search_ tags are mapped to.
WCM search_ tag SIAPI attribute search_title Title search_name Name search_description Description search_keywords Keywords search_categories Category search_authors Author search_owners Owner search_lastmodifieddate LastModifiedDate search_effectivedate EffectiveDate search_expirationdate ExpirationDate search_authoringtemplate AuthoringTemplate search_modifier Modifier search_uuid ContentID search_contentpath ContentPath
Example 1
For this example we have:
- A content object to hold the search form and results
- Some content that's tagged with categories, and has specific searchable content contained.
Create the necessary infrastructure
- Create a search collection named MyDemoCollection.
- Create an Authoring template, include a Component Reference named CompRef.
- Create a presentation template, including the html:
<Element context=current type=content key=CompRef/>
- Create Site named SiteDemoSearchSite. Mapped the Authoring template to the presentation template
- Create Site Area named SiteDemoSearchSiteArea
- Create Search Component.
In the search component fields, use the following values:
Header:
<table>
<tr>
<td>Attribute</td><td>value</td><tr>
Results:<tr><td>link</td><td>
<a href="/wps/myportal/searchResults?WCM_GLOBAL_CONTEXT=<AttributeResource attributeName="url" separator=","/>"><AttributeResource attributeName="name" separator=","/></a></td></tr>
Footer:
</table>
Separator: <tr><td></td><td></td></tr><tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
No Result Design:
There are no results for query. Please refine search and try again.The URL that's generated for Results: is prepended with...
/wps/myportal/searchResults?WCM_GLOBAL_CONTEXT=.which causes the link, when clicked, to bring the user to a portal page with a friendly URL mapping of searchResults. On that page there will be a local rendering portlet deployed.
Populate the Search Component with MyDemoCollection as the search collection.
- Create an HTML component to hold the search form.
<form action='' method="post"> <table> <tr> <td> <input type="text" name="search_query"/> </td> </tr> <tr> <td align="right"> <input type="submit" value="Search"/> </td> </tr> </table> </form> Results:<br> <Component name="search - demosearchcomponent"/><br>This places the search form and the results in the same component. The action='' is used to submit the form to itself.
- Using the new authoring template, create a piece of content, CompRef, populated with the html search form.
- Create 2 portal pages.
- Create friendly URL mapping for searchResults, pointed at one of the new pages.
- Deploy the Local Rendering portlet to both pages.
- Configure the local rendering portlet on the searchResults page to a dummy piece of content
- Set it up to receive links from this and other portlets.
- Configure the portlet on the other page to a piece of default content and set the ability to receive links from this and other portlets.
When a search is issued, the links for the results will show in the same form as the search. However, clicking a link will break you out to a different page, so that you don't lose the search context.
Advanced Searching for Content
For this example...
- The Authoring Template for all content was named AT DEMO_AT
- WCM categories to tag the content:
- We entered the following into every piece of content in a rich text field: TestSearchTerm
- Have the following 5 Content objects:
The query syntax that SIAPI uses follows the syntax from the Omnifind product documentation.
Query examples
First, we'll start with a very basic query. This returns all the content that contains the term TestSearchTerm. Enter TestSearchTerm in the search box, all of the content will be returned:
Next, we'll search for all content that contains the TestSearchTerm and is categorized with the category Group1. Enter into the search box TestSearchTerm +Category:Group1:
Next, lets search for all content that contains the TestSearchTerm and is categorized with either Group1 or Group2. Enter into the search box:
TestSearchTerm ^(Category:Group1 | Category:Group2)
Finally, lets get all content that contains TestSearchTerm, but is NOT categorized with Group1 or Group2. Enter into the search box:
TestSearchTerm -Category:Group1 -Category:Group2
Add additional custom search metadata
Now that you can build advanced queries, you may wish to add own custom searchable attributes. For example, lets say you want to tag content with an additional keyword type value that you do not wish to use as a keyword for the WCM content.
Following the instructions in the infocenter it notes that you will basically have to update a properties file, and restart the sever. For this example, we set the following:
SearchService.MetaFields=metaText,meta
So now that WCM is making this a searchable field, that field needs to be added to the content. We can add the component directly to a piece of content:
- Opened content open for edit
- Clicked on the Manage Elements button to add the element
- Added text component named metaField
- After adding, populated it with metaTextSearch
- Save and close the content.
Once the content has the component added, the search crawler needs to rerun so that the value gets placed into the search crawler information for the content.
After the crawl, you can now issue search like meta:metaTextSearch, and the content will be returned.
So, for this...
SearchService.MetaFields=metaText,meta
.meta is the key, which will be the lookup. metaText is the attribute name that will be used to populate the value within the search collection.