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(theme): SearchPage should respect contextualSearch: false setting #10178

Merged
merged 3 commits into from
May 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ function SearchPageContent(): JSX.Element {
i18n: {currentLocale},
} = useDocusaurusContext();
const {
algolia: {appId, apiKey, indexName},
algolia: {appId, apiKey, indexName, contextualSearch},
} = useAlgoliaThemeConfig();

const processSearchResultUrl = useSearchResultUrlProcessor();
const documentsFoundPlural = useDocumentsFoundPlural();

Expand Down Expand Up @@ -213,11 +214,16 @@ function SearchPageContent(): JSX.Element {
initialSearchResultState,
);

// respect settings from the theme config for facets
const disjunctiveFacets = contextualSearch
? ['language', 'docusaurus_tag']
: [];

const algoliaClient = algoliaSearch(appId, apiKey);
const algoliaHelper = algoliaSearchHelper(algoliaClient, indexName, {
hitsPerPage: 15,
advancedSyntax: true,
disjunctiveFacets: ['language', 'docusaurus_tag'],
disjunctiveFacets,
});

algoliaHelper.on(
Expand Down Expand Up @@ -313,17 +319,19 @@ function SearchPageContent(): JSX.Element {
});

const makeSearch = useEvent((page: number = 0) => {
algoliaHelper.addDisjunctiveFacetRefinement('docusaurus_tag', 'default');
algoliaHelper.addDisjunctiveFacetRefinement('language', currentLocale);

Object.entries(docsSearchVersionsHelpers.searchVersions).forEach(
([pluginId, searchVersion]) => {
algoliaHelper.addDisjunctiveFacetRefinement(
'docusaurus_tag',
`docs-${pluginId}-${searchVersion}`,
);
},
);
if (contextualSearch) {
algoliaHelper.addDisjunctiveFacetRefinement('docusaurus_tag', 'default');
algoliaHelper.addDisjunctiveFacetRefinement('language', currentLocale);

Object.entries(docsSearchVersionsHelpers.searchVersions).forEach(
([pluginId, searchVersion]) => {
algoliaHelper.addDisjunctiveFacetRefinement(
'docusaurus_tag',
`docs-${pluginId}-${searchVersion}`,
);
},
);
}

algoliaHelper.setQuery(searchQuery).setPage(page).search();
});
Expand Down Expand Up @@ -401,7 +409,7 @@ function SearchPageContent(): JSX.Element {
/>
</div>

{docsSearchVersionsHelpers.versioningEnabled && (
{contextualSearch && docsSearchVersionsHelpers.versioningEnabled && (
<SearchVersionSelectList
docsSearchVersionsHelpers={docsSearchVersionsHelpers}
/>
Expand Down