| 4 | // This is used to prune out irrelevant suggestions before we try to rank them, and for |
| 5 | // calculating word relevancy. Every term must match at least one thing. |
| 6 | export function matches(queryTerms, ...things) { |
| 7 | for (const term of queryTerms) { |
| 8 | const regexp = RegexpCache.get(term); |
| 9 | let matchedTerm = false; |
| 10 | for (const thing of things) { |
| 11 | if (!matchedTerm) { |
| 12 | matchedTerm = thing.match(regexp); |
| 13 | } |
| 14 | } |
| 15 | if (!matchedTerm) return false; |
| 16 | } |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | // Weights used for scoring matches. |
| 21 | const matchWeights = { |