( searchTerms: string[], queryInfo: QueryInfo, newQueryInfo: Map<string, string> )
| 4 | type QueryInfo = SearchBoxQuery['view']['queryInfo'] |
| 5 | |
| 6 | export function buildPath( |
| 7 | searchTerms: string[], |
| 8 | queryInfo: QueryInfo, |
| 9 | newQueryInfo: Map<string, string> |
| 10 | ): string { |
| 11 | const displayNamesToIds: Map<string, string> = new Map(newQueryInfo) |
| 12 | |
| 13 | queryInfo.topics.forEach((topic) => { |
| 14 | displayNamesToIds.set(topic.displayName, topic.id) |
| 15 | }) |
| 16 | |
| 17 | const topicIds = searchTerms.map((name) => displayNamesToIds.get(name)).filter(Boolean) |
| 18 | const parentTopicId = topicIds.length < 1 ? ROOT_TOPIC_ID : topicIds[0] |
| 19 | const phrases = searchTerms.filter((name) => !displayNamesToIds.has(name)) |
| 20 | const q = topicIds.slice(1).map((id) => `in:${id}`).concat(phrases).join(' ') |
| 21 | |
| 22 | if (q.length > 0) { |
| 23 | return `/topics/${parentTopicId}/q/${q}` |
| 24 | } |
| 25 | |
| 26 | return `/topics/${parentTopicId}` |
| 27 | } |
no test coverage detected