cancel
Showing results for 
Search instead for 
Did you mean: 

Customise Share search results

benarrayx
Champ in-the-making
Champ in-the-making
Hi there, I'm trying to modfiy my Share search results in order to display a custom metadata field. I can see there are 2 steps:

1. modify tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.get.json.ftl in order to send the metadata value via JSON
2. modify tomcat/webapps/share/components/search/search.js in order to display the returned field.

The metadata I want to return is contained in a custom aspect:

<aspect name="trc:statusA">
         <title>Document status</title>
         <properties>
            <property name="trc:status">
               <type>d:text</type>
               <constraints>
                  <constraint ref="trc:statusC" />
               </constraints>
            </property>
         </properties>
      </aspect>

In step 1, I've added the following code:

         <#if item.trc:status??>
         "status": "${item.trc:status}",
         </#if>

However, this generates an error:

Caused by: freemarker.core.ParseException: Encountered ":" at line 22, column 38 in org/alfresco/slingshot/search/search.get.json.ftl.
Was expecting one of:
    ">" …
    "." …
    "[" …
    "(" …
    "?" …
    "!" …
    <TERMINATING_EXCLAM> …
    "??" …
    "+" …
    "-" …
    "*" …
    "/" …
    "%" …
    "!=" …
    "=" …
    "==" …
    ">=" …
    <ESCAPED_GTE> …
    ">" …
    <ESCAPED_GT> …
    <LESS_THAN_EQUALS> …
    <LESS_THAN> …
    ".." …
    <AND> …
    <OR> …

This is clearly because I have referred to the property as trc:status, and it doesn't like the colon. However, how else can I refer to it?

AHA, Ben
14 REPLIES 14

benarrayx
Champ in-the-making
Champ in-the-making
For reference, I've also tried:

- item.status - never shows any data
- item.properties["trc:status"] - throws error "Expression item.properties is undefined"

Cheers, Ben

tommorris
Champ in-the-making
Champ in-the-making
Hi there.

You've found the correct webscript, but you need to modify a bit more. The 'item' javascript object is a regular javascript data-object (aka 'value object' or 'data transfer object') and not the alfresco-node object that you're expecting.

Have a look at the JS file that accompanies the FTL (alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.get.js)… you'll see that it includes the following JS file: alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js. Modify this file. In particular, look for the function 'getDocumentItem' and all will become clear.

Tom
http://www.ixxus.com

benarrayx
Champ in-the-making
Champ in-the-making
Hi Tom, many thanks for that.

I added my property to the js object created in getDocumentItem, as follows:

trcStatus: (node.hasAspect("trc:statusA")) ? node.properties["trc:status"] : ""

However, this never returns anything, regardless or not if the document has the aspect. I also tried adding a static property:

item.ben = "ben";

If I try and output this in search.get.json.ftl:

"ben": "${item.ben}"

I get an error telling me "jsonUtils.encodeJSONString(x) is undefined". I figured out this was probably because the property was null/empty, so wrapped it as follows:

"ben": "<#if item.ben??>${item.ben}</#if>"

which stops the error, but the output is always empty. It seems as though the changes I'm making to webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js aren't getting carried through to search.get.json.ftl.

Can you offer me any further advice?

Regards, Ben

benarrayx
Champ in-the-making
Champ in-the-making
Ah, seems like a restart of Alfresco was required to get the new data coming through - I assumed since it was javascript it would be interpreted on the fly, clearly not the case!!

Anyway, all working good now, thanks for the help Tom Smiley Happy

Ben

kyriakos
Champ in-the-making
Champ in-the-making
benArrayX so you managed to customise share search to lookup in custom metadata-aspects?

benarrayx
Champ in-the-making
Champ in-the-making
Hi kyriakos, I didn't modify the search to search in custom metadata fields, only to output the values of a custom metadata field in the search results.

1 final step not mentioned here is that you need to edit /webapps/share/components/search/search.js to include your custom field in the definition. In the Search_onReady function:

fields: ["nodeRef", "type", "name", "displayName", "description",
                      "modifiedOn", "modifiedByUser", "modifiedBy", "size",
                      "title", "browseUrl", "trcStatus", "site", "tags"]

(I added the trcStatus field), and then modify the output in the Search_renderCellDescription function:

if (status !== undefined && status !== '')
            desc += '<br />Status: ' + status;
         else
            desc += '<br />Status: Unknown / incorrect document type';

Cheers, Ben

kyriakos
Champ in-the-making
Champ in-the-making
So Ben i other words, you have created a custom metadata field, you put let's say the value " dog" in that field then you go to search and write "dog" and you have a result? with these changes?

tommorris
Champ in-the-making
Champ in-the-making
Hi Ben. Sorry for the late reply.
yes, sorry - I forgot to mention the 'fields' thing…

benarrayx
Champ in-the-making
Champ in-the-making
Hi kyriakos, that is not the case. This topic is not about searching custom meta-data fields, it's about displaying the contents of custom meta-data fields in search results. I am not searching custom fields, AFAIK that's not possible but is in the roadmap.

Cheers, Ben