Case study: User Interface for Advanced Search in WCM

In this section, we will discuss the case study of UI for Advance Search in WCM. Here we will provide different criteria for search, such as choosing the web form of which we want to search the content and the facility to choose the path in the ROOT folder to search the content. For this we will use Lucene search so that it will search only in a Staging Sandbox.

This search example is for free text-based search and does not provide the capability to search the content based on its property. We will see the example of searching content based on the content property in the next section.

To implement this functionality:

  1. Provide a link for Advance Search in the browse-sandbox.jsp page as:
    <div style="float:right;padding-right:20px;padding-top:3px">
    <a:actionLink id="advance-search-image" value="Advance Search" image="/images/icons/search_icon.gif" showLink="false" showLink="false" action="advanceSearch" />
    <a:actionLink id="advance-search-apply" value="Advance Search" showLink="false" action="advanceSearch" />
    </div>
    
  2. Create a new JSP file in the jsp/extension/wcm/search folder for rendering the Search UI Page.
  3. Add a managed bean definition in the faces-config-custom.xml file. This bean is going to handle search parameter retrieval process for Advanced Search JSP.
    <managed-bean>
    <description>
    The bean that holds a state for the Advanced Search screen.
    </description>
    <managed-bean-name>CustomAdvancedSearchBean</managed-bean-name>
    <managed-bean-class>com.cignex.web.bean.wcm.CustomAdvancedSearchBean </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>nodeService</property-name>
    <value>#{NodeService}</value>
    </managed-property>
    <managed-property>
    <property-name>searchService</property-name>
    <value>#{SearchService}</value>
    </managed-property>
    <managed-property>
    <property-name>serviceRegistry</property-name>
    <value>#{ServiceRegistry}</value>
    </managed-property>
    </managed-bean>
    
  4. Implement class com.cignex.web.bean.wcm.CustomAdvancedSearchBean and implement a method [public Search ()] that will perform the search with the specified parameters. This class will also have corresponding fields for all search components.
  5. Create a Java class, CustomAdvanceSearchBean, with the specified package structure, which will actually perform the search in the repository.

Note

Download the sample code files from the Packt website.

Search text in ROOT folder and for all web forms

This will search in all of the sub-folders of ROOT in the current web project and will also search for all the web forms. The Reset All button will reset all search criteria. Search will return the search results with the filename and corresponding path. The following screenshot shows a snap of the search screen, which searches for the text Alfresco in the current web project's Staging Sandbox.

Search text in ROOT folder and for all web forms
Search text in particular web form content

This will search the text in all the sub-folders of ROOT in the current web project and will also search in a specific, selected web form as shown in the following screenshot:

Search text in particular web form content
Search text in particular folder of web project

This will search the specified text in the particular selected folder within the web project. The Folder Tree component allows you to choose the folder in which you want to search the text. The following screenshot shows the Folder Tree component and the search result:

Search text in particular folder of web project
Search text in particular web form and in particular folder of web project

This will search the specified text in a particular folder selected with the help of the Folder Tree component and also search the content created using the specified web form. The Select WebForm combo box will fetch all web forms associated with the current web project:

Search text in particular web form and in particular folder of web project

Metadata extraction for WCM

The case study we discussed in the previous section was for the free text search with advanced search criteria in the WCM. In this section, we will discuss how we can perform the search based on the metadata of particular content. Alfresco provides some of the metadata extractors, which are responsible for extracting the metadata from the added or updated content at the server side. Alfresco has different extractors for handling different types of mimetypes for DM.

