Alfresco Share – Customize advanced search for aspect properties

The advanced search form in Alfresco Share allows to use specific property values to search depending on the content type selected. Alfresco wiki includes a detailed explanation on configuring these feature and Jeff Potts develops a sample on his Working With Custom Content Types tutorial.

The problem

As Axel Faust describes at Alfresco Forum: “currently it’s not possible to setup a search form based just on an aspect. The reason for this is that there is no FormProcessor on the Repository tier that can handle aspect-based forms”.

The hack

AdvancedSearch Javascript component can be overridden in order to include aspect properties as search fields just prefixing the property with “prop_”.

(function() {
	var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, Selector = YAHOO.util.Selector, Bubbling = YAHOO.Bubbling;
	var $html = Alfresco.util.encodeHTML, $links = Alfresco.util.activateLinks, $combine = Alfresco.util.combinePaths, $userProfile = Alfresco.util.userProfileLink;

	Alfresco.ExtendedAdvancedSearch = function(htmlId) {
		return, htmlId);

    YAHOO.extend(Alfresco.ExtendedAdvancedSearch, Alfresco.AdvancedSearch);

	YAHOO.lang.augmentObject(Alfresco.ExtendedAdvancedSearch.prototype, {
	    onSearchClick: function ADVSearch_onSearchClick(e, obj)
	       // retrieve form data structure directly from the runtime
	       var formData = this.currentForm.runtime.getFormData();
	       // add "prop_" prefix to aspect properties
	       var modifiedFormData = {},
               length = formData.length;
		   var originalValue;
		   for (var prop in formData) {
			    if (formData.hasOwnProperty(prop)) {
		        	originalValue = formData[prop];
			        if (!(prop.substring(0, 5) == "prop_")) {
			        	prop = "prop_" + prop;
			        modifiedFormData[prop] = originalValue;
		   formData = modifiedFormData;
	       // add DD type to form data structure
	       formData.datatype = this.currentForm.type;
	       // build and execute url for search page
	       var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "{site}search?t={terms}&q={query}&r={repo}",
	          site: (this.options.siteId.length !== 0 ? ("site/" + this.options.siteId + "/") : ""),
	          terms: encodeURIComponent(Dom.get( + "-search-text").value),
	          query: encodeURIComponent(YAHOO.lang.JSON.stringify(formData)),
	          repo: this.options.searchRepo.toString()
	       window.location.href = url;
	}, true);

Alternative workaround

You can define and advanced search form based on an aspect without modifying the product and without adding extra fields. Just defining a new advanced search form based on cm:content but including only aspects fields with the modifier force.

1. Create a new entry in advanced search forms list

	<config replace="true" evaluator="string-compare" condition="AdvancedSearch">
                    <!-- Named search form to avoid default "search" form from cm:content -->
	            <form id="custom-search" labelId="advsearch.label.custom" descriptionId="advsearch.description.custom">cm:content</form>
	            <form labelId="search.form.label.cm_content" descriptionId="search.form.desc.cm_content">cm:content</form>
	            <form labelId="search.form.label.cm_folder" descriptionId="search.form.desc.cm_folder">cm:folder</form>            

2. Define your form based on cm:content but including only aspects fields and using force. Below a simple my:field from fake aspect is configured.

<config evaluator="model-type" condition="cm:content">
        <form id="custom-search">
                <show id="my:field" force="true" />
                <field id="my:field">
                    <control template="/org/alfresco/components/form/controls/textfield.ftl" />

3 comentarios en “Alfresco Share – Customize advanced search for aspect properties

    • You can use it as a part of a Share AMP, including this JS in components/search/extended-advsearch.js and redefining references at web-extension/site-webscripts/org/alfresco/components/search/advsearch.get.js and web-extension/site-webscripts/org/alfresco/components/search/advsearch.get.html.ftl.

      By using “Working With Custom Content Types” source code from Jeff Potts it can be enough. It works on every custom aspect, so no specific model must be defined.

      Thanks for your feedback!

  1. Pingback: Alfresco · Using the force for advanced search and aspects | Programming and So


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s