MCPcopy Create free account
hub / github.com/arktypeio/arktype / boostOf

Function boostOf

ark/docs/components/shell/SearchPanel.tsx:122–149  ·  view source on GitHub ↗
({ index, names }: Loaded, query: string, home: number)

Source from the content-addressed store, hash-verified

120 * Errors, and ArkType's win them elsewhere.
121 */
122const boostOf = ({ index, names }: Loaded, query: string, home: number) => {
123 const queryTerms = termsOf(query)
124 const queryName = queryTerms.join(" ")
125 return (_id: unknown, term: string, stored?: Record<string, unknown>) => {
126 const { page, top, name } = stored as {
127 page: number
128 top: boolean
129 name: string
130 }
131 const { url, section } = index.pages[page]
132 const demote = demoted.has(url) || unscoped.has(index.sections[section])
133 const boost =
134 demote ? 0.3
135 : section === home ? 1.25
136 : section === 0 ? 1.15
137 : 1
138 if (!top) return name === queryName && !demote ? boost * 4 : boost
139 const { terms, keys } = names[page]
140 const named =
141 terms.every(t => queryTerms.includes(t)) ||
142 keys.some(key => queryTerms.includes(key))
143 return (
144 boost *
145 (terms.includes(term) || keys.includes(term) ? 3 : 1) *
146 (named ? 2 : 1)
147 )
148 }
149}
150
151/** the section of the page being read, or ArkType's outside the docs */
152const homeSectionOf = ({ index }: Loaded) => {

Callers 1

resultsOfFunction · 0.85

Calls 2

termsOfFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected