| 475 | } |
| 476 | |
| 477 | function rank(page, terms) { |
| 478 | var ranking = {page: page, rank:0}, |
| 479 | keywords = page.keywords, |
| 480 | title = page.shortName.toLowerCase(); |
| 481 | |
| 482 | terms && angular.forEach(terms.toLowerCase().split(' '), function(term) { |
| 483 | var index; |
| 484 | |
| 485 | if (ranking) { |
| 486 | if (keywords.indexOf(term) == -1) { |
| 487 | ranking = null; |
| 488 | } else { |
| 489 | ranking.rank ++; // one point for each term found |
| 490 | if ((index = title.indexOf(term)) != -1) { |
| 491 | ranking.rank += 20 - index; // ten points if you match title |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | }); |
| 496 | return ranking; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | |