Skip to content

Commit

Permalink
fix(findAnswers): expose in lite version (#1227)
Browse files Browse the repository at this point in the history
* fix(findAnswers): expose in lite version

* test: add browser-lite to integration test for answers
  • Loading branch information
Eunjae Lee authored Nov 18, 2020
1 parent c7bff86 commit 6cb1d0a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
10 changes: 9 additions & 1 deletion packages/algoliasearch/src/builds/browserLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { createInMemoryCache } from '@algolia/cache-in-memory';
import { AuthMode, version } from '@algolia/client-common';
import {
createSearchClient,
findAnswers,
FindAnswersOptions,
FindAnswersResponse,
initIndex,
multipleQueries,
MultipleQueriesOptions,
Expand Down Expand Up @@ -66,7 +69,7 @@ export default function algoliasearch(
multipleSearchForFacetValues,
initIndex: base => (indexName: string): SearchIndex => {
return initIndex(base)(indexName, {
methods: { search, searchForFacetValues },
methods: { search, searchForFacetValues, findAnswers },
});
},
},
Expand All @@ -86,6 +89,11 @@ export type SearchIndex = BaseSearchIndex & {
facetQuery: string,
requestOptions?: RequestOptions & SearchOptions
) => Readonly<Promise<SearchForFacetValuesResponse>>;
readonly findAnswers: (
query: string,
queryLanguages: readonly string[],
requestOptions?: RequestOptions & FindAnswersOptions
) => Readonly<Promise<FindAnswersResponse>>;
};

export type SearchClient = BaseSearchClient & {
Expand Down
80 changes: 41 additions & 39 deletions specs/answers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,55 @@ const credentials = {
// apiKey: `${process.env.ALGOLIA_SEARCH_KEY_1}`
};

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

it("searchIndex::findAnswers", async () => {
const results: any = await browser.executeAsync(function(
credentials,
done
) {
const client = algoliasearch(credentials.appId, credentials.apiKey);
it("searchIndex::findAnswers", async () => {
const results: any = await browser.executeAsync(function(
credentials,
done
) {
const client = algoliasearch(credentials.appId, credentials.apiKey);

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

const index = client.initIndex("ted");
const index = client.initIndex("ted");

Promise.all([
index.findAnswers("sir ken robinson", ["en"]),
index.findAnswers("what", ["en"]),
index.findAnswers("sarah jones", ["en"], {
nbHits: 2,
attributesForPrediction: ["main_speaker"],
params: {
highlightPreTag: "_pre_",
highlightPostTag: "_post_"
}
})
]).then(function(responses) {
done({
kenRobinson: responses[0],
what: responses[1],
sarah: responses[2]
Promise.all([
index.findAnswers("sir ken robinson", ["en"]),
index.findAnswers("what", ["en"]),
index.findAnswers("sarah jones", ["en"], {
nbHits: 2,
attributesForPrediction: ["main_speaker"],
params: {
highlightPreTag: "_pre_",
highlightPostTag: "_post_"
}
})
]).then(function(responses) {
done({
kenRobinson: responses[0],
what: responses[1],
sarah: responses[2]
});
});
});
},
credentials);
},
credentials);

expect(results.kenRobinson.nbHits).toBe(10);
expect(results.kenRobinson.nbHits).toBe(10);

expect(results.what.nbHits).toBe(0);
expect(results.what.nbHits).toBe(0);

expect(results.sarah.nbHits).toBe(1);
expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe(
"_pre_Sarah_post_ _pre_Jones_post_"
);
expect(results.sarah.nbHits).toBe(1);
expect(results.sarah.hits[0]._highlightResult.main_speaker.value).toBe(
"_pre_Sarah_post_ _pre_Jones_post_"
);

expect(results.sarah.hits[0]._answer.extract).toBe(
"_pre_Sarah_post_ _pre_Jones_post_"
);
expect(results.sarah.hits[0]._answer.extract).toBe(
"_pre_Sarah_post_ _pre_Jones_post_"
);
});
});
});

0 comments on commit 6cb1d0a

Please sign in to comment.