Quick search in the Share (the little box in the top right) do not behave as most expect. When you enter multiple keywords, then Alfresco will search using OR. Which means that you get more hits with multiple keywords, not as you expect, results narrowed. So we need to get Alfresco to do AND by default between the keywords.
Now it is perfectly acceptable to write AND yourself between keywords (feel free to try), but we want it automatically. There is an issue ALF-6349 where it is described how it can be done generally to all searches by changing the Search.java to make it configurable via the bean definition. The problem with introducing the change is that when you have already selected a default (OR) you can not just change when a number of components and their adaptations may depend on current behavior, and we can have unexpected bugs.
My solution was instead to change only how Share quick search behaves, also here a change is needed for projects/repository/source/java/org/alfresco/repo/jscript/Search.java by extending the class when the search is done with the javascript search object to be able to take a new parameter,
andOperator: boolean optional, if true, use the AND operator, defaults to false (OR)
Next file to change is projects/remote-api/config/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js
We can now use a parameter in the serach
var queryDef = {
query: ftsQuery,
language: "fts-alfresco",
page: {maxItems: params.maxResults * 2}, // allow for space for filtering out results
templates: getQueryTemplate(),
defaultField: "keywords",
onerror: "no-results",
sort: sortColumns,
andOperator: true
};
In this file there is also one more change needed,
ftsQuery += ' AND (+TYPE:"cm:content" OR +TYPE:"cm:folder")'
an OR needs to be inserted here, else we get AND (since this is now default).
The last file to change is projects/remote-api/config/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.get.config.xml
<search>
<default-query-template>%(ALL)</default-query-template>
</search>
We need to change the default query template, else all terms will get AND and the results are no hits. But we instead use the magic keyword ALL, not only does our search work, it will automatically search all your custom metadata fields too (you can try this in the quick search using ALL:<your term>).
I will attach a complete diff for my changes to the issue ALF-6349.