Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve recall with section-restricted search #9

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apify/docs-search-modal",
"version": "1.0.25",
"version": "1.0.26",
"description": "A custom implementation of the modal search for Apify Docs.",
"author": "Jindřich Bär",
"license": "ISC",
Expand Down
35 changes: 31 additions & 4 deletions src/components/ApifySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ import { ResultsItems } from './ResultsItems';
import { render } from 'react-dom';
import { useHotkeys } from 'react-hotkeys-hook';
import { SearchIcon, ControlKeyIcon } from '../utils/icons';
import { countFamily } from '../utils/countFamily';

const pathPrefixToSectionTag = {
"/api/client/js": "apify-client-js",
"/api/client/python": "apify-client-python",
"/sdk/js": "apify-sdk-js",
"/sdk/python": "apify-sdk-python",
"/cli": "apify-cli",
}

function getCurrentSectionTag(pathname: string) {
return Object.entries(pathPrefixToSectionTag).find(([pathPrefix]) => pathname.startsWith(pathPrefix))?.[1] ?? 'apify-docs'
}

const MAX_RESULTS = 20;

const collapseResults = (() => {
return {
Expand Down Expand Up @@ -60,17 +73,31 @@ function Autocomplete(props: any) {
{
sourceId: 'products',
getItems() {
const currentSection = getCurrentSectionTag(window.location.pathname);

return getAlgoliaResults({
searchClient: props.searchClient,
queries: [
{
indexName: props.indexName,
query,
params: {
hitsPerPage: 20,
hitsPerPage: MAX_RESULTS,
attributesToSnippet: ['content:35'],
attributesToRetrieve: ['content', 'hierarchy', 'toc', 'url', 'breadcrumbs'],
filters: props.filters ?? 'version:latest',
facetFilters: `section:${currentSection}`
},
},
{
indexName: props.indexName,
query,
params: {
hitsPerPage: MAX_RESULTS,
attributesToSnippet: ['content:35'],
attributesToRetrieve: ['content', 'hierarchy', 'toc', 'url', 'breadcrumbs'],
filters: props.filters ?? 'version:latest'
filters: props.filters ?? 'version:latest',
facetFilters: `section:-${currentSection}`,
},
},
],
Expand All @@ -84,7 +111,7 @@ function Autocomplete(props: any) {

return [
getStableGroups(
resp.hits[0],
resp.hits.flat(),
'hierarchy.lvl0'
)
.sort((a, b) => {
Expand Down
Loading