Skip to content

Commit 6cb1d0a

Browse files
author
Eunjae Lee
authored
fix(findAnswers): expose in lite version (#1227)
* fix(findAnswers): expose in lite version * test: add browser-lite to integration test for answers
1 parent c7bff86 commit 6cb1d0a

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

packages/algoliasearch/src/builds/browserLite.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { createInMemoryCache } from '@algolia/cache-in-memory';
44
import { AuthMode, version } from '@algolia/client-common';
55
import {
66
createSearchClient,
7+
findAnswers,
8+
FindAnswersOptions,
9+
FindAnswersResponse,
710
initIndex,
811
multipleQueries,
912
MultipleQueriesOptions,
@@ -66,7 +69,7 @@ export default function algoliasearch(
6669
multipleSearchForFacetValues,
6770
initIndex: base => (indexName: string): SearchIndex => {
6871
return initIndex(base)(indexName, {
69-
methods: { search, searchForFacetValues },
72+
methods: { search, searchForFacetValues, findAnswers },
7073
});
7174
},
7275
},
@@ -86,6 +89,11 @@ export type SearchIndex = BaseSearchIndex & {
8689
facetQuery: string,
8790
requestOptions?: RequestOptions & SearchOptions
8891
) => Readonly<Promise<SearchForFacetValuesResponse>>;
92+
readonly findAnswers: (
93+
query: string,
94+
queryLanguages: readonly string[],
95+
requestOptions?: RequestOptions & FindAnswersOptions
96+
) => Readonly<Promise<FindAnswersResponse>>;
8997
};
9098

9199
export type SearchClient = BaseSearchClient & {

specs/answers.spec.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,55 @@ const credentials = {
1818
// apiKey: `${process.env.ALGOLIA_SEARCH_KEY_1}`
1919
};
2020

21-
describe("answers features - algoliasearch.com", () => {
22-
beforeEach(async () => browser.url("algoliasearch.com"));
21+
["algoliasearch-lite.com", "algoliasearch.com"].forEach(preset => {
22+
describe(`answers features - ${preset}`, () => {
23+
beforeEach(async () => browser.url(preset));
2324

24-
it("searchIndex::findAnswers", async () => {
25-
const results: any = await browser.executeAsync(function(
26-
credentials,
27-
done
28-
) {
29-
const client = algoliasearch(credentials.appId, credentials.apiKey);
25+
it("searchIndex::findAnswers", async () => {
26+
const results: any = await browser.executeAsync(function(
27+
credentials,
28+
done
29+
) {
30+
const client = algoliasearch(credentials.appId, credentials.apiKey);
3031

31-
// TODO: remove this customization once the engine accepts url encoded query params
32-
client.transporter.userAgent.value = "answers-test";
32+
// TODO: remove this customization once the engine accepts url encoded query params
33+
client.transporter.userAgent.value = "answers-test";
3334

34-
const index = client.initIndex("ted");
35+
const index = client.initIndex("ted");
3536

36-
Promise.all([
37-
index.findAnswers("sir ken robinson", ["en"]),
38-
index.findAnswers("what", ["en"]),
39-
index.findAnswers("sarah jones", ["en"], {
40-
nbHits: 2,
41-
attributesForPrediction: ["main_speaker"],
42-
params: {
43-
highlightPreTag: "_pre_",
44-
highlightPostTag: "_post_"
45-
}
46-
})
47-
]).then(function(responses) {
48-
done({
49-
kenRobinson: responses[0],
50-
what: responses[1],
51-
sarah: responses[2]
37+
Promise.all([
38+
index.findAnswers("sir ken robinson", ["en"]),
39+
index.findAnswers("what", ["en"]),
40+
index.findAnswers("sarah jones", ["en"], {
41+
nbHits: 2,
42+
attributesForPrediction: ["main_speaker"],
43+
params: {
44+
highlightPreTag: "_pre_",
45+
highlightPostTag: "_post_"
46+
}
47+
})
48+
]).then(function(responses) {
49+
done({
50+
kenRobinson: responses[0],
51+
what: responses[1],
52+
sarah: responses[2]
53+
});
5254
});
53-
});
54-
},
55-
credentials);
55+
},
56+
credentials);
5657

57-
expect(results.kenRobinson.nbHits).toBe(10);
58+
expect(results.kenRobinson.nbHits).toBe(10);
5859

59-
expect(results.what.nbHits).toBe(0);
60+
expect(results.what.nbHits).toBe(0);
6061

61-
expect(results.sarah.nbHits).toBe(1);
62-
expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe(
63-
"_pre_Sarah_post_ _pre_Jones_post_"
64-
);
62+
expect(results.sarah.nbHits).toBe(1);
63+
expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe(
64+
"_pre_Sarah_post_ _pre_Jones_post_"
65+
);
6566

66-
expect(results.sarah.hits[0]._answer.extract).toBe(
67-
"_pre_Sarah_post_ _pre_Jones_post_"
68-
);
67+
expect(results.sarah.hits[0]._answer.extract).toBe(
68+
"_pre_Sarah_post_ _pre_Jones_post_"
69+
);
70+
});
6971
});
7072
});

0 commit comments

Comments
 (0)