Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(search-client): Add support for Custom Search Clients #432

Merged
merged 7 commits into from
Apr 25, 2018

Conversation

francoischalifour
Copy link
Member

@francoischalifour francoischalifour commented Apr 25, 2018

This PR adds support for the search-client prop. This allows any InstantSearch user to plug their own search client (including a custom Algolia backend).

Usage

<template>
  <ais-index
    index-name="instant_search"
    :searchClient="searchClient"
  >
  ...
  </ais-index>
</template>

<script>
  import algoliasearch from "algoliasearch/lite";

  export default {
    data() {
      return {
        searchClient: algoliasearch("latency", "6be0576ff61c053d5f9a3225e2a90f76")
      };
    }
  };
</script>

Demo

View Demo

(see file src/App.vue)

Related feature in InstantSearch.js

algolia/instantsearch#2894

);
}

this._localSearchStore = createFromAlgoliaClient(Object.create(this.searchClient));
Copy link
Member Author

Choose a reason for hiding this comment

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

Object.create() is not necessary here. I will remove it.

} else {
this._localSearchStore = this.searchStore;
if (!this.searchStore) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be changed to else if I think :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, ESLint is never happy with that ahah.

Copy link
Contributor

@bobylito bobylito left a comment

Choose a reason for hiding this comment

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

Looks good to me

const client = this._helper.getClient();

if (typeof client.addAlgoliaAgent === 'function') {
client.addAlgoliaAgent(`vue-instantsearch ${version}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could add this conditionally in the helper so we can call it without checking here

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm OK with this change. It's yet another helper upgrade though haha. WDYT @bobylito?

@Haroenv
Copy link
Contributor

Haroenv commented Apr 25, 2018

I wonder if this deserves a mention in the search store guide

@francoischalifour
Copy link
Member Author

francoischalifour commented Apr 25, 2018

@Haroenv I've never really used Vue InstantSearch so you decide what's better for the users! How would you see that?

We could add another section below "Create a search store from an Algolia client instance" like "Create a search store from a custom client instance".

We'll have to document both search() and searchForFacetValues() methods.

@Haroenv
Copy link
Contributor

Haroenv commented Apr 25, 2018

A section there seems good!

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.

3 participants