Changeset 414

Show
Ignore:
Timestamp:
12/19/07 10:39:39 (5 years ago)
Author:
mgalloy
Message:

Basic search seems to work; need to style it a bit better, add the other fields, and put it in multiple search terms.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/idldoc/src/resources/search.js

    r413 r414  
    1818var SCORE        = 12; 
    1919var MATCHES      = 13; 
    20 var SORT         = 14; 
    2120 
    2221var SCORE_VALUES = new Array(0, 0, 0, 8, 6, 10, 4, 6, 8, 4); 
     
    8382} 
    8483 
     84function sortByScore(a, b) { 
     85  return b[SCORE] - a[SCORE]; 
     86} 
     87 
    8588 
    8689function sortResults() { 
    8790  for (item = 0; item < libdata.length; item++) { 
    88     libdata[item][SORT] = item; 
    89   } 
    90    
    91   for (item = 0; item < libdata.length; item++) { 
    92     if (libdata[item][N_MATCHES] > 0) { 
    93       libdata[item][SCORE] = item; 
     91    if (libdata[item][N_MATCHES] > 0) { 
    9492      matchType = libdata[item][MATCH_TYPE]; 
    9593      typeMultiplier = SCORE_VALUES[matchType];       
    9694      matchPercentage = libdata[item][N_MATCHES] * searchString.length / libdata[item][matchType].length; 
    97       libdata[item][SCORE] = Math.round(typeMultiplier * matchPercentage); 
    98     } 
    99   } 
    100    
    101   for (item = 1; item < libdata.length; item++) { 
    102     tempScore = libdata[item][SCORE]; 
    103     tempSort = libdata[item][SORT]; 
    104    
    105     for (k = item; k > 1 && tempScore > libdata[k - 1][SCORE]; k--) { 
    106       libdata[k][SCORE] = libdata[k - 1][SCORE]; 
    107       libdata[k][SORT] = libdata[k - 1][SORT]; 
    108     } 
    109    
    110     libdata[k][SCORE] = tempScore; 
    111     libdata[k][SORT] = tempSort; 
    112   } 
     95      libdata[item][SCORE] = typeMultiplier * matchPercentage; 
     96    } 
     97  } 
     98   
     99  libdata = libdata.sort(sortByScore); 
    113100} 
    114101 
     
    147134function putItem(item) { 
    148135  mType = libdata[item][MATCH_TYPE]; 
    149   width = 2 * libdata[item][SCORE]; 
     136  width = Math.round(2 * libdata[item][SCORE]); 
    150137   
    151138  html += "<li>"; 
     
    156143  html += "..." + libdata[item][mType].substring(libdata[item][MATCHES] - 5, libdata[item][MATCHES] + 15) + "...<br/>"; 
    157144   
    158   html += "Score: " + libdata[item][SCORE]; 
     145  html += "Score: " + Math.round(10 * libdata[item][SCORE]) / 10; 
    159146  html += " - " + libdata[item][N_MATCHES] + " matches "; 
    160147   
     
    195182   
    196183  for (var item = 0; item < libdata.length; item++) { 
    197     if (libdata[libdata[item][SORT]][N_MATCHES] > 0) { 
    198       putItem(libdata[item][SORT]); 
     184    if (libdata[item][N_MATCHES] > 0) { 
     185      putItem(item); 
    199186    } 
    200187  }