This portlet can be used to display results of a 3rd party search engine.
The standard configuration is best suited for a mnoGoSearch™ but it can be used for any search which is invoked by a HTTP URL (with GET parameters) and returns a XML document.
To use this module you have to create a new portlet in the portlet descriptor (portlet.xml and gentics-portlet.xml) of your Portletapplication (see below for a sample configuration)
Example 5.3. GenticsContentSearchModule2 - Minimal portlet.xml portlet descriptor
<portlet> <portlet-name>GenticsContentSearchModule2</portlet-name> <portlet-class> com.gentics.portalnode.genericmodules.ViewPortlet </portlet-class> <supports> <mime-type>text/html</mime-type> </supports> <portlet-info> <title>GenticsContentSearchModule2</title> </portlet-info> <portlet-preferences> <preference> <name>datasource</name> <value>content</value> </preference> <preference> <name>searchurl</name> <value> http://localhost/cgi-bin/mnogosearch.cgi?ps=800&q=${query} </value> </preference> <preference> <name>xslt</name> <!-- Newlines added for readability --> <value> <!-- needs to be removed --> file:///${com.gentics.portalnode.home}/WEB-INF/views/ GenticsContentSearchModule2/searchconvert_mnogosearch.xslt </value> </preference> <preference> <name>contentidfilter</name> <value>http.*?index.php\?C=([0-9\.]+)</value> </preference> </portlet-preferences> </portlet>
Example 5.4. GenticsContentSearchModule2 - Minimal gentics-portlet.xml portlet configuration
<portlet> <portlet-name>GenticsContentSearchModule2</portlet-name> <parameter-description> <parameter-definition type="string" name="viewplugin.viewbasedir"> path of the view definitions</parameter-definition> <parameter-definition type="string" name="searchmodule.searchurl"> search url</parameter-definition> </parameter-description> <start-parameters> <parameter name="viewplugin.viewbasedir"> ${com.gentics.portalnode.home}/WEB-INF/views/GenticsContentSearchModule2 </parameter> </start-parameters> <templates> <template loader="plugins"> <classes> <class id="plugin">formplugin2</class> <class id="component">DatasourceListComponent</class> <class id="class">search</class> </classes> <parameters> <parameter id="filename"> modules/GenticsContentSearchModule2/listcomponent_search.vm </parameter> </parameters> </template> </templates> </portlet>
Table 5.16. Events of the GenticsContentSearchModule2
Name | Description | Event properties | ||||||
---|---|---|---|---|---|---|---|---|
onSearch | This event is triggered when a user requests a new search.. |
| ||||||
openResult | This event is triggered when a user clicks on a search result (The only exception is if the search result is a file, which will be immediately downloaded - if it is a content object). |
|
![]() | Note |
---|---|
The above events are triggered within a View - therefore the full path for a reaction for onSearch would look like: portal.modules.GenticsContentSearchModule2.plugins.viewplugin.onSearch |
Table 5.17. Portlet Preferences for GenticsContentSearchModule2
Variable | Description |
---|---|
searchurl | Search URL used for the search. ${query} will be replaced by the user input. |
datasource | Datasource from which to load the objects. |
defaultpagesize | Page size used for the DatasourceListComponent |
xslt | URL of the XSLT which should be used to convert search results to the input of a “CreateResolvablesAction” (Section 2.2.8.7). |
contentidfilter | A regular expression which should replace a URL returned in the results of the search so that only the contentid is left over. E.g. if the search returns URLs like: http://localhost/cgi-bin/index.php?C=10007.123 you can use the following regular expression: http.*?index.php\?C=([0-9\.]+) which would replace the whole URL and leave: 10007.123 (the first regexp group has to match the contentid) |
teaserview_showresults | true/false - Wether the result list should be shown if the window state is 'normal' |
hideadvanced | true/false - Wether to hide the 'Advanced Search' option. |
The GenticsContentSearchModule2 will try to display 3 attributes of the resolvables: name, edittimestamp and description (if they exist).
Further customization of the GenticsContentSearchModule2 can be made by providing Resolvable objects. These are parsed by the “CreateResolvablesAction” (Section 2.2.8.7).
These have 2 objects. The first object are general preferences for a select component, while the second will hold the values for the SelectComponent.
First of all you can present the user a list of Pagesizes which are available.
Example 5.5. Pagesize configuration
<preference> <name>pagesize</name> <value><![CDATA[ <objects xmlns="http://www.gentics.com/create-resolvables"> <object> <attribute name="label">Page Size</attribute> <attribute name="default">10</attribute> </object> <object> <attribute name="5">5</attribute> <attribute name="10">10</attribute> <attribute name="15">15</attribute> <attribute name="20">20</attribute> </object> </objects> ]]></value> </preference>
As mentioned above the first object will be used to set up general SelectComponent options. 'label' will be the label of the SelectComponent, and 'default' will be the default value if the user does not change the value.
Another predefined option is 'outputformat' where the user can switch between a full list including all details and a short list which will only display the name column.
This SelectComponent can only have two valid options: 'full' and 'short' all others will be ignored.
In addition the GenticsContentSearchModule2 supports up to 4 custom SelectComponents which can be freely configured. The user selected value of these SelectComponents can afterwards be used within the searchurl.
These have the name: selectbox1,selectbox2,selectbox3 and selectbox4 and will be replaced in the searchurl as ${selectvalue1} through ${selectvalue4}
Example 5.6. Custom SelectComponent
<preference> <name>selectbox1</name> <value><![CDATA[ <objects xmlns="http://www.gentics.com/create-resolvables"> <object> <attribute name="label">Word Match</attribute> </object> <object> <attribute name="wrd">Whole Word</attribute> <attribute name="beg">Word beginning</attribute> <attribute name="end">Word ending</attribute> <attribute name="sub">Word substring</attribute> </object> </objects> ]]></value> </preference>
You could then adapt your searchurl e.g. for mnogosearch: http://localhost/cgi-bin/search_mnogo.cgi?ps=800&q=${query}&wm=${selectvalue1}
The GenticsContentSearchModule2 uses by default a very simple template for the DatasourceListComponent. You can overload this template to use your own and customize the look. For this to work, all you need to do is overloading the template for the DatasourceListComponent of the class 'search'
A XSLT is used to convert the XML document returned by the 3rd party search engine to a predefined xml document used to create resolvables. (Using Section 2.2.8.7, “CreateResolvablesAction”). The default xslt stylesheet contained in Gentics Portal.Node only works for one XML format (see below). If you want to support another format, or require additional attributes you need to customize the default XSLT stylesheet.
Example 5.7. Sample XML document returned by mnoGoSearch™
<search> <res> <url>http://mydomain.com/index.php?C=10007.1151</url> </res> <res> <url>http://mydomain.com/index.php?C=10007.1153</url> </res> <res> <url>http://mydomain.com/index.php?C=10007.1160</url> </res> </search>
Example 5.8. Default XSLT Stylesheet
Using XSLT it is very easy to convert e.g. the above example XML returned by a search engine to the predefiend format required by Section 2.2.8.7, “CreateResolvablesAction”. This example shows the default XSLT which could be adopted to support other search engines.
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.gentics.com/create-resolvables"> <xsl:template match="/"> <objects> <xsl:for-each select="search/res"> <object> <attribute name="contentid"><xsl:value-of select="url" /></attribute> </object> </xsl:for-each> </objects> </xsl:template> </xsl:stylesheet>