Skip to content

Commit

Permalink
fix(theme): SearchPage should respect contextualSearch: false setti…
Browse files Browse the repository at this point in the history
…ng (#10178)

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
  • Loading branch information
3 people authored May 30, 2024
1 parent bc71803 commit 1049294
Showing 1 changed file with 22 additions and 14 deletions.
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

0 comments on commit 1049294

Please sign in to comment.