OpenLayers OpenLayers

Changeset 7098

Show
Ignore:
Timestamp:
05/08/08 04:56:38 (4 months ago)
Author:
tschaub
Message:

sort by words matched then by frequency

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/doc/examples.html

    r7097 r7098  
    9999                                var count = dict[exIndex]; 
    100100                                if(scores[exIndex]) { 
    101                                     scores[exIndex] += count; 
     101                                    if(scores[exIndex][word]) { 
     102                                        scores[exIndex][word] += count; 
     103                                    } else { 
     104                                        scores[exIndex][word] = count; 
     105                                    } 
    102106                                } else { 
    103                                     scores[exIndex] = count; 
     107                                    scores[exIndex] = {}; 
     108                                    scores[exIndex][word] = count; 
    104109                                } 
    105110                            } 
     
    112117                        examples.push(ex); 
    113118                    } 
    114                     // sort examples by descending score 
     119                    // sort examples by first by number of words matched, then 
     120                    // by word frequency 
    115121                    examples.sort(function(a, b) { 
    116                         return (b.score - a.score); 
     122                        var cmp; 
     123                        var aWords = 0, bWords = 0; 
     124                        var aScore = 0, bScore = 0; 
     125                        for(var i in a.score) { 
     126                            aScore += a.score[i]; 
     127                            aWords += 1; 
     128                        } 
     129                        for(var j in b.score) { 
     130                            bScore += b.score[j]; 
     131                            bWords += 1; 
     132                        } 
     133                        if(aWords == bWords) { 
     134                            cmp = bScore - aScore; 
     135                        } else { 
     136                            cmp = bWords - aWords; 
     137                        } 
     138                        return cmp; 
    117139                    }); 
    118140                }