-
Notifications
You must be signed in to change notification settings - Fork 73
feat(search-client): Add support for Custom Search Clients #111
Conversation
Deploy preview for angular-instantsearch ready! Built with commit 512d6c7 https://deploy-preview-111--angular-instantsearch.netlify.com |
src/instantsearch/instantsearch.ts
Outdated
@@ -28,6 +29,7 @@ export type InstantSearchConfig = { | |||
appId: string, | |||
apiKey: string | |||
) => object; | |||
searchClient?: object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of rely on the object
type we can create a new type that will better represent what we expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't done for searchParameters
though, I was wondering if there was a reason, @iam4x?
Otherwise, I will add a more strict type for searchClient
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, for the SearchParameters
it's a bit more tedious because the data structure is way more larger. But we should add the correct types at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
searchParameters
are what the Algolia API expect, it's hard to type since it can change at any time without our control.
Here you should create a type and use it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'm working on the type according to the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can import searchParameters from the typing of algoliasearch
@@ -60,10 +60,14 @@ export class AppComponent {} | |||
> A hook that will be called each time a search needs to be done, with the helper as a parameter. It’s your responsibility to call `helper.search()`. This option allows you to avoid doing searches at page load for example. | |||
|
|||
`createAlgoliaClient?: (algoliasearch: Function, appId: string, apiKey: string) => CustomClient` | |||
> _Deprecated in favor of `searchClient`._ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not want to deprecate this yet, it is still used for the server side rendering strategy:
import {
createSSRAlgoliaClient,
parseServerRequest
} from "angular-instantsearch";
[...]
constructor(
private httpClient: HttpClient,
private transferState: TransferState,
private injector: Injector,
@Inject(PLATFORM_ID) private platformId: Object
) {
const req = isPlatformServer(this.platformId)
? this.injector.get("request")
: undefined;
const searchParameters = parseServerRequest(req);
this.instantSearchConfig = {
searchParameters,
appId: "latency",
apiKey: "6be0576ff61c053d5f9a3225e2a90f76",
indexName: "ikea",
urlSync: true,
createAlgoliaClient: createSSRAlgoliaClient({
makeStateKey,
HttpHeaders,
transferState: this.transferState,
httpClient: this.httpClient
})
};
}
If we want to get rid of createAlgoliaClient
we have to support server side rendering as well with the new method.
I can help for this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added createSSRSearchClient()
and deprecated createSSRAlgoliaClient()
. Hope this is how you envisioned it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @francoischalifour
This PR adds support for the
searchClient
parameter. This allows any Angular InstantSearch user to plug their own search client (including a custom Algolia backend).Example
Related