Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save barrychapman/4eacf1db18dfc0e9d9f946c7973389df to your computer and use it in GitHub Desktop.
Save barrychapman/4eacf1db18dfc0e9d9f946c7973389df to your computer and use it in GitHub Desktop.
Change search portlet configuration in theme (Liferay 6.2)
## Replace $theme.search() with our own form, note that you can still use it, just make sure the search.vm
## is loaded before you add the search portlet. We removed it to simplify changing styles on the search bar
## in the theme.
<form action="" method="get" name="search">
<input name="p_p_id" type="hidden" value="3">
<input name="p_p_lifecycle" type="hidden" value="0">
<input name="p_p_state" type="hidden" value="maximized">
<input name="p_p_mode" type="hidden" value="view">
<input name="_3_struts_action" type="hidden" value="/search/search">
<input name="_3_keywords" size="30" title="Search" type="text" value="" placeholder="Search here...">
<input name="_3_groupId" type="hidden" value="$themeDisplay.getScopeGroupId()">
<input align="absmiddle" border="0" src="/theme/images/common/search.png" title="Search" type="image">
</form>
#parse ("$full_templates_path/search.vm")
#set ($searchPortletId = "3")
#set ($prefsVersion = "1")
#set ($portletPreferencesService = $serviceLocator.findService('com.liferay.portal.service.PortletPreferencesLocalService'))
#set ($companyId = $getterUtil.getLong($companyId))
#set ($ownerId = 0) ## PortletKeys.PREFS_OWNER_ID_DEFAULT
#set ($ownerType = 3) ## PortletKeys.PREFS_OWNER_TYPE_LAYOUT
#set ($portletPreferences = $portletPreferencesService.getPreferences($companyId, $ownerId, $ownerType, $layout.getPlid(), $searchPortletId))
#if ($portletPreferences != "" &&
$portletPreferences.class.name == "com.liferay.portlet.PortletPreferencesImpl")
#set ($storedVersion = $portletPreferences.getValue('version', '0'))
#if ($storedVersion != $prefsVersion)
#set ($VOID = $portletPreferences.setValue("advancedConfiguration", "true"))
#set ($VOID = $portletPreferences.setValue("searchConfiguration", "{'facets': [{'displayStyle': 'scopes','weight': 1.6,'static': false,'order': 'OrderHitsDesc','data': {'maxTerms': 10,'frequencyThreshold': 1,'showAssetCount': true},'label': 'site','className': 'com.liferay.portal.kernel.search.facet.ScopeFacet','fieldName': 'groupId'},{'displayStyle': 'asset_entries','weight': 1.5,'static': false,'order': 'OrderHitsDesc','data': {'values': ['com.liferay.portlet.bookmarks.model.BookmarksEntry','com.liferay.portlet.bookmarks.model.BookmarksFolder','com.liferay.portlet.blogs.model.BlogsEntry','com.liferay.portlet.documentlibrary.model.DLFileEntry','com.liferay.portlet.documentlibrary.model.DLFolder','com.liferay.portlet.journal.model.JournalArticle','com.liferay.portlet.journal.model.JournalFolder','com.liferay.portlet.messageboards.model.MBMessage','com.liferay.portlet.wiki.model.WikiPage'],'frequencyThreshold': 1},'label': 'asset-type','className': 'com.liferay.portal.kernel.search.facet.AssetEntriesFacet','fieldName': 'entryClassName'},{'displayStyle': 'asset_tags','weight': 1.4,'static': false,'order': 'OrderHitsDesc','data': {'maxTerms': 10,'displayStyle': 'list','frequencyThreshold': 1,'showAssetCount': true},'label': 'tag','className': 'com.liferay.portal.kernel.search.facet.MultiValueFacet','fieldName': 'assetTagNames'},{'displayStyle': 'asset_categories','weight': 1.3,'static': false,'order': 'OrderHitsDesc','data': {'maxTerms': 10,'displayStyle': 'list','frequencyThreshold': 1,'showAssetCount': true},'label': 'category','className': 'com.liferay.portal.kernel.search.facet.MultiValueFacet','fieldName': 'assetCategoryIds'},{'displayStyle': 'folders','weight': 1.2,'static': false,'order': 'OrderHitsDesc','data': {'maxTerms': 10,'frequencyThreshold': 1,'showAssetCount': true},'label': 'folder','className': 'com.liferay.portal.kernel.search.facet.MultiValueFacet','fieldName': 'folderId'},{'displayStyle': 'modified','weight': 1,'static': false,'order': 'OrderHitsDesc','data': {'ranges': [{'range': '[past-hour TO *]','label': 'past-hour'},{'range': '[past-24-hours TO *]','label': 'past-24-hours'},{'range': '[past-week TO *]','label': 'past-week'},{'range': '[past-month TO *]','label': 'past-month'},{'range': '[past-year TO *]','label': 'past-year'}],'frequencyThreshold': 0},'label': 'modified','className': 'com.liferay.portal.kernel.search.facet.ModifiedFacet','fieldName': 'modified'}]}"))
#set ($VOID = $portletPreferences.setValue("portlet-setup-show-borders", "false"))
#set ($VOID = $portletPreferences.setValue("version", $prefsVersion))
#set ($VOID = $portletPreferences.store())
#end
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment