AnsweredAssumed Answered

change search results data

Question asked by fuad_gafarov on Jan 23, 2012
Latest reply on Mar 6, 2012 by need
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("/")
         };

Warning:Still 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 ?

Outcomes