Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

feat(answers): add findAnswers #804

Merged
merged 12 commits into from Dec 23, 2020
Merged

feat(answers): add findAnswers #804

merged 12 commits into from Dec 23, 2020

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Dec 14, 2020

This PR adds findAnswers method.
In this way, we can apply facets to /answers call.

It doesn't emit 'result' but returns a promise of result.
If we can replace the traditional hits with the hits from answers completely, then we should go for emitting 'result', but it's not the case at the moment. So I chose to return a promise.

Let me know what you think.

(I haven't added any tests because we haven't agreed on how to implement this in helper yet. Once decided here, I will add test.)

@eunjae-lee eunjae-lee requested a review from a team December 14, 2020 17:09
@ghost ghost requested review from francoischalifour and Haroenv and removed request for a team December 14, 2020 17:09
src/algoliasearch.helper.js Outdated Show resolved Hide resolved
src/algoliasearch.helper.js Outdated Show resolved Hide resolved
src/algoliasearch.helper.js Outdated Show resolved Hide resolved
'attributesToSnippet',
'hitsPerPage',
'restrictSearchableAttributes',
'snippetEllipsisText' // FIXME remove this line once the engine is fixed.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the doc, snippetEllipsisText is throwing an error. I've reported it to the team, but for now let's have it here.

@eunjae-lee eunjae-lee changed the title feat(answers): add searchForAnswers WIP feat(answers): add searchForAnswers Dec 22, 2020
@eunjae-lee eunjae-lee changed the title feat(answers): add searchForAnswers feat(answers): add findAnswers Dec 22, 2020
@eunjae-lee eunjae-lee changed the title feat(answers): add findAnswers feat(answers): add findAnswers Dec 22, 2020
@eunjae-lee eunjae-lee marked this pull request as ready for review December 22, 2020 13:41
index.d.ts Outdated
queryLanguages: string[];
nbHits: number;
}): Promise<{
hits: Array<any & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you not use the return type of findAnswers on the client?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method likely should be generic, like the client one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the dependency and now it's using the type from the client:
da8af13

Comment on lines 253 to 272
/**
* @typedef Answer
* @type {object}
* @property {string} extract the extracted value with highlights
* @property {string} extractAttribute the attribute used to extract the answer
* @property {number} score the score indicating how well it was matched
*/

/**
* @typedef AnswerHit
* @type {object}
* @property {Answer} _answer the object describing why the hit was chosen
*/

/**
* @typedef AnswersResult
* @type {object}
* @property {AnswerHit[]} hits the answer hits
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these docs aren't used as explanation while there's the definition file (only locally), so I don't think it's needed.

Are you allowed to omit the return type all together or does eslint not allow it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think? 5aa1206

Comment on lines 310 to 316
'search for answers was called, but this client does not have a function client.initIndex'
);
}
var index = this.client.initIndex(derivedState.index);
if (typeof index.findAnswers !== 'function') {
throw new Error(
'search for answers was called, but this client does not have a function client.initIndex(index).findAnswers'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is helpful, but the second error message gives pretty much the same information. Could it be consolidated to save space? How do we do it in searchForFacetValues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike SFFV, the existence of findAnswers can be checked only after creating index here. So I couldn't merge them in a single conditional block.
2433fb1

index.d.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@eunjae-lee eunjae-lee merged commit 4635dd5 into develop Dec 23, 2020
@eunjae-lee eunjae-lee deleted the feat/answers branch December 23, 2020 16:30
eunjae-lee added a commit that referenced this pull request Jan 12, 2021
 * feat(answers): add  (#804) 4635dd5
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
* feat(answers): add searchForAnswers WIP

* update parameters

* add a FIXME comment

* accept options as an object

* add jsdoc and typings

* add test cases

* fix lint error

* better types

* clean up error message

* Update src/algoliasearch.helper.js

Co-authored-by: Haroen Viaene <hello@haroen.me>

* remove jsdoc

* fix type

Co-authored-by: Haroen Viaene <hello@haroen.me>
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants