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 1 commit
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 @@
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 @@
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: disjunctiveFacets,

Check failure on line 226 in packages/docusaurus-theme-search-algolia/src/theme/SearchPage/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expected property shorthand
slorber marked this conversation as resolved.
Show resolved Hide resolved
});

algoliaHelper.on(
Expand Down Expand Up @@ -313,17 +319,19 @@
});

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
Loading