04-14-2009 02:43 PM
<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'];very long working.04-15-2009 04:06 PM
// 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!04-15-2009 07:14 PM
// 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;04-21-2009 05:15 AM
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);
04-21-2009 12:45 PM
The Alfresco Lucene API can perform some sorting for you, and we provide access to that through the scripting API:Ah, this was used at first but was not returning correct results with tokenized fields, e.g. cm:title because each token was being considered separately.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 requestedThat's great- thanks Kevin- Though while we're prioritizing features for Alfresco 3.2, I'd place these above multi-column sort as they are likely even more common needs:
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…)In order to tap into the power of the Java API, from the webscript would we call the Java API like this? (Or is there another more standard way?)
04-22-2009 05:17 AM
04-22-2009 02:12 PM
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.
05-13-2009 12:46 PM
- 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);
05-13-2009 06:27 PM
05-14-2009 05:37 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.