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(findAnswers): expose in lite version #1227

Merged
merged 2 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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_"
);
});
});
});