In this section, we will see how we can configure XML Metadata Extractor for WCM. We will take the example of news content, which we are creating with the help of a news web form.

  1. To Activate metadata extraction for WCM, rename the wcm-xml-metadata-extracter-context.xml.sample file available in the<alf_home>/tomcat/shared/classes/alfresco/extension folder to wcm-xml-metadata-extracter-context.xml. This file will have bean declaration for WCM Metadata extraction, as follows:
    <bean id="avmMetadataExtracterRegistry"
    class="org.alfresco.repo.content.metadata. MetadataExtracterRegistry" />
    ...
    <property name="invokePolicies">
    <value>true</value>
    </property>
    ...
    <property name="metadataExtracterRegistry">
    <ref bean="avmMetadataExtracterRegistry" />
    </property>
    ...
    </bean>
    
  2. The AVMNodeService fires policies for content creation and update that are listened to by avmMetadataExtractors, which is responsible for initiating the metadata extraction for content newly created or updated.
  3. To configure an extractor to handle XML content, first we need to configure XpathMetadataExtracter, as follows:
    <property name="xpathMappingProperties">
    <bean class="org.springframework.beans.factory.config. PropertiesFactoryBean">
    <property name="location">
    <value>
    classpath:alfresco/extension/News-Xpath-Mappings. properties
    </value>
    </property>
    </bean>
    </property>
    

    Here, News-Xpath-Mappings.properties stored in the alfresco/extension folder will have mappings of XPath as follows:

    # Name Space
    namespace.prefix.trn=http://www.alfrescobook.com/webforms
    # XPATH Mappings
    short_title=news/shortTitle/text()
    content_header=news/contentHeader/text()
    content_sub_header=news/contentSubHeader/text()
    news_date=news/newsDate/text()
    
  4. Now we need to map this property with the properties of a content model; for that again, we need to configure property as follows:
    <property name="mappingProperties">
    <bean class="org.springframework.beans.factory.config. PropertiesFactoryBean">
    <property name="location">
    <value>classpath:alfresco/extension/Content-Model-Mappings. properties
    </value>
    </property>
    </bean>
    </property>
    
  5. Here Content-Model-Mappings.properties stored in the alfresco/extension folder will have a mapping of properties of the content model as:
    namespace.prefix.cignex=http://www.cignex.com
    # Mappings
    short_title=shortTitle
    content_header=contentHeader
    content_sub_header=contentSubHeader
    news_date=newsDate
    
  6. Now we need to select the extractor as XMLMetadataExtractor and configure bean for this as:
    <bean id="extracter.xml.sample.XMLMetadataExtracter"
    class="org.alfresco.repo.content.metadata.xml.XmlMetadataExtracter"
    parent="baseMetadataExtracter">
    <property name="registry">
    <ref bean="avmMetadataExtracterRegistry" />
    </property>
    <property name="overwritePolicy">
    <value>EAGER</value>
    </property>
    <property name="selectors">
    <list>
    <ref bean="extracter.xml.sample.selector.XPathSelector" />
    </list>
    </property>
    </bean>
    
  7. We also need to create a custom content model to define our custom properties. In this example, we are considering news as one content type, so we need to create a custom aspect with the properties of news as:
    <aspect name="cignex:news">
    <title>Cignex News</title>
    <properties>
    <property name="cignex:shortTitle">
    <title>Short Title</title>
    <type>d:text</type>
    <index enabled="true"/>
    </property>
    <property name="cignex:contentHeader">
    <title>Content Header</title>
    <type>d:text</type>
    <index enabled="true"/>
    </property>
    <property name="cignex:contentSubHeader">
    <title>Content Sub Header</title>
    <type>d:text</type>
    <index enabled="true"/>
    </property>
    <property name="cignex:newsDate">
    <title>News Date</title>
    <type>d:date</type>
    <index enabled="true"/>
    </property>
    </properties>
    </aspect>
    
  8. Now we can search based on any custom property (metadata). You can add search criteria as:
    @cignex:shortTitle:"CignexNews",@cignex:contentHeader:"Cignex*"
    
  9. You can use any of the previously mentioned approaches using Java or JavaScript API, among others, to perform the search by providing this criteria.

    Note

    Download the sample code files for the WCM metadata extractor from the Packt website.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset