AnsweredAssumed Answered

The efficient way of finding property-values

Question asked by buurd on Mar 11, 2010
Latest reply on Apr 6, 2010 by andy
Hi

I have a script that finds all values used for a particular property. Consider the following function that recives the resultset from a Lucene query and a name of a property (cm:author for example).


function getPropertyValues(results, property){
    var values = new Array();
    for(var i = 0; i < results.length; i++){
        var content = results[i];
        var value = content.properties[property];
        if(values[value] == null){
            values[value] = value;
        }
    }
    return values;
}

This is a really inefficient way of getting the list of property values that matches the query. Imagine that you have about 100 author that have produced 100 documents each, then you have to iterate through 100 000 nodes to make sure that you have not missed one and it is probably take several seconds.

My question is: What is the efficient way of getting the distinct values that exists for a property?

Thanks in advance
Roland

Outcomes