You are here

Alfresco Share: default AND search

It's weird that Alfresco Share uses an OR search by default. If we want to find files related to the budget of the marketing department we would have to search for

budget AND marketing

There's an article and a bug report with information on how to change the default behavior to an AND search, but they require you to modify the Java code, which is quite complicated.

As long as this problem is not fixed in Alfresco, you may find it easier to make some JavaScript changes. Just edit file /opt/alfresco-4.2.b/tomcat/webapps/share/components/search/search.js and modifiy the _performSearch function as following:

_performSearch: function Search__performSearch(args)
{
var searchTerm = YAHOO.lang.trim(args.searchTerm),
searchTag = YAHOO.lang.trim(args.searchTag),
searchAllSites = args.searchAllSites,
searchRepository = args.searchRepository,
searchSort = args.searchSort;

// ----------------------------------        
// use default AND operator
// ----------------------------------

// first remove any " AND " terms entered by the user (case insensitive)
searchTerm = searchTerm.replace(/ AND /gi, " ");

// replace spaces not between quotes with " AND "
var testregex = /(?:[\s]+)|((?:"[^"]*")|(?:'[^']*'))/g;
searchTerm = searchTerm.replace(testregex, function(match){
if (match.replace(/[\s]/g, "") == "")
return " AND ";
else
return match;
});

// debug
//alert(searchTerm);

if (this.options.searchQuery.length === 0 &&

This will replace all spaces in the search string with " AND ", except when the space is between two quotes.

Alfresco doesn't use search.js directly, it uses the minified version search-min.js. You may simply overwrite search-min.js with the contents of search.js though, it won't make a big performance difference. If you do wish to minify the file, you can use an online tool such as http://refresh-sf.com/yui/.