Adding Views to Filtered Search

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Views to Filtered Search

Intermediate II
4 49 13.1K

Introduction

One of the Alfresco Solutions Engineers recently contacted me to ask how easy it would be to add a table view into the new filtered search page in Alfresco 5.0. Fortunately this page is built using the Aikau framework, so this is actually an incredibly easy task to accomplish. This blog will take you through the process. If you have trouble following the steps or just want to try it out then download the example extension module from here.

Extension Module Creation

The best practice to customizing Alfresco Share is to first create an extension module, and for Aikau pages this is a very straightforward process. First of all ensure that Share is running in “client-debug” mode.

Now login to Share and perform a search so that the filtered search page is displayed.

Filtered search page

Open the “Debug” drop-down menu and select “Toggle Developer View

Debug Menu

You should see a page that looks like this:

Developer View

Now click on the link at the very top of the page that says “Click to generate extension JAR”. This will generate a JAR file containing all files required to customize the filtered search page.

Unpack the JAR file and open the “/alfresco/site-webscripts/org/alfresco/share/pages/faceted-search/customization/faceted-search.get.js” file in your editor of choice.

Now go back to the filtered search page (still in developer view) and click on the info icon for the main list. It should display a tooltip indicating that the widget selected has an id of “FCTSRCH_SEARCH_RESULTS_LIST”.

Selecting the Search List

Copy the “Find Widget Code Snippet”, it should be:

widgetUtils.findObject(model.jsonModel.widgets, 'id', 'FCTSRCH_SEARCH_RESULTS_LIST');

Paste this into the “faceted-search.get.js” file that is open in your editor. This snippet of code is all you need to target a widget on an Aikau page (obviously each snippet of code is different for each widget on the page), and in this case you have targeted the main search results list.

Understanding the extension

Lists in Aikau are used to manage data and delegate the rendering of that data to one or more views . We want to add an additional view into the search page.

There is lots of information in the Aikau tutorial on creating views, so I'm not going to repeat that information here, but if you're not familiar with defining a list then you should certainly work your way through the tutorial.

To add a new view you just need to “push” a new widget declaration into the “widgets” array of the search lists “config” object. You can create any view you like, but as a relatively simple example you could create the following (this would be the complete contents of the faceted-search.get.js file):

