The CMS provides a default search tool on contents. This tool allows to search contents among 5 criterium :
content type,
content title,
last contributor's login,
workflow step,
last modified date
The results are displayed in a grid with 5 columns :
the content title with its content type's icon
the last contributor
the last modified date
the workflow step as an icon
the content type (hidden by default)
How to override the default search tool ?
The search tool is configurable in the plugin.xml file so you can easily override it.
The following elements are defined, and so configurables, in the plugin.xml file:
the criterium
the result columns
the mapping between content properties and columns
the search URL
the number of result per page
Criteria declaration
To declare a criteria (ie. form field), you must defines at least :
the field name
the column index in which it will be displayed : 1,2,3 or 4
the field label
the test operator for the search : wd (wildcard), eq (equals), ne (not equals), lt (less than), le (lessthan or equals), ge (greater than or equals) or gt (greater than)
the type : string, long, double, date or boolean
You can also define :
if it is a hidden field. Default to false
a specific widget to use.
if it is a metadata or not. Default to true.
a enumerator
Samples
Simple string criteria
Oops !
Copy to clipboard failed. Open the code and copy it manually.
The renderer function is a ExtJS function to be used to process the raw data and return HTML markup to display it in the cell. The render function is called with the following parameters:
value : the data value for the cell,
p : an object in which you may set the following attributes:
css : StringA CSS class name to add to the cell's TD element.
attr : StringAn HTML attribute definition string to apply to the data container element within the table cell (e.g. 'style="color:red;"').
record : The Ext.data.Record from which the data was extracted
rowIndex: the row index
colIndex: the column index
The CMS search tool provides 4 renderer functions you can use :
org.ametys.cms.tool.search.SearchTool.renderTitle
To render the "document-title" property with the content type's icon
Oops !
Copy to clipboard failed. Open the code and copy it manually.
org.ametys.cms.tool.search.SearchTool.renderTitle = function (value, p, record)
{
var title = '';
if (record.data['icon-small'])
{
title += '<img src="' + context.contextPath + record.data['icon-small'] + '" style="float:left; margin-right: 5px"/>';
}
title += record.data['document-title'];
return title;
}
org.ametys.cms.tool.search.SearchTool.renderTitle = function (value, p, record)
{
var title = '';
if (record.data['icon-small'])
{
title += '<img src="' + context.contextPath + record.data['icon-small'] + '" style="float:left; margin-right: 5px"/>';
}
title += record.data['document-title'];
return title;
}
org.ametys.cms.tool.search.SearchTool.renderTitle = function (value, p, record)
{
var title = '';
if (record.data['icon-small'])
{
title += '<img src="' + context.contextPath + record.data['icon-small'] + '" style="float:left; margin-right: 5px"/>';
}
title += record.data['document-title'];
return title;
}
The property mapping is used to link the column property to the XML received after a search. This is a very important part, if your result values are not well displayed, first check the mapping.
In the mapping, you defines :
the column property id
the matching XPath where to find the property value
the property type. Default to string
Oops !
Copy to clipboard failed. Open the code and copy it manually.
To do this correctly you must know the XML stream send by the search generator. By default it is composed by the requested properties defined in mapping as following :
Oops !
Copy to clipboard failed. Open the code and copy it manually.
By default it is 50. If you want to override this value, do as follow in the plugin.xml file
Oops !
Copy to clipboard failed. Open the code and copy it manually.
<nb-result-per-page>100</nb-result-per-page>
<nb-result-per-page>100</nb-result-per-page>
<nb-result-per-page>100</nb-result-per-page>
Search URL
The search URL is the called URL to launch search. If you want to override it (if you changed the default search generator for example), do as follow in the plugin.xml file
Oops !
Copy to clipboard failed. Open the code and copy it manually.
If you need to do more specific actions that the tool declaration does not allow you, you can override the JS tool (org.ametys.cms.tool.search.SearchTool). Take a look to the original JS file to see which function(s) you need to override.
The following sample shows you how to override the search tool to add a listener on a criteria field :
Oops !
Copy to clipboard failed. Open the code and copy it manually.
Override the search generator class (org.ametys.cms.repository.SearchGenerator.java)
You may need to override the search generator JAVA class to do specific treatments. The search generator provides a lot of protected methods to do this easily. Take a look on API.
To use it you must add your own pipeline in your plugin and change the default url (see "Search Url" above)
Oops !
Copy to clipboard failed. Open the code and copy it manually.