The simplest way to implement a full-text search is to write a formatter for the jsp-search
content, shipped with the OpenCms core in the module org.opencms.jsp.search
and get your configuration right. For the formatter, you can start with the demo formatter referenced in the above section.
Do not let normal editors edit your search content directly. Your formatter may not be capable of all configuration options and you typically do not want to let persons not skilled for it change the configuration.
When you got everything correct, you rewrite your formatter JSP to be used for a dynamic function or a content type providing configuration options specific to your needs. The rewrite is very easy, since you only replace the confguration handed over to the <cms:search>
tag. You may even keep your configuration content, or what might be more valueable, replace it with a JSON configuration. There's a one-to-one correspondence between the options in the XML content and in the JSON configuration.. Everything else remains the same.
The formatter basically:
- hands over the
jsp-search
content (or later the JSON configuration) to the <cms:search>
tag as configuration content (or string).
- explores the result object exposed by
<cms:search>
to build up the search form and render the search results.
The result exposed by <cms:search>
is of type org.opencms.jsp.search.result.I_CmsSearchResultWrapper
. A good explanation of its structure is given in the presentation of the tag on the OpenCms Days 2015. Moreover, you can explore the formatters for the full text search of
- the Mercury demo template shipped with OpenCms 10.0 (the formatter is located in /system/modules/alkacon.mercury.template/functions/search.jsp)
- the search included in this documentation (the formatter is located in /system/modules/com.alkacon.opencms.documentation.searchform/formatters/searchform-formatter.jsp)
as examples for using it.
When your formatter is finished, ensure that you set the fl
parameter for your search correctly to prevent loading too much fields that you do not use in the formatter.
Moreover, for the JSON configuration, an example JSON file with all options is found in the test cases for OpenCms here.