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

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Hi,

As the error says, it's complaining about jsonUtils.encodeJSONString(x), can you post the entire FTL file that uses that expression?

Regards,
Adei

fuad_gafarov
Champ in-the-making
Champ in-the-making
sure
search.get.json.ftl

<#macro dateFormat date>${date?string("dd MMM yyyy HH:mm:ss 'GMT'Z '('zzz')'")}</#macro>
<#escape x as jsonUtils.encodeJSONString(x)>
{
   "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>
   ]
}
</#escape>

mikeh
Star Contributor
Star Contributor
You'll get an error unless *every* node that passes through that Freemarker script has the "index" property.

Simply add
<#if item.index??>
around it, or
${item.index!""}
if you'd prefer it to always be in the result set.

Thanks,
Mike

fuad_gafarov
Champ in-the-making
Champ in-the-making
I add

${item.index!""}
also add

<#if item.index??>
but index -result not shown. All other default results shows.
Why?
in search.lib.js I add

         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("/")
         };

so anyway index must show - test.

Why haven't work?
May be I create my own search_print-min.js - instead of search-min.js ?


I try to create print version of search results. Other easy way?

mikeh
Star Contributor
Star Contributor
- Exactly which part of search.lib.js have you altered - are you sure it's the correct part?

- Have you tried using the Rhino debugging tool [1] to check the line of code you expect to be run is actually run?
[1] http://<server>:8080/alfresco/service/index and look for the debugger there.

- Have you checked the JSON response directly from a web browser rather than more custom code?

It's always good to check each step when developing and give the whole picture when looking for help - that's good general advice, which doesn't just apply to Alfresco!

Thanks,
Mike

fuad_gafarov
Champ in-the-making
Champ in-the-making
Tnx for advice.

- Exactly which part of search.lib.js have you altered - are you sure it's the correct part?
getDocumentItem - function

- Have you tried using the Rhino debugging tool [1] to check the line of code you expect to be run is actually run?
On Rhino launch - it makes error. - No X11 DISPLAY variable was set - It needs swing (Learn in your previous posts). I've trying to put swing. OS - CentOS 5.7 with KDE

- Have you checked the JSON response directly from a web browser rather than more custom code?
Sorry I've never working with json This is very painfull for me.  How I can check JSON response? write template please.

Thank you for your help.

mikeh
Star Contributor
Star Contributor
Sorry I've never working with json This is very painfull for me.  How I can check JSON response? write template please.
You can use Firebug for Firefox, or WebInspector for Chrome/Safari to check which webscript URL is being requested via AJAX. Then just open that same URL in your browser directly.

Thanks,
Mike

fuad_gafarov
Champ in-the-making
Champ in-the-making
Thanks, I've used firebug.

This is response

{
   "items":
   [
      {
         "nodeRef": "workspace:\/\/SpacesStore\/21dab966-48f6-4f45-833b-a3324d600568",
         "type": "document",
         "name": "Alfresco.txt",
         "displayName": "Alfresco.txt",
         "title": "Alfresco.txt",
         "description": "",
         "modifiedOn": "19 Oct 2011 11:14:49 GMT+0500 (AZST)",
         "modifiedByUser": "hicran.valehov",
         "modifiedBy": "Hicran Valehov",
         "size": "14",
         "index": "",
         "path": "\/Company Home\/user_homes\/seadet_eliyeva\/Daxil Olan S\u0259n\u0259dl\u0259rin Qeydiyyat\u0131",
         "tags": ["baki dair\u0259vi"]
      }
   ]
}

index is empty. And 2 other javascript errors in response in my modified search_print-min.js (this._button is undefined and Dom.get(this.id + "-search-info") is null)

But why? In search.lib.js - getDocumentItem I was defining index - to test string.


function getDocumentItem(siteId, containerId, pathParts, node)
{
   var cat = siteId + containerId, refkey = "" + node.nodeRef.toString();
   if (checkProcessed(cat, refkey))
   {
      return null;
   }
   addToProcessed(cat, refkey);
  

   var item = t = null;
   if (node.qnamePath.indexOf(COMMENT_QNAMEPATH) == -1)
   {
      if (node.isContainer || node.isDocument)
      {
         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("/")
         };
         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;
}

Why it not take that string?

need
Champ in-the-making
Champ in-the-making
Hi,

i have the same problem, have you solved?

I test this solution on Alfresco share 4.0b, i've read the output response by firebug and i not see the custom properties…