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

kyriakos
Champ in-the-making
Champ in-the-making
thanx ben for the answer Smiley Very Happy

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

You can modify the process that constructs the lucene query that dictates the search if you like.

You can copy the js library included in the alfresco-side webscript that conducts this search: ''search.lib.js" and move it to the extension directory, and then modify it.
(alfresco\WEB-INF\classes\alfresco\extension\templates\webscripts\org\alfresco\slingshot\search\search.lib.js)

Then change this function: "getSearchResults", where you can see what you'll need to change.

Tom
http://www.ixxus.com

pablog_
Champ in-the-making
Champ in-the-making
Hi four years later!!, now, in alfresco 4.2, the function "Search_onReady" don't have "fields:" property, I have made all the changes that your say in the post and the output retrieve the next exception:


search.lib.js: Skipping node due to exception when processing query result: TypeError: properties is not a function, it is org.alfresco.repo.jscript.ContentAwareScriptableQNameMap.


Thanks!

gdey
Champ in-the-making
Champ in-the-making
Hi
  I am trying to add new functionality to the search , I followed this blog and did the following
extension-modules.xml
<blockcode>
<extension>
  <modules>
    <module>
      <id>Test Custom Search</id>
      <version>1.0</version>
      <customizations>
        <customization>
          <targetPackageRoot>org.alfresco.components.search</targetPackageRoot>
          <sourcePackageRoot>tutorials</sourcePackageRoot>
        </customization>
      </customizations>
      <auto-deploy>true</auto-deploy>
    </module>
   
  </modules>
</extension>

</blockcode>

search.get.html.ftl

<blockcode>
<@markup id="custom-search-dependencies" target="js" action="after" scope="global">
   <#– JavaScript Dependencies –>
   <!–<@script src="${url.context}/scripts/custom-search.js" group="search"/>–>
   <!–<@script src="http://localhost:9080/share/scripts/custom-search.js" group="search"/>–>
   <@script src="${url.context}/res/scripts/custom-search.js" group="search"/>
</@>
</blockcode>

search.get.js
<blockcode>
// Find the default DocumentList widget and replace it with the custom widget
for (var i=0; i<model.widgets.length; i++)
{
  if (model.widgets.id == "Search")
  {
    model.widgets.name = "Test.Search";
  }
}
</blockcode>
custom-search.js
<javascript>
// Declare namespace…
if (typeof Test == undefined || !Test) { var Test = {}; }
if (!Test.Search) { Test.Search = {}; }
(function()
{
   /**
    * YUI Library aliases
    */
   var Dom = YAHOO.util.Dom,
       Event = YAHOO.util.Event;

   /**
    * Alfresco Slingshot aliases
    */
   var $html = Alfresco.util.encodeHTML;

   /**
    * Search constructor.
    *
    * @param {String} htmlId The HTML id of the parent element
    * @return {Test.Search} The new Search instance
    * @constructor
    */
   Test.Search = function(htmlId)
   {
      Alfresco.util.PopupManager.displayMessage({
           text: "Inside constructor !"
         });
      Test.Search.superclass.constructor.call(this, htmlId);
     
      // Decoupled event listeners
      YAHOO.Bubbling.on("onSearch", this.onSearch, this);
     
      return this;
   };
  
   YAHOO.extend(Test.Search, Alfresco.Search,
   {
           
     
      /**
       * Click event for Repository search link
       *
       * @method onRepositorySearch
       */
      onRepositorySearch: function Search_onRepositorySearch(e, args)
      {
       
         Test.Search.superclass.Search_onRepositorySearch(e,args);
         // Pop-up a message…
          Alfresco.util.PopupManager.displayMessage({
            text: "Change added"
          });
 
      }
   });
})();

</javascript>

I created a share amp project and placed the custom-search.js under src/main/resource/script/custom-search.js

The search stopped working because it cant find the custom-search.js . On a debug mode java console I can see
GET http://localhost:9080/share/res/share/scripts/custom-search.js 404 (Not Found)


I tried different option with the @script but it keep complaining , not sure how it is finding two share.

Could not get the example to work.
thanks
Gautam

anotheralfresco
Champ in-the-making
Champ in-the-making
Gautam,
Were you able to get your example to work? I am trying to do the same thing and I am not able to get it to work either. If you got it to work, can you post your solution.
Thanks