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 Alfresco.ExtendedAdvancedSearch.superclass.constructor.call(this, 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(this.id + "-search-text").value),
	          query: encodeURIComponent(YAHOO.lang.JSON.stringify(formData)),
	          repo: this.options.searchRepo.toString()
	       });
	       
	       window.location.href = url;
	    }
		  
	}, true);
})();

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

Responder

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

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. 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 )

Google+ photo

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

Conectando a %s