cancel
Showing results for 
Search instead for 
Did you mean: 

change search results data

fuad_gafarov
Champ in-the-making
Champ in-the-making
I need put my custom model data (ex. tc:index) in search results.


I read
https://forums.alfresco.com/en/viewtopic.php?f=47&t=27052

Warning: index - my variable
I've apply:

1. add index to getDocumentItem function
\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\slingshot\search\search.lib.js



         item =
         {
            site: getSiteData(siteId),
            container: containerId,
            nodeRef: node.nodeRef.toString(),
            tags: ((t = node.tags) !== null) ? t : [],
            name: node.name,
            displayName: node.name,
            title: node.properties["cm:title"],
            description: node.properties["cm:description"],
            modifiedOn: node.properties["cm:modified"],
            modifiedByUser: node.properties["cm:modifier"],
       index: "test",
            createdOn: node.properties["cm:created"],
            createdByUser: node.properties["cm:creator"],
            path: pathParts.join("/")
         };

WarningSmiley Frustratedtill I've change my model variable to simple string "test"


2. add index to json
\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\slingshot\search\search.get.json.ftl


   "items":
   [
      <#list data.items as item>
      {
         "nodeRef": "${item.nodeRef}",
         "type": "${item.type}",
         "name": "${item.name!''}",
         "displayName": "${item.displayName!''}",
         <#if item.title??>
         "title": "${item.title}",
         </#if>
         "description": "${item.description!''}",
         "modifiedOn": "<@dateFormat item.modifiedOn />",
         "modifiedByUser": "${item.modifiedByUser}",
         "modifiedBy": "${item.modifiedBy}",
         "size": "${item.size?c}",
         "index": "${item.index}",
         <#if item.site??>
         "site":
         {
            "shortName": "${item.site.shortName}",
            "title": "${item.site.title}"
         },
         "container": "${item.container}",
         </#if>
         <#if item.path??>
         "path": "${item.path}",
         </#if>
         "tags": [<#list item.tags as tag>"${tag}"<#if tag_has_next>,</#if></#list>]
      }<#if item_has_next>,</#if>
      </#list>
   ]


3. show index in results
\tomcat\webapps\share\components\search\search_print-min.js
Warning: search_print-min.js - my own created file. Exact copy of search-min.js


if (oRecord.getData("modifiedBy"))
            {
               desc += ' ' + me.msg("message.modifiedby");
               desc += ' <a href="' + Alfresco.constants.URL_PAGECONTEXT + 'user/' + encodeURI(oRecord.getData("modifiedByUser")) + '/profile">' + $html(oRecord.getData("modifiedBy")) + '</a>';
            }
         
if (oRecord.getData("index"))
            {
               desc += ' ' + me.msg("index");
               desc += ' ' + $html(oRecord.getData("index")) + '';
            }

But it got error - 00230002 Wrapped Exception (with status template): 00230003 Error during processing of the template 'Expression jsonUtils.encodeJSONString(x) is undefined on line 2, column 15 in org/alfresco/slingshot/search/search.get.json.ftl.'. Please contact your system administrator.


Why? Maybe I've added index variable somewhere in table definition?
On link which I leave - talking about fields array in search.min-js - but in my search-min - haven't that array

Maybe I am using search_print.min.js - instead of search.min.js ?
10 REPLIES 10

need
Champ in-the-making
Champ in-the-making
hello all,

I solved by leaving the changes in the original directory, but do not think is a good way.