docs: add full-text search (#2735)
### Change Type - [x] `patch` — Bug fix ### Test Plan 1. Make sure search (AI and regular) still works as expected. ### Release Notes - Docs: Add full-text search.
This commit is contained in:
parent
538734782c
commit
b50cda0a6e
7 changed files with 64 additions and 47 deletions
|
@ -98,21 +98,14 @@ const Autocomplete = forwardRef(function Autocomplete(
|
|||
<Icon className="autocomplete__icon" icon="search" small />
|
||||
)}
|
||||
|
||||
<Combobox
|
||||
autoSelect
|
||||
placeholder="Search…"
|
||||
ref={ref}
|
||||
className="autocomplete__input"
|
||||
value={value}
|
||||
/>
|
||||
<Combobox placeholder="Search…" ref={ref} className="autocomplete__input" value={value} />
|
||||
|
||||
{value && <ComboboxCancel className="autocomplete__cancel" />}
|
||||
|
||||
{value && (
|
||||
<ComboboxPopover className="autocomplete__popover">
|
||||
{value && options.length !== 0 && (
|
||||
<ComboboxPopover sameWidth className="autocomplete__popover">
|
||||
{customUI}
|
||||
{options.length === 0 && <span className="autocomplete__empty">No results found.</span>}
|
||||
{options.length !== 0 && renderedGroups}
|
||||
{renderedGroups}
|
||||
</ComboboxPopover>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -39,17 +39,22 @@ export function Search() {
|
|||
const res = await fetch(endPoint)
|
||||
if (res.ok) {
|
||||
const json = await res.json()
|
||||
const topExamples = json.results.examples.slice(0, 5)
|
||||
const topArticles = json.results.articles.slice(0, 10)
|
||||
const topAPI = json.results.apiDocs.slice(0, 10)
|
||||
const topExamples = json.results.examples.slice(0, 10)
|
||||
const topAPI = json.results.apiDocs.slice(0, 20)
|
||||
const allResults = topExamples.concat(topArticles).concat(topAPI)
|
||||
setSearchResults(
|
||||
allResults.map((result: SearchResult) => ({
|
||||
label: result.title,
|
||||
value: result.url,
|
||||
group: result.sectionType,
|
||||
}))
|
||||
)
|
||||
|
||||
if (allResults.length) {
|
||||
setSearchResults(
|
||||
allResults.map((result: SearchResult) => ({
|
||||
label: result.title,
|
||||
value: result.url,
|
||||
group: result.sectionType,
|
||||
}))
|
||||
)
|
||||
} else {
|
||||
setSearchResults([{ label: 'No results found.', value: '#', group: 'docs' }])
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
@ -66,6 +71,7 @@ export function Search() {
|
|||
}
|
||||
|
||||
const handleSearchTypeChange = () => {
|
||||
setSearchResults([])
|
||||
setSearchType(searchType === SEARCH_TYPE.AI ? SEARCH_TYPE.NORMAL : SEARCH_TYPE.AI)
|
||||
handleInputChange(query)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue