|
230 | 230 | }
|
231 | 231 | }
|
232 | 232 |
|
| 233 | + function typePassesFilter(filter, type) { |
| 234 | + // No filter |
| 235 | + if (filter < 0) return true; |
| 236 | + |
| 237 | + // Exact match |
| 238 | + if (filter === type) return true; |
| 239 | + |
| 240 | + // Match related items |
| 241 | + var name = itemTypes[type]; |
| 242 | + switch (itemTypes[filter]) { |
| 243 | + case "constant": |
| 244 | + return (name == "associatedconstant"); |
| 245 | + case "fn": |
| 246 | + return (name == "method" || name == "tymethod"); |
| 247 | + case "type": |
| 248 | + return (name == "primitive"); |
| 249 | + } |
| 250 | + |
| 251 | + // No match |
| 252 | + return false; |
| 253 | + } |
| 254 | + |
233 | 255 | // quoted values mean literal search
|
234 | 256 | var nSearchWords = searchWords.length;
|
235 | 257 | if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
|
|
239 | 261 | for (var i = 0; i < nSearchWords; ++i) {
|
240 | 262 | if (searchWords[i] === val) {
|
241 | 263 | // filter type: ... queries
|
242 |
| - if (typeFilter < 0 || typeFilter === searchIndex[i].ty) { |
| 264 | + if (typePassesFilter(typeFilter, searchIndex[i].ty)) { |
243 | 265 | results.push({id: i, index: -1});
|
244 | 266 | }
|
245 | 267 | }
|
|
285 | 307 | searchWords[j].replace(/_/g, "").indexOf(val) > -1)
|
286 | 308 | {
|
287 | 309 | // filter type: ... queries
|
288 |
| - if (typeFilter < 0 || typeFilter === searchIndex[j].ty) { |
| 310 | + if (typePassesFilter(typeFilter, searchIndex[j].ty)) { |
289 | 311 | results.push({
|
290 | 312 | id: j,
|
291 | 313 | index: searchWords[j].replace(/_/g, "").indexOf(val),
|
|
295 | 317 | } else if (
|
296 | 318 | (lev_distance = levenshtein(searchWords[j], val)) <=
|
297 | 319 | MAX_LEV_DISTANCE) {
|
298 |
| - if (typeFilter < 0 || typeFilter === searchIndex[j].ty) { |
| 320 | + if (typePassesFilter(typeFilter, searchIndex[j].ty)) { |
299 | 321 | results.push({
|
300 | 322 | id: j,
|
301 | 323 | index: 0,
|
|
451 | 473 | var matches, type, query, raw = $('.search-input').val();
|
452 | 474 | query = raw;
|
453 | 475 |
|
454 |
| - matches = query.match(/^(fn|mod|struct|enum|trait|t(ype)?d(ef)?)\s*:\s*/i); |
| 476 | + matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i); |
455 | 477 | if (matches) {
|
456 |
| - type = matches[1].replace(/^td$/, 'typedef') |
457 |
| - .replace(/^tdef$/, 'typedef') |
458 |
| - .replace(/^typed$/, 'typedef'); |
| 478 | + type = matches[1].replace(/^const$/, 'constant'); |
459 | 479 | query = query.substring(matches[0].length);
|
460 | 480 | }
|
461 | 481 |
|
|
0 commit comments