Skip to content

Commit

Permalink
fix(widgets): remove answers widget (#6399)
Browse files Browse the repository at this point in the history
The answers widget has long been deprecated, and is removed without replacement as no answers service exists anymore.

As a userland solution if you're using the answers widget, copy the removed answers files inside your own project and import it locally.

BREAKING CHANGE: the answers widget no longer exists
BREAKING CHANGE: the findAnswers in the helper no longer exists
  • Loading branch information
Haroenv committed Oct 18, 2024
1 parent bedf54d commit 8660605
Show file tree
Hide file tree
Showing 19 changed files with 1 addition and 1,834 deletions.
16 changes: 0 additions & 16 deletions packages/algoliasearch-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import EventEmitter from '@algolia/events';

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type {
FindAnswersResponse,
FrequentlyBoughtTogetherQuery,
HighlightResult,
LookingSimilarQuery,
Expand Down Expand Up @@ -163,21 +162,6 @@ declare namespace algoliasearchHelper {
) => void
): void;

/**
* Start the search for answers with the parameters set in the state.
* This method returns a promise.
* @param {Object} options - the options for answers API call
* @param {string[]} options.attributesForPrediction - Attributes to use for predictions. If empty, `searchableAttributes` is used instead.
* @param {string[]} options.queryLanguages - The languages in the query. Currently only supports ['en'].
* @param {number} options.nbHits - Maximum number of answers to retrieve from the Answers Engine. Cannot be greater than 1000.
* @deprecated answers is deprecated and will be replaced with new initiatives
*/
findAnswers<TObject>(options: {
attributesForPrediction: string[];
queryLanguages: string[];
nbHits: number;
}): Promise<FindAnswersResponse<TObject>>;

/**
* Search for facet values based on an query and the name of a faceted attribute. This
* triggers a search and will return a promise. On top of using the query, it also sends
Expand Down
49 changes: 0 additions & 49 deletions packages/algoliasearch-helper/src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ var EventEmitter = require('@algolia/events');
var DerivedHelper = require('./DerivedHelper');
var escapeFacetValue = require('./functions/escapeFacetValue').escapeFacetValue;
var inherits = require('./functions/inherits');
var merge = require('./functions/merge');
var objectHasKeys = require('./functions/objectHasKeys');
var omit = require('./functions/omit');
var RecommendParameters = require('./RecommendParameters');
var RecommendResults = require('./RecommendResults');
var requestBuilder = require('./requestBuilder');
Expand Down Expand Up @@ -288,53 +286,6 @@ AlgoliaSearchHelper.prototype.searchOnce = function (options, cb) {
);
};

/**
* Start the search for answers with the parameters set in the state.
* This method returns a promise.
* @param {Object} options - the options for answers API call
* @param {string[]} options.attributesForPrediction - Attributes to use for predictions. If empty, `searchableAttributes` is used instead.
* @param {string[]} options.queryLanguages - The languages in the query. Currently only supports ['en'].
* @param {number} options.nbHits - Maximum number of answers to retrieve from the Answers Engine. Cannot be greater than 1000.
*
* @return {promise} the answer results
* @deprecated answers is deprecated and will be replaced with new initiatives
*/
AlgoliaSearchHelper.prototype.findAnswers = function (options) {
// eslint-disable-next-line no-console
console.warn('[algoliasearch-helper] answers is no longer supported');
var state = this.state;
var derivedHelper = this.derivedHelpers[0];
if (!derivedHelper) {
return Promise.resolve([]);
}
var derivedState = derivedHelper.getModifiedState(state);
var data = merge(
{
attributesForPrediction: options.attributesForPrediction,
nbHits: options.nbHits,
},
{
params: omit(requestBuilder._getHitsSearchParams(derivedState), [
'attributesToSnippet',
'hitsPerPage',
'restrictSearchableAttributes',
'snippetEllipsisText',
]),
}
);

var errorMessage =
'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers';
if (typeof this.client.initIndex !== 'function') {
throw new Error(errorMessage);
}
var index = this.client.initIndex(derivedState.index);
if (typeof index.findAnswers !== 'function') {
throw new Error(errorMessage);
}
return index.findAnswers(derivedState.query, options.queryLanguages, data);
};

/**
* Structure of each result when using
* [`searchForFacetValues()`](reference.html#AlgoliaSearchHelper#searchForFacetValues)
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions packages/algoliasearch-helper/types/algoliasearch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,6 @@ export type SearchForFacetValuesResponse = PickForClient<{
v5: AlgoliaSearch.SearchForFacetValuesResponse;
}>;

export type FindAnswersOptions = PickForClient<{
v3: any; // answers only exists in v4
// @ts-ignore
v4: ClientSearch.FindAnswersOptions;
v5: any; // answers only exists in v4
}>;
export type FindAnswersResponse<T> = PickForClient<{
v3: any; // answers only exists in v4
// @ts-ignore
v4: ClientSearch.FindAnswersResponse<T>;
v5: any; // answers only exists in v4
}>;
export type FindAnswers = PickForClient<{
v3: any; // answers only exists in v4
// @ts-ignore
v4: ReturnType<DefaultSearchClient['initIndex']>['findAnswers'];
v5: any; // answers only exists in v4
}>;

export type SupportedLanguage = PickForClient<{
v3: string;
v4: string;
Expand Down
132 changes: 0 additions & 132 deletions packages/instantsearch.js/.storybook/static/answers.css

This file was deleted.

Loading

0 comments on commit 8660605

Please sign in to comment.