feat(v2): contextual search, dynamic Algolia facetFilters (#3550)

* POC of contextual search dynamic filters

* fix useSearchTags bugs

* contextual search should use preferred version  (persisted in storage)

* Contextual search: make system decoupled from algolia + wire proper meta tags and facet filters

* rework doc tag + minor refactorings

* update snapshots

* polish contextual search

* add Algolia validateThemeConfig tests
This commit is contained in:
Sébastien Lorber 2020-10-15 12:16:30 +02:00 committed by GitHub
parent d23940c9c3
commit 21264f5ed0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 468 additions and 138 deletions

View file

@ -8,17 +8,28 @@
const Joi = require('@hapi/joi');
const DEFAULT_CONFIG = {
contextualSearch: false, // future: maybe we want to enable this by default
// By default, all Docusaurus sites are using the same AppId
// This has been designed on purpose with Algolia.
appId: 'BH4D9OD16A',
searchParameters: {},
};
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
const Schema = Joi.object({
algolia: Joi.object({
// Docusaurus attributes
contextualSearch: Joi.boolean().default(DEFAULT_CONFIG.contextualSearch),
// Algolia attributes
appId: Joi.string().default(DEFAULT_CONFIG.appId),
apiKey: Joi.string().required(),
indexName: Joi.string().required(),
searchParameters: Joi.object()
.default(DEFAULT_CONFIG.searchParameters)
.unknown(),
})
.label('themeConfig.algolia')
.required()
@ -30,5 +41,17 @@ exports.validateThemeConfig = function validateThemeConfig({
validate,
themeConfig,
}) {
return validate(Schema, themeConfig);
const normalizedThemeConfig = validate(Schema, themeConfig);
if (
normalizedThemeConfig &&
normalizedThemeConfig.algolia.contextualSearch &&
normalizedThemeConfig.algolia.searchParameters &&
normalizedThemeConfig.algolia.searchParameters.facetFilters
) {
throw new Error(
'If you are using algolia.contextualSearch: true, you should not provide algolia.searchParameters.facetFilters, as it is computed for you dynamically',
);
}
return normalizedThemeConfig;
};