As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
<index enabled="true"> <atomic>true</atomic> <stored>false</stored> <tokenised>true</tokenised> </index>
var result = search.luceneSearch(query); result.sort(Sorting); …. function Sorting(a, b) { var x = a.properties['cm:title']; var y = b.properties['cm:title']; return ((x > y) ? 1 : -1); }
var x = a.properties['cm:title']; var y = b.properties['cm:title'];
// this query produces 458 rows on our fresh alfresco test installation with dummy content: var query = "TYPE:\"{http://www.alfresco.org/model/content/1.0}content\""; if( query != null && query.length > 0 ) { var result = search.luceneSearch(query); // fast // now to sort manually on tokenized values I'll need to look at each attribute: // I took out the sorting for simplicity: just saving to a temp variable shows slowness! var temp; for(i=0;i<result.length;i++) { temp = result[i].properties['cm:title']; // very slow! } }
temp = result[i].properties['cm:title']; // very slow!
// In my test case, this query returns 394 nodes. var query = "TYPE:\"{http://www.alfresco.org/model/content/1.0}content\""; var total = ""; var out = ""; if( query != null && query.length > 0 ) { var result = search.luceneSearch(query); // fast total = result.length; for (i=0;i<result.length;i++) { // let's take a look at how long the script takes on various ScriptNode object attributes. // I uncommented each of these one by one and measured how long it took to print out that // individual ScriptNode attribute: //out += result[i].id +"<br>"; // ~ 0.3 seconds on 394 nodes. //out += result[i].nodeRef +"<br>"; // ~ 0.3 seconds on 394 nodes. //out += result[i].displayPath +"<br>"; // ~ 0.6 seconds on 394 nodes. //out += result[i].qnamePath +"<br>"; // ~ 0.4 seconds on 394 nodes. //out += result[i].isLocked() +"<br>"; // ~ 0.3 seconds on 394 nodes. //out += result[i].type +"<br>"; // ~ 0.4 seconds on 394 nodes. //out += result[i].parent.id +"<br>"; // ~ 0.3 seconds on 394 nodes. //out += result[i].isCategory +"<br>"; // ~ 0.2 seconds on 394 nodes. //out += result[i].aspects +"<br>"; // ~ 0.4 seconds on 394 nodes. !!! fast. //out += result[i].size +"<br>"; // ~ 27.4 seconds on 394 nodes. //out += result[i].url +"<br>"; // ~ 28.1 seconds on 394 nodes. //out += result[i].downloadUrl +"<br>"; // ~ 28.2 seconds on 394 nodes. //out += result[i].name +"<br>"; // ~ 27.8 seconds on 394 nodes. } } out += "<br><br>"; out += "<b>query:</b> "+query+"<br>"; out += "<b>total:</b> "+total+"<br>"; out;
Array luceneSearch(string query, string sortColumn, boolean asc) Returns an array of ScriptNode satisfying the search criteria sorted by the specified sortColumn (the property name to sort on) and asc (true => ascending order, false => descending order). For example var nodes = search.luceneSearch("TEXT:alfresco", "@cm:modified", false);
The Alfresco Lucene API can perform some sorting for you, and we provide access to that through the scripting API:Array luceneSearch(string query, string sortColumn, boolean asc) Returns an array of ScriptNode satisfying the search criteria sorted by the specified sortColumn (the property name to sort on) and asc (true => ascending order, false => descending order). For example var nodes = search.luceneSearch("TEXT:alfresco", "@cm:modified", false);
If you need to sort by more than one column then the Script API does not yet provide this. But i can easily add it for Alfresco 3.2 since it has now been requested
The reason some properties take longer than others to retrieve is that some properties are easily resolvable from data already cached on the ScriptNode instance - and some data must be retrieved directly from the repository (and then cached). Accessing individual properties of 1000's of nodes via the ScriptNode API is not going to be as fast as writing some Java code to do it - as the ScriptNode API calls must always pass through all levels of Permissions and Public Service Interceptors etc. for each call (Java code does not always need to do this…)
I'll talk to our Lucene guy today to see what is the issue around sorting on tokenized fields. If we can fix that or find you a solution then hopefully you won't have to go the java route. Yes that is the right link for integrating Java calls into secure WebScripts - but it's not a nice solution if you can avoid it then I would.
- Query, language (lucene, xpath, jcr-path and alfresco-fts etc), store (workspace or avm), multi-column sorting and paging all supported via search definition object - A query definition object with a number of parameter objects can be simple to use as: var results = search.query({query: "TEXT:alfresco"}); - Or as richly defined as: var sort1 = { column: "@{http://www.alfresco.org/model/content/1.0}modified", ascending: false }; var sort2 = { column: "@{http://www.alfresco.org/model/content/1.0}created", ascending: false }; var paging = { maxItems: 100, skipCount: 0 }; var def = { query: "cm:name:test*", store: "workspace://SpacesStore", language: "fts-alfresco", sort: [sort1, sort2], page: paging }; var results = search.query(def);
Sam, perhaps there is a correlation with attribute tokenization?