var widget = widgetUtils.findObject(model.jsonModel.widgets, 'id', 'FCTSRCH_SEARCH_RESULTS_LIST');
if (widget && widget.config && widget.config.widgets)
{
   widget.config.widgets.push({
      name: 'alfresco/documentlibrary/views/AlfSearchListView',
      config: {
         viewSelectionConfig: {
            label: 'Table View',
            iconClass: 'alf-tableview-icon'
         },
         widgetsForHeader: [
            {
               name: 'alfresco/documentlibrary/views/layouts/HeaderCell',
               config: {
                  label: 'Name'
               }
            },
            {
               name: 'alfresco/documentlibrary/views/layouts/HeaderCell',
               config: {
                  label: 'Description'
               }
            }
         ],
         widgets: [
            {
               name: 'alfresco/search/AlfSearchResult',
               config: {
                  widgets: [
                     {
                        name: 'alfresco/documentlibrary/views/layouts/Row',
                        config: {
                           widgets: [
                              {
                                 name: 'alfresco/documentlibrary/views/layouts/Cell',
                                 config: {
                                    additionalCssClasses: 'mediumpad',
                                    widgets: [
                                       {
                                          name: 'alfresco/renderers/SearchResultPropertyLink',
                                          config: {
                                             propertyToRender: 'displayName'
                                          }
                                       }
                                    ]
                                 }
                              },
                              {
                                 name: 'alfresco/documentlibrary/views/layouts/Cell',
                                 config: {
                                    additionalCssClasses: 'mediumpad',
                                    widgets: [
                                       {
                                          name: 'alfresco/renderers/Property',
                                          config: {
                                             propertyToRender: 'description'
                                          }
                                       }
                                    ]
                                 }
                              }
                           ]
                        }
                     }
                  ]
               }
            }
         ]
      }
   });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

We're pushing in a new 'alfresco/documentlibrary/views/AlfDocumentListView' that uses the table view icon ('alf-tableview-icon'), has a label of “Table View” (which we could have localized if we wanted) and a value of “table”.

The view has two header cells (for name and description) and each item in the list is rendered as an 'alfresco/documentlibrary/views/layouts/Row' widget containing two 'alfresco/documentlibrary/views/layouts/Cell' widgets.

The first cell contains 'alfresco/renderers/SearchResultPropertyLink' that renders the “displayName” of the item and the second is a simple 'alfresco/renderers/Property' that renders the description.

Testing out the view

Re-package the extension files as a JAR file, copy that JAR file into the “share/WEB-INF/lib” folder and then restart the server. When you perform a search you should see your table view as an option.

Selecting the view

Selecting the table view will show the search results as:

Search Table View

You can add more columns to your table view, but it's important to understand that the API used on the search page only retrieves a very small set of Node data. The data that is available for each node found is:

    • displayName
    • description
    • mimetype
    • modifiedBy (user display name)
    • modifiedByUser (username)
    • modifiedOn
    • name
    • title
    • nodeRef
    • path (within a site)
    • site (if the node is in a site)
    • size (in bytes)
    • tags
    • type (e.g. “document”)


If you want to display more than than this limited set of data then there are a couple of options available.

One approach that you could take is to use the “alfresco/documentlibrary/views/layouts/XhrLayout” widget that allows an initial version of the view to be rendered for an item (using the limited data set) and when that item is clicked the full node data is requested and the “full” view is then rendered using that data. However, this widget is only a prototype and should only be used as an example.

Another option would be to extend the “alfresco/documentlibrary/AlfSearchList” widget to request the full data for each node before the view is rendered. This would naturally slow down the rendering of search results but would allow you to display any of the data available for that node.

Deprecations

The example used in this blog will work on 5.0, but you should be aware that some of the widgets referenced have now been deprecated in later versions of Alfresco. The deprecated widgets won't be removed for a long time, but if you’re customizing 5.0.1 onwards then you should look to use the latest versions. All deprecations are listed in the release notes for Aikau.

49 Comments
Active Member
Very nice and easy to do. This shows the power of Aikau!
Active Member
'Another option would be to extend the “alfresco/documentlibrary/AlfSearchList” widget to request the full data for each node before the view is rendered. This would naturally slow down the rendering of search results but would allow you to display any of the data available for that node.'



I'm trying to show a custom property in the list of search results, but does not show me the value of that custom property



I added



                     {

                        name: 'alfresco/documentlibrary/views/layouts/Cell',

                        config: {

                           additionalCssClasses: 'mediumpad',

                           widgets: [

                              {

                                 name: 'alfresco/renderers/Property',

                                 config: {

                                    propertyToRender: 'node.properties.kbSmiley Surprisedrigen',

         warnIfNotAvailable: true,

                                    warnIfNoteAvailableMessage: 'no.title.message'

                                 }

                              }

                           ]

                        }

                     }



in custom view.
Intermediate II
@Manuel - the reason for this is that the search API does not return all the properties - you've included my comment about this, so I just want to check whether or not you've actually changed the underlying search REST API. The reason why only a small amount of data is returned is that it makes searching faster. To see exactly what properties are returned on the search REST API you can use a web development tool in your browser and view the XHR tab.
Active Member
Ok, How to modify REST API and where?



I've never changed REST API.
Intermediate II
@Manuel - it's a WebScript on the Alfresco Repository. You'll need to replace it with your own API that provides the additional data that you're interested in.
Active Member
Can u give an example?

or maybe can u give another option? to show the custom property.



Thanks
Active Member
Thanks for this example. What I need in the table view is just a column that contains select options (either select boxes or - in my case - option boxes) for the documents. The user should be able to select a document from the table and do some further action with it by clicking a menu item. However, for simplification the column can also just contain an AlfButton for each row that do some action (like adding an aspect to the document where the button was clicked).

I tried to get it working by checking out the API for

http://dev.alfresco.com/resource/docs/aikau-jsdoc/AlfDynamicPayloadButton.html

http://dev.alfresco.com/resource/docs/aikau-jsdoc/AlfButton.html

but I wasn't able to run it. I don't know how to pass the current NodeRef of each row to the button and execute just a JavaScript after click on the button.

Do you has an approach how I can solve that?
Intermediate II
What exactly do you want an example of?
Intermediate II
@Mario - We do have widgets for handling multiple selection items (see alfresco/documentlibrary/AlfSelectedItemsMenuBarPopup) and a renderer for publishing selection information (see alfresco/renderers/Selector). You can see how these are used in one of the pre-canned Document Library views (e.g. alfresco/documentlibrary/views/AlfSimpleView)
Active Member
I attempted to apply the provided example by downloading the Extension.jar, unpacking it with the 'jar' command, modifying the faceted-search.get.js file by copy/pasting in the code above and repackaging the 'alfresco' folder with the 'jar' command again. This new Extension.jar file was copied into our Alfresco share/WEB-INF/lib folder. Our tomcat server was restarted. The result was that the 'Table View' does now show up in the list of views selectable from Advanced Search, but selecting it doesn't change the view and actually shows both the 'Detailed View' and the 'Table View' checked in the drop-down view list. We are running Alfresco 5.0.1 and I am aware you mentioned that some Deprecations have occurred. So, I also tried refactoring the example javascript code provided for faceted-search.get.js based on the , but got exactly the same testing results.



Any suggestions or caveats that may cause the code you pr...
Intermediate II
Have you tried this using a newer release of Aikau (see https://www.alfresco.com/blogs/developer/2015/03/24/why-alfresco-5-0-d-will-be-a-game-changer-for-ui...)?



Why are you repackaging the JAR file? I've not quite followed the reason for that? Does it not work just using the JAR as provided?
Active Member
To clarify,



I am repackaging the JAR because I was following the steps in the blog and reached the section that says 'Testing out the view'. The problem I was originally reporting turned out to be because the code inside the downloadable JAR file provided by this blog does not match the code that I copy/pasted from the code block in the blog section 'Understanding the extension'. I was assuming the steps in the blog article described how to make your own JAR file that matched the one that is downloadable. However, it turns out the steps in the blog article end up with a JAR file that I have yet to get to work.



I have had some success downloading the linked JAR file, unpackaging it, modifying the code to customize my own Search Result view and re-packaging.
Intermediate II
@Joshua - it sounds like there's an error in my post then that I need to correct - could you point me at the specific points that don't match? You say that you've had some success modifying the JAR  - does that mean you've been able to progress now or is there something else that needs to be resolved?
Active Member
The block of code in the blog directly beneath the quote that says '...following (this would be the complete contents of the faceted-search.get.js file):' is different than the same faceted-search.get.js file that is retrieve from unpackaging the download SearchView.jar file that is linked to by this blog article (at the very top) quoted '...download the example extension module from here.'



When I run 'diff' between these two blocks of code here is the diff results:



$ diff CodeFromBlogCodeBlock.js CodeFromUnpackagedJar.js

0a1,2

> // Add JavaScript to modify the JSON model for the page

>

5c7

       name: 'alfresco/documentlibrary/views/AlfDocumentListView',

9c11,12

             iconClass: 'alf-tableview-icon',

>             value: 'table'

27c30

                name: 'alfresco/documentlibrary/views/layouts/Row',

31c34

                         name: 'alfresco/documentlibrary/views/layouts/Cell',

32a36

>                            additionalCssClasses: 'mediumpad',

35c39

                                  name: 'alfresco/renderers/SearchResultPropertyLink',

37,45c41

<                                     additionalCssClasses: "mediumpad",

<                                     widgets: [

<                                        {

<                                           name: "alfresco/renderers/SearchResultPropertyLink",

<                                           config: {

<                                              propertyToRender: "displayName"

<                                           }

<                                        }

                                     propertyToRender: 'displayName'

47c43,51

                               }

>                            ]

>                         }

>                      },

>                      {

>                         name: 'alfresco/documentlibrary/views/layouts/Cell',

>                         config: {

>                            additionalCssClasses: 'mediumpad',

>                            widgets: [

49c53

                                  name: 'alfresco/renderers/Property',

51,59c55

<                                     additionalCssClasses: "mediumpad",

<                                     widgets: [

<                                        {

<                                           name: "alfresco/renderers/Property",

<                                           config: {

<                                              propertyToRender: "description"

<                                           }

<                                        }

                                     propertyToRender: 'description'

Active Member
Dave, Would you be able to point me to documentation or an example of how to extend/modify the search results to include my custom data fields?  I have found some references online to modifying the search.lib.js to do this but I am using the Alfresco Community 5 version and do not see the getDocumentItem method there to modify and have come up short searching for other options.  Any help you can provide is greatly appreciated.
Intermediate II
@Richard The majority of the REST APIs called from Share are WebScripts. This includes the search REST APIs. For Repository REST APIs you will need to override them by placing duplicate files in a location that appears earlier in the classpath (typically this is in the '/alfresco/extension/templates/webscripts' path). To identify which WebScript files you need to override, use browser developer tools to view the XHR requests, when searching you'll see this XHR path used: '/share/proxy/alfresco/slingshot/search/'... 'proxy/alfresco' indicates that the request is being routed directly to the Alfresco Repository. You can then browse by URI from the Repository (e.g. 'alfresco/service/index/uri/') and look for the REST API being used (e.g. /slingshot/search). Clicking on that link will provide the details of the WebScript - if you click on the link next to 'id' it will give you a breakdown of all the files as they currently are. You can copy/paste the original WebScript to the '/alfresco/extension/templates/webscripts' location and then make the modifications that you require. Unfortunately there is no easy way of extending existing REST APIs on the Repository as there is with Share. I hope this helps.
Active Member
I'd be very interested in this as well! which webscript does provide the default properties?
Active Member
Hi Dave,



I followed your blog post and I had issues with Alfresco 5.0.1 and Aikau 1.0.8.2.



To make it work I had to use this widget hierarchy :

alfresco/lists/views/AlfListView > alfresco/documentlibrary/views/layouts/Row > alfresco/documentlibrary/views/layouts/Cell



Instead of the one you mention in your post :

alfresco/documentlibrary/views/AlfSearchListView > alfresco/search/AlfSearchResult > alfresco/documentlibrary/views/layouts/Row



When I used the AlfSearchListView I didn't achieve to override the function 'getViewName' that returns the technical name of the view. Because of this it returned the name defined in AlfSearchListView.js 'detailed'. Thus, when choosing a view mode two modes were checked : 'Detailed View' and 'My custom view', displaying of the search results was not correct too.



Don't hesitate to contact me if you want further information or if you think I've made a mistake Smiley Happy



Vianney FAIVRE
Active Member
About using custom fields data in the table list, for alfresco 5.0.d :
1- Copy /tomcat/webapps/alfresco/WEB-INF/lib/alfresco-remote-api-5.0.d.jar extract to anyfoldername/
2- Copy anyfoldername/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js  and search.get.json.ftl
to /tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/
3- Edit search.lib.js and add your fields :

search.get.json.ftl:
....
coolField:node.properties['my:coolField'],
....
search.lib.js:
...
'coolField': '${item.coolField!''}',
...
Active Member
Hi Coshe



Can you please explain the steps as for me this is not working. My search has stopped working after this.
Active Member
Hi Neha,

Sorry, my mistake, the order of the files and the changes was inverted:



Just add  'coolField': '${item.coolField!''}' in the array on search.get.json.ftl file (where coolField is your field name). Try to copy one of the others values and then modify it :



File search.get.json.ftl:

....

[sourcecode language='javascript']

'items':

[

 

  {

   'nodeRef': '${item.nodeRef}',

   'type': '${item.type}',

   'name': '${item.name!''}',

   'displayName': '${item.displayName!''}',

  

   'title': '${item.title}',

  

   'description': '${item.description!''}',

   'modifiedOn': '${xmldate(item.modifiedOn)}',

   'modifiedByUser': '${item.modifiedByUser}',

   'modifiedBy': '${item.modifiedBy}',

   'size': ${item.size?c},

   'coolField': '${item.coolField!''}',

   'mimetype': '${item.mimetype!''}',

  

   'site':

   {

    'shortName': '${item.site.shortName}',

    'title': '${item.site.title}'

   },

   'container': '${item.container}',

  

  

   'path': '${item.path}',

  

   'lastThumbnailModification':

   [

   

   

    '${lastThumbnailMod}'

    ,

   

   

   ],

   'tags': ['${tag}',]

  },

 

],

[/sourcecode]

....





On search.lib.js:



....

[sourcecode language='javascript']

function getRepositoryItem(folderPath, node, populate)

{

   // check whether we already processed this document

   if (checkProcessedCache('' + node.nodeRef.toString()))

   {

      return null;

   }



   // check whether this is a valid folder or a file

   var item = t = null;

   if (node.isContainer || node.isDocument)

   {

      if (!populate) return {};

      item =

      {

         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'],

         createdOn: node.properties['cm:created'],

         createdByUser: node.properties['cm:creator'],

         lastThumbnailModification: node.properties['cm:lastThumbnailModification'],

         mimetype: node.mimetype,

         coolField:node.properties['my:coolField'],

         path: folderPath.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;

}

[/sourcecode]

...



If you have any problem please look at  tomcat/logs/catalina.out
Active Member
Hi Coshee,

     Thank for all the information provided till now.  Now I am able to get my 'custom field value'. Here My doubt is, how to append/show this custom value in search result and how can I achieve this?



Thanks in advance.
Active Member
[…] extension module for the faceted search page. The quickest way to do this is to follow the steps in this blog post to download an extension JAR file for the faceted search […]
Active Member
Thanks for your help!



I have another question for you, I hope that you can help me.



I have defined a new filter on custom property from the page: http://localhost:8080/share/page/dp/ws/faceted-search-config



It is correctly displayed inside the search resalt page, but there is a problem.

The custom property is composed by multiple words.

For example, its value could be:

- 'Corte d'appello'

- 'Corte di giustizia'

...

I need to filter by the complate phrase of custom property.

On the contrary, the filter split the phrase and display just single word.

As result, I can filter by:

- corte (2)

- d'appello (1)

- di (1)

- giustizia (1)



I have tried to write the value as single string, 'corte-di-giustizia', but it's worse!

With 'corte-di-giustizia' I can filter by:

- corte (1)

- di (1)

- giustizia (1)

- corte-di-giustizia (1)

- cortedigiustizia (1)



I'd like to filter by the complate value of the property and not by single word.



I have alfresco 5.0.



Thanks,

Giuseppe.
Active Member
Hi,



I used Alfresco Community Edition 5.1 and try to add table view into advance search by copy/paste above code on faceted-search.get.js.



but i could see only table header and detailed view as table content.



please help me.



var widget = widgetUtils.findObject(model.jsonModel.widgets, 'id', 'FCTSRCH_SEARCH_RESULTS_LIST');

if (widget && widget.config && widget.config.widgets)

{

   widget.config.widgets.push({

      name: 'alfresco/lists/views/AlfListView',

      config: {

         viewSelectionConfig: {

            label: 'Table View',

            iconClass: 'alf-tableview-icon',

   value: 'table'

         },

         widgetsForHeader: [

            {

               name: 'alfresco/lists/views/layouts/HeaderCell',

               config: {

                  label: 'Name'

               }

            },

            {

               name: 'alfresco/lists/views/layouts/HeaderCell',

               config: {

                  label: 'Description'

               }

            }

         ],

         widgets: [

            {

               name: 'alfresco/search/AlfSearchResult',

               config: {

                  widgets: [

                     {

                        name: 'alfresco/lists/views/layouts/Row',

                        config: {

                           widgets: [

                              {

                                 name: 'alfresco/lists/views/layouts/Cell',

                                 config: {

                                    additionalCssClasses: 'mediumpad',

                                    widgets: [

                                       {

                                          name: 'alfresco/search/SearchResultPropertyLink',

                                          config: {

                                             propertyToRender: 'node.size'

                                          }

                                       }

                                    ]

                                 }

                              },

                              {

                                 name: 'alfresco/lists/views/layouts/Cell',

                                 config: {

                                    additionalCssClasses: 'mediumpad',

                                    widgets: [

                                       {

                                          name: 'alfresco/renderers/Property',

                                          config: {

                                             propertyToRender: 'node.size'

                                          }

                                       }

                                    ]

                                 }

                              }

                           ]

                        }

                     }

                  ]

               }

            }

         ]

      }

   });

}
Active Member
Hi,



i used Alfresco Community Edition 5.1 , but i can't see table view content instead i show only table header and detailed view as table content



please help!!!!!!!!!



var widget = widgetUtils.findObject(model.jsonModel.widgets, 'id', 'FCTSRCH_SEARCH_RESULTS_LIST');

if (widget && widget.config && widget.config.widgets)

{

   widget.config.widgets.push({

      name: 'alfresco/lists/views/AlfListView',

      config: {

         viewSelectionConfig: {

            label: 'Table View',

            iconClass: 'alf-tableview-icon',

   value: 'table'

         },

         widgetsForHeader: [

            {

               name: 'alfresco/lists/views/layouts/HeaderCell',

               config: {

                  label: 'Name'

               }

            },

            {

               name: 'alfresco/lists/views/layouts/HeaderCell',

               config: {

                  label: 'Description'

               }

            }

         ],

         widgets: [

            {

               name: 'alfresco/search/AlfSearchResult',

               config: {

                  widgets: [

                     {

                        name: 'alfresco/lists/views/layouts/Row',

                        config: {

                           widgets: [

                              {

                                 name: 'alfresco/lists/views/layouts/Cell',

                                 config: {

                                    additionalCssClasses: 'mediumpad',

                                    widgets: [

                                       {

                                          name: 'alfresco/search/SearchResultPropertyLink',

                                          config: {

                                             propertyToRender: 'node.size'

                                          }

                                       }

                                    ]

                                 }

                              },

                              {

                                 name: 'alfresco/lists/views/layouts/Cell',

                                 config: {

                                    additionalCssClasses: 'mediumpad',

                                    widgets: [

                                       {

                                          name: 'alfresco/renderers/Property',

                                          config: {

                                             propertyToRender: 'node.size'

                                          }

                                       }

                                    ]

                                 }

                              }

                           ]

                        }

                     }

                  ]

               }

            }

         ]

      }

   });

}



Regards

janaka
Intermediate II
@Janaka You should remove the 'alfresco/search/AlfSearchResult' from the model that you're trying to add.
Intermediate II
@Giuseppe - This is actually a SOLR issue rather than anything UI specific and I'm afraid that I'm not sure how to resolve the issue. I've seen this issue occur with other OOTB properties in Alfresco (such as the those in the 'audio' namespace). I'm not actually sure of the correct way in which you need to update the model to avoid the tokenization of those values.
Intermediate II
@Giuseppe - try following the instructions in this documentation to configure you custom properties: http://docs.alfresco.com/5.0/concepts/search-fts-config.html (e.g. set the 'facetable' element to be true or the 'tokenized' element to be 'both').
Active Member
thanks it is working
Active Member
Hi



i need to show all properties value of each document (e.g  auhtor,created date..) on result. but i couldn't get like that properties value by alfresco/documentlibrary/AlfSearchList or alfresco/documentlibrary/views/layouts/XhrLayout.



can you help to read all properties in document?



Regards

janaka
Active Member
Hi,



i need to get all properties value of each document on result . but all properties value (include author,created date etc..) are not rendered by using alfresco/lists/views/layouts/XhrLayout or alfresco/search/AlfSearchList.



i  used  Alfresco Community 5.1



Regards

janaka
Intermediate II
@Janaka - The reason why this is not possible is because the default search API only returns a subset of the metadata for each document. This was originally done for performance reasons in the original YUI2 based search page (that was replaced with the faceted search page in version 5.0). The only way that you'll be able to do this is to replace the the search API that is used with a custom version.
Active Member
Hi ,



i rendered path using following widget

{

  'name': 'alfresco/search/SearchResultPropertyLink',

   'config': {

   'propertyToRender': 'path',

               }

}



when click on it , it redirect into document properties file

(http://127.0.0.1:8080/share/page/site/swsdp/document-details?nodeRef=workspace://SpacesStore/5515d3e...)



but i need to redirect into relevant folder (http://127.0.0.1:8080/share/page/repository?path=%2F)



how can do this?



Regards
Intermediate II
@Janaka - depending upon what you're expecting to get in your search results then it might be necessary to implement a custom widget to achieve this. Especially if search results can reveal wiki pages, blogs, links, etc (which they can be default) - because switching to navigate directly to the location of the node (rather than the relevant details page) probably won't make a good user experience. You should be able to extend the SearchResultPropertyLink and extend the generateSearchLinkPayload function (provided by the alfresco/renderers/_SearchResultLinkMixin module) to setup up a different target for documents and folders. This won't be possible through configuration alone at moment.
Active Member
thanks
Active Member
Hi Dave Draper,



When i saw advance search in alfresco, there is path for folder (In folder: /Company Home).

if i click on '/Company Home' , it redirect into relevant folder in repository browser.



do you have idea about it?



e.g

news-editor.js 

Modified 22 hours ago by Administrator

In folder: /Company Home

Size: 16 KB



Regards

janaka
Intermediate II
@Janaka - if you look  in the 'alfresco/search/AlfSearchResult' widget you'll see that this 'path renderer' (navigation to the location of the search result) is provided by the `createPathRenderer` function. It is actually an 'alfresco/renderers/PropertyLink' widget that is configured with the appropriate navigation data.  See: https://github.com/Alfresco/Aikau/blob/4529a6f41641378e54850285e6041696f793c75d/aikau/src/main/resou...
Active Member
I used my own widget , it is working .



thanks Dave Draper
Active Member
hi dave,

@Dave Draper , i used customized widget to search relevant document by click on folder link in result dashlet.



To render widget , use following

{

   'name': 'advancedsearch/SearchResultPathPropertyLink',

   'config': {

  'propertyToRender': 'path',

  'navigationTarget': 'NEW'

        

    }

}

--------------------------------------------------------------------------------------------------------------------------

this may be helped for other and may be used with next version.



define(['dojo/_base/declare',

        'alfresco/renderers/PropertyLink',

        'alfresco/navigation/_HtmlAnchorMixin',

        'alfresco/renderers/_SearchResultLinkMixin',

   'dojo/_base/lang',

   'alfresco/core/ObjectTypeUtils'],

        function(declare, PropertyLink, _HtmlAnchorMixin, _SearchResultLinkMixin,lang,ObjectTypeUtils) {



   return declare([PropertyLink, _HtmlAnchorMixin, _SearchResultLinkMixin], {



      /**

       * Generates the publication payload by calling the mixed in

       * [generatePayload]{@link module:alfresco/renderers/_SearchResultLinkMixin#generatePayload}

       * function and then wraps the property in an anchor element by calling the mixed in

       * [makeAnchor]{@link module:alfresco/navigation/_HtmlAnchorMixin#makeAnchor} function

       *

       * @instance

       */

      postCreate: function alfresco_search_SearchResultPropertyLink__postCreate() {

         this.inherited(arguments);

   //this.currentItem.type = 'folder';

         this.publishPayload = this.generateSearchLinkPayload(this.payload, this.currentItem, null, this.publishPayloadType, this.publishPayloadItemMixin, this.publishPayloadModifiers);

         this.makeAnchor(this.publishPayload.url, this.publishPayload.type);

      },

   /**

       * This function generates a payload for the [NavigationService]{@link module:alfresco/services/NavigationService}

       * that varies depending upon the type of search result (e.g. a document or folder, in a site or in

       * the repository, etc) which can also be used to extrapolate an HTML anchor for

       * [_HtmlAnchorMixin]{@link module:alfresco/navigation/_HtmlAnchorMixin}.

       *

       * @instance

       * @return {object} The generated payload

       */

      generateSearchLinkPayload: function alfresco_renderers__SearchResultLinkMixin__generateSearchPathLinkPayload() {

         // jshint maxcomplexity:false

         var payload = {

            type: this.navigationType,

            target: this.navigationTarget,

            url: null

         };

         var type = lang.getObject('type', false, this.currentItem),

             site = lang.getObject('site.shortName', false, this.currentItem);



         switch(type)

         {

            case 'document':

              

               var path = lang.getObject('path', false, this.currentItem),

               name = lang.getObject('name', false, this.currentItem);

               if (site)

               {

                  //payload.url = 'site/' + site + '/documentlibrary?path=' + encodeURIComponent(path) + '%2F' + encodeURIComponent(name);

      payload.url = 'site/' + site + '/documentlibrary?file='+encodeURIComponent(name)+'#filter=path|' + encodeURIComponent(path);

               }

               else if (path)

               {

                  path = '/' + path.split('/').slice(2).join('/');

                  //payload.url = 'repository?path=' + encodeURIComponent(path) + '%2F' + encodeURIComponent(name);

      payload.url = 'repository?file=' + encodeURIComponent(name)+'#filter=path|'+encodeURIComponent(path);

      //http://127.0.0.1:8080/share/page/repository?file=news-editor.html#filter=path|%2F

               }

               break;

     

   case 'wikipage':

               var title = lang.getObject('name', false, this.currentItem);

               if (site)

               {

                  payload.url = 'site/' + site + '/wiki-page?title=' + title;

               }

               break;

         }

         return payload;

      },

  

   /**

       * Set up the attributes to be used when rendering the template.

       *

       * @instance

       */

      postMixInProperties: function alfresco_Path_Property__postMixInProperties() {

         if (this.label)

         {

            this.label = this.message(this.label) + ': ';

         }

         else

         {

            this.label = '';

         }



         if (ObjectTypeUtils.isString(this.propertyToRender) &&

             ObjectTypeUtils.isObject(this.currentItem) &&

             lang.exists(this.propertyToRender, this.currentItem))

         {

            this.renderPropertyNotFound = false;

            this.originalRenderedValue = this.getRenderedProperty(lang.getObject(this.propertyToRender, false, this.currentItem)!='' ? lang.getObject(this.propertyToRender, false, this.currentItem):this.currentItem.site.title);

            this.renderedValue = this.mapValueToDisplayValue(this.originalRenderedValue);

         }

         else

         {

   this.originalRenderedValue = this.currentItem.site.title;

   this.renderedValue = this.mapValueToDisplayValue(this.originalRenderedValue);

            //this.alfLog('log', 'Property does not exist:', this);

         }



         this.renderedValue = this.generateRendering(this.renderedValue);

         this.updateRenderedValueClass();

      },



      /**

       * Returns an array containing the selector that identifies the span to wrap in an anchor.

       * This overrides the [mixed in function]{@link module:alfresco/navigation/_HtmlAnchorMixin}

       * that just returns an empty array.

       *

       * @instance

       */

      getAnchorTargetSelectors: function alfresco_search_SearchResultPropertyLink__getAnchorTargetSelectors() {

         return ['span.inner'];

      },



      /**

       * Overrides the [inherited function]{@link module:alfresco/renderers/PropertyLink#getPublishTopic}

       * to return the 'ALF_NAVIGATE_TO_PAGE' topic.

       *

       * @instance

       * @return {object} The generated payload

       */

      getPublishTopic: function alfresco_search_SearchResultPropertyLink__getPublishTopic() {

         return 'ALF_NAVIGATE_TO_PAGE';

      },



      /**

       * Overrides the [inherited function]{@link module:alfresco/renderers/PropertyLink#getPublishPayload}

       * to return the payload generated by the [generatePayload function]

       * {@link module:alfresco/search/SearchResultPropertyLink#generatePayload}.

       *

       * @instance

       * @return {object} The generated payload

       */

      getPublishPayload: function alfresco_search_SearchResultPropertyLink__getPublishPayload() {

         return this.publishPayload;

      }

   });

});





Thanks



janaka
Active Member II

This post was very helpful in figuring out how to add a new search view.  We now have a nice table view of the results but we're currently limited to 25 results.  Does anyone have any advice on how to add either an infinite scroll or paging to the above example?  Using either the alfresco/documentlibrary/views/AlfDocumentListView (now deprecated) or the alfresco/lists/views/AlfListView?  

Side note as it may be relevant, I was unable to get the example working using the alfresco/documentlibrary/views/AlfSearchListView module as shown above or with its replacement alfresco/search/AlfSearchListView, but was successful with the other 2 view modules I mentioned.  Trying to use either of the AlfSearchListView modules seemed to conflict with the existing "Detailed View".

Thanks,
Neil

Intermediate II

Infinite scrolling is handled by the list widget and not the view container. The AlfSearchList on the search page should already be configued to use infinite scrolling. However if you have a table view that will typically fit within the constraints of the page then no scroll events will occur that will trigger the loading of the next page. There are two immediate options that spring to mind ...

  1. Change the default page size so that enough results are shown to result in a scroll bar being shown on the page
  2. Use an InfiniteScrollArea to wrap the list so that the scroll bars appear within the main page (rather than on the page itself). Again though this requires that the default page size results in a view that is taller than the infinite scroll area.

The key thing to remember is that without any scroll events occurring the next page of data will not be loaded.

Occasional Visitor

I was able to add a new search view and now I am trying to display more than than this limited set of data.
Can't manage to get it to work in Alfresco 5.1, any tips ? I've tried all the tips mentioned both on the post and the comments too. 

Intermediate II

If by limited set of data you mean the the actual metadata returned by the underlying REST API then your options are essentially to either upgrade to 5.2 (where the APIs were updated to return the full metadata for the nodes) or to override the WebScripts with updated versions that do include the additional data. As the 5.2 code is open source your should be able to view the changes. The main change is that in the search.lib.js file you'll need to add:

nodeJSON: appUtils.toJSON(node, true)

...to every item handling function (i.e. "getDocumentItem", "getBlogPostItem", "getForumPostItem", etc. etc.) I would recommend that you review the change history and revision 131071 in particular.

Active Member II

I had the same problem. Working solution is to set facetable index while defining type/aspect property:

<index enabled="true">
    <facetable>true</facetable>
</index>

					
				
			
			
			
				
			
			
			
			
			
			
		
Occasional Visitor

I'm trying to do this example to add a new search view, but it doesn't work for me, I don´t see the option in the table views. I'm working with Alfresco 5.2, I've done all the steps and this is my faceted-search.get.js:

var widget = widgetUtils.findObject(model.jsonModel.widgets, 'id', 'FCTSRCH_SEARCH_RESULTS_LIST');
if (widget && widget.config && widget.config.widgets)
{
 widget.config.widgets.push({
   id: "FCTSRCH_SEARCH_RESULTS_LIST",
   name: "alfresco/search/AlfSearchList",
   config: {
       viewSelectionConfig: {
          label: 'Contract View',
          iconClass: 'alf-tableview-icon'
       },
    widgetsForHeader: [
     {
         name: 'alfresco/lists/views/layouts/HeaderCell',
         config: {
          label: 'Name'
         }
       },
       {
         name: 'alfresco/documentlibrary/views/layouts/HeaderCell',
         config: {
          label: 'Description'
         }
       }
     ],
     widgets: [
      {
        name: 'alfresco/documentlibrary/views/AlfDocumentListView',
        config: {
         widgets: [
           {
            name: 'alfresco/documentlibrary/views/layouts/Row',
            config: {
             widgets: [
                {
                  name: 'alfresco/documentlibrary/views/layouts/Cell',
                  config: {
                  additionalCssClasses: 'mediumpad',
                  widgets: [
                   {
                    name: 'alfresco/renderers/SearchResultPropertyLink',
                    config: {
                      propertyToRender: 'displayName'
                    }
                  }
                ]
              }
        },
        {
          name: 'alfresco/documentlibrary/views/layouts/Cell',
          config: {
           additionalCssClasses: 'mediumpad',
           widgets: [
           { 
              name: 'alfresco/renderers/Property',
              config: {
                propertyToRender: 'description'
              }
           }
         ]
       }
     }
    ]
   }
  }
 ]
 }
 }
 ]
 }
});
}

I'm trying to use "alfresco/search/AlfSearchList" because the next step is to display more information about the nodes, because the set of data available is not enough.

Established Member II

Hi Samuel have you found a solution for Alfresco 5.2?

Senior Member II

Hi,

Could anyone help me to add new custom action in aikau search result page?

@ddraper 

 

Established Member

Hi,

Can anyone help me to do the same customization in Alfresco 6.2 (SDK 4.1 using docker).

Thanks