I am able to customize the search result list in alfresco 5.2 with Aikau by adding the following to a Share Amp:
- create src/main/amp/config/alfresco/web-extension/site-data/extensions/search-results-extension.xml
<extension>
<modules>
<module>
<id>Search Results Add Created Date</id>
<auto-deploy>true</auto-deploy>
<customizations>
<customization>
<targetPackageRoot>org.alfresco.share.pages.faceted-search</targetPackageRoot>
<sourcePackageRoot>com.mine.content.alfresco.pages.faceted-search</sourcePackageRoot>
</customization>
</customizations>
</module>
</modules>
</extension>
- create /src/main/amp/config/alfresco/web-extension/site-webscripts/com/mine/content/alfresco/pages/faceted-search/faceted-search.get.js
var fctSearchRes = widgetUtils.findObject(model.jsonModel.widgets, "id", "FCTSRCH_SEARCH_RESULT");
fctSearchRes.config.widgetsBelow = [{
name: "alfresco/renderers/Date",
config: {
propertyToRender: "created",
simple: true,
label: msg.get("label.created"),
renderSize: "medium"
}
}];
This places the value created date at the bottom of the attributes listed in the search result elements.
If i want to include a custom attribute, I assume that i will need to explicitly include it as part of the item in the search result, though I am not sure if the changes to 5.2 make all of the items attributes available, or whether I need to override / extend search.get.json.ftl. In either case, I am unable to get my custom attribute to show up in the result list.
Any thoughts on how to get this to work?
Thanks!
Solved! Go to Solution.
You cannot only override the search.lib.js via the extension path - you have to override the search.get.js as well and adjust the import path. Imports are always absolute in default Alfresco and will not check for any overrides in extension.
The Alfresco faceted-search will never show any custom properties / attributes on search result items unless the search.get.json.ftl is overriden to include these additional data elements. Nothing has changed in that regard in Alfresco 5.2 since Alfresco currently only invests the bare minimum in Share enhancements/functionality (ADF and ReST API are clear areas of focus, and if you look at the Aikau project on GitHub you'll see that any development on it has effectively stopped this year). Unfortunately, that web script template has not been designed to be easily customised, so a fully copy+change is necessary. Additionally, there can only be one override, e.g. it is not possible for multiple, independent add-ons to make minor additions to the results in parallel.
Thanks Axel!
So i would override / copy the search.lib.js and add my attribute to the item array in the getDocumentItem function like:
....
var item = t = null;
if (node.isContainer || node.isDocument)
{
if (!populate) return {};
item =
{
site: getSiteData(siteId),
container: containerId,
nodeRef: node.nodeRef.toString(),
tags: ((t = node.tags) !== null) ? t : [],
name: node.name,
displayName: highlighting["cm:name"] ? highlighting["cm:name"].get(0) : node.name,
title: highlighting["cm:title"] ? highlighting["cm:title"].get(0) : node.properties["cm:title"],
description: highlighting["cm:description"] ? highlighting["cm:description"].get(0) : node.properties["cm:description"],
modifiedOn: node.properties["cm:modified"],
modifiedByUser: node.properties["cm:modifier"],
createdOn: node.properties["cm:created"],
createdByUser: node.properties["cm:creator"],
documentDate: node.properties["my:document_date"],
lastThumbnailModification: node.properties["cm:lastThumbnailModification"],
mimetype: node.mimetype,
path: pathParts.join("/"),
nodeJSON: appUtils.toJSON(node, true)
};
item.modifiedBy = getPersonDisplayName(item.modifiedByUser);
item.createdBy = getPersonDisplayName(item.createdByUser);
}......
(bolded part added), which will make it available for me to reference in the search.get.json.ftl by doing something like:
....
"node": <#noescape>${item.nodeJSON}</#noescape>,
"nodeRef": "${item.nodeRef}",
"type": "${item.type}",
"name": "${item.name!''}",
"displayName": "${item.displayName!''}",
<#if item.title??>
"title": "${item.title}",
</#if>
"description": "${item.description!''}",
"modifiedOn": "${xmldate(item.modifiedOn)}",
"modifiedByUser": "${item.modifiedByUser}",
"modifiedBy": "${item.modifiedBy}",
"fromDate": "${xmldate(item.fromDate)}",
"size": ${item.size?c},
"mimetype": "${item.mimetype!''}",
<#if item.site??>
"site":
{
"shortName": "${item.site.shortName}",
"title": "${item.site.title}"
},
"container": "${item.container}",
</#if>
<#if item.path??>
"path": "${item.path}",
</#if>
<#if item.documentDate??>
"documentDate": "${item.documentDate}",
</#if>
"lastThumbnailModification":
[
<#if item.lastThumbnailModification??>
<#list item.lastThumbnailModification as lastThumbnailMod>
"${lastThumbnailMod}"
<#if lastThumbnailMod_has_next>,</#if>
</#list>
</#if>
],......
(bolded part added).
This should allow me to reference it in the aikau 'faceted-search.get.js' code, right?
For some reason i am not seeing the custom attribute listed...am i missing something?
Thanks!
Dan
I can trace it as far back as the 'search.get.json.ftl'... If I have the code of
<#if item.staticTest??>
"staticTest": "${item.staticTest}",
<#else>
"staticTest": "staticTestEmpty",
</#if>
, I get the else condition value that shows in the aikau widget / search result page. So that sounds like the .js file that is adding the staticTest value to the item object is not getting picked up.
The slightly modified search.lib.js function 'getDocumentItem' is:
function getDocumentItem(siteId, containerId, pathParts, node, populate, highlighting)
{
// PENDING: how to handle comments? the document should
// be returned instead// check whether we already processed this document
if (checkProcessedCache("" + node.nodeRef.toString()))
{
return null;
}// check whether this is a valid folder or a file
var item = t = null;
if (node.isContainer || node.isDocument)
{
if (!populate) return {};
item =
{
logger.warn("search.lib.js, in getDocumentItem: node modifier: " + node.properties["cm:modifier"]);
logger.warn("search.lib.js, in getDocumentItem: documentDate: " + node.properties["osp:document_date"]);
site: getSiteData(siteId),
container: containerId,
nodeRef: node.nodeRef.toString(),
tags: ((t = node.tags) !== null) ? t : [],
name: node.name,
displayName: highlighting["cm:name"] ? highlighting["cm:name"].get(0) : node.name,
title: highlighting["cm:title"] ? highlighting["cm:title"].get(0) : node.properties["cm:title"],
description: highlighting["cm:description"] ? highlighting["cm:description"].get(0) : node.properties["cm:description"],
modifiedOn: node.properties["cm:modified"],
modifiedByUser: node.properties["cm:modifier"],
createdOn: node.properties["cm:created"],
createdByUser: node.properties["cm:creator"],
staticTest: node.properties["cm:creator"],
lastThumbnailModification: node.properties["cm:lastThumbnailModification"],
mimetype: node.mimetype,
path: pathParts.join("/"),
nodeJSON: appUtils.toJSON(node, true)
};
item.modifiedBy = getPersonDisplayName(item.modifiedByUser);
item.createdBy = getPersonDisplayName(item.createdByUser);
}
if (node.isContainer)
{
item.type = "folder";
item.size = -1;
}
else if (node.isDocument)
{
item.type = "document";
item.size = node.size;
}return item;
}
, so I feel like I am either modifying the wrong function, or the changed js is not getting picked up.
FWIW, I am adding the search js and ftl to an alfresco amp in the folder '/config/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search'
You cannot only override the search.lib.js via the extension path - you have to override the search.get.js as well and adjust the import path. Imports are always absolute in default Alfresco and will not check for any overrides in extension.
Rats... I missed that.. I was including the search.lib.js in my amp, and I have been staring at the import statement and missed that it did not have the 'extension' portion of the classpath.
Thanks again for your help!
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.