Coder Social home page Coder Social logo

davidalphafox / instant-meilisearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meilisearch/meilisearch-js-plugins

0.0 1.0 0.0 2.18 MB

The search client to use MeiliSearch with InstantSearch.

License: MIT License

JavaScript 49.31% Shell 1.45% HTML 14.34% Vue 12.59% CSS 22.31%

instant-meilisearch's Introduction

Instant-MeiliSearch

Instant MeiliSearch

MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ

npm version Tests License Bors enabled

⚡ How to integrate a front-end search bar in your website using MeiliSearch

MeiliSearch is an open-source search engine. Discover what MeiliSearch is!

This library is a plugin to establish the communication between your MeiliSearch instance and the open-source InstantSearch tools (powered by Algolia) for your front-end application.
Instead of reinventing the wheel, we have opted to reuse the InstantSearch library for our own front-end tooling. We will contribute upstream any improvements that may result from our adoption of InstantSearch.

If you use React or Vue, you might want to check out these repositories:

NB: If you don't have any MeiliSearch instance running and containing your data, you should take a look at this getting started page.

Installation

Use npm or yarn to install instant-meilisearch:

$ npm install @meilisearch/instant-meilisearch
$ yarn add @meilisearch/instant-meilisearch

Usage

Basic

import instantMeiliSearch from "@meilisearch/instant-meilisearch";

const searchClient = instantMeiliSearch(
  "https://demos.meilisearch.com",
  "dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25"
);

Customization

import instantMeiliSearch from "@meilisearch/instant-meilisearch";

const searchClient = instantMeiliSearch(
  "https://demos.meilisearch.com",
  "dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25",
  {
    paginationTotalHits: 30, // default: 200.
    placeholderSearch: false // default: true.
  }
);
  • placeholderSearch (true by default). Displays documents even when the query is empty.

  • paginationTotalHits (200 by default): The total (and finite) number of hits you can browse during pagination when using the pagination widget. If the pagination widget is not used, paginationTotalHits is ignored.
    Which means that, with a paginationTotalHits default value of 200, and hitsPerPage default value of 20, you can browse paginationTotalHits / hitsPerPage => 200 / 20 = 10 pages during pagination. Each of the 10 pages containing 20 results.
    The default value of hitsPerPage is set to 20 but it can be changed with InsantSearch.configure.
    ⚠️ MeiliSearch is not designed for pagination and this can lead to performances issues, so the usage of the pagination widget is not encouraged. However, the paginationTotalHits parameter lets you implement this pagination with less performance issue as possible: depending on your dataset (the size of each document and the number of documents) you might decrease the value of paginationTotalHits.
    More information about MeiliSearch and the pagination here.

Example with InstantSearch

The open-source InstantSearch library powered by Algolia provides all the front-end tools you need to highly customize your search bar environment.

In index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
  </head>

  <body>
    <div>
      <div id="searchbox"></div>
      <div id="hits"></div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
    <script src="./app.js"></script>
  </body>
</html>

In app.js:

const search = instantsearch({
  indexName: "steam-video-games",
  searchClient: instantMeiliSearch(
    "https://demos.meilisearch.com",
    "dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25",
  )
});

search.addWidgets([
  instantsearch.widgets.searchBox({
    container: "#searchbox"
  }),
  instantsearch.widgets.hits({
    container: "#hits",
    templates: {
      item: `
        <div>
          <div class="hit-name">
            {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
          </div>
        </div>
      `
    }
  })
]);

search.start();

🚀 For a full getting started example, please take a look at this CodeSandbox:

Edit MS + IS

💡 If you have never used InstantSearch, we recommend reading this getting started documentation.

More Documentation

Compatibility with MeiliSearch

This package only guarantees the compatibility with the version v0.18.1 of MeiliSearch.

Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!


MeiliSearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.

instant-meilisearch's People

Contributors

andrelillvede avatar bb avatar bidoubiwa avatar bors[bot] avatar curquiza avatar dependabot-preview[bot] avatar dependabot[bot] avatar meili-bot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.