• Stars
    star
    161
  • Rank 225,213 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Front-end search bar for documentation with Meilisearch

Meilisearch

DEPRECATED - docs-searchbar.js


🚨 DEPRECATION WARNING 🚨

Dear Community,

We'd like to share some updates regarding the future maintenance of this repository:

Our team is small, and our availability will be reduced in the upcoming times. As such, we decided to deprecate this repository. We invite you into using Tauri's meilisearch-docsearch instead of this one.

We still accept bug fixes from the community but no more enhancements.

Seeking immediate support? Please join us on our Discord channel.


Meilisearch | Meilisearch Cloud | Documentation | Discord | Roadmap | Website | FAQ

NPM version Test License Bors enabled

docs-searchbar.js is a front-end SDK for Meilisearch providing a search bar for your documentation.

docs-searchbar.js comes with a css template. The default styling of this library fits a documentation search bar, but you can customize it.

To make it work, You need to have your documentation's content in a Meilisearch instance. If not already the case, you can achieve this using docs-scraper.

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

docs-searchbar.js example

💡 If you use VuePress for your website, you should check out our VuePress plugin for Meilisearch.

Table of Contents

⚡ Supercharge your Meilisearch experience

Say goodbye to server deployment and manual updates with Meilisearch Cloud. Get started with a 14-day free trial! No credit card required.

🔧 Installation

With npm:

We only guarantee that the package works with node >= 12 and node < 15.

# With NPM
npm install docs-searchbar.js
# With Yarn
yarn add docs-searchbar.js

In your HTML:

Add the following script into your HTML file:

<script src="https://cdn.jsdelivr.net/npm/docs-searchbar.js@latest/dist/cdn/docs-searchbar.min.js"></script>

🏃‍♀️ Run Meilisearch

There are many easy ways to download and run a Meilisearch instance.

For example, using the curl command in your Terminal:

# Install Meilisearch
curl -L https://install.meilisearch.com | sh

# Launch Meilisearch
./meilisearch --master-key=masterKey

NB: you can also download Meilisearch from Homebrew or APT or even run it using Docker.

Index your data

The goal of this library is to provide a front-end search bar into your own documentation. To make that possible, you need to gather your website content in advance, and index it in a Meilisearch instance.

Luckily, we provide all the tools that you need, and can help you through the whole process, if you follow this guide 🚀

Note: If you want to try out docs-searchbar.js as a first introduction, try out our playground.

Use your own scraper

We recommend using the docs-scraper tool to scrape your website, but this is not mandatory.

If you already have your own scraper but you still want to use Meilisearch and docs-searchbar.js, check out this discussion.

🎬 Getting Started

ES module

Add an input tag with the attribute id="search-bar-input in one of your HTML file.

<input type="search" id="search-bar-input" />

Then, import docs-searchbar.js and run the docsSearchBar function. For more explaination of the required parameters, see next section.

import docsSearchBar from 'docs-searchbar.js'

docsSearchBar({
  hostUrl: 'https://mymeilisearch.com',
  apiKey: 'XXX',
  indexUid: 'docs',
  inputSelector: '#search-bar-input',
})

HTML

Add the following code to one of your HTML files.

<!DOCTYPE html>
<html>
  <head>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/docs-searchbar.js@latest/dist/cdn/docs-searchbar.min.css"
    />
  </head>

  <body>
    <input type="search" id="search-bar-input" />
    <script src="https://cdn.jsdelivr.net/npm/docs-searchbar.js@latest/dist/cdn/docs-searchbar.min.js"></script>
    <script>
      docsSearchBar({
        hostUrl: 'https://mymeilisearch.com',
        apiKey: 'XXX',
        indexUid: 'docs',
        inputSelector: '#search-bar-input',
        debug: true, // Set debug to true if you want to inspect the dropdown
      })
    </script>
  </body>
</html>

The hostUrl and the apiKey (optional) fields are the credentials of your Meilisearch instance.
indexUid is the index identifier in your Meilisearch instance in which your website content is stored.
inputSelector is the id attribute of the HTML search input tag. As an alternative the dom element can be supplied with inputElement directly.

Your documentation content is not indexed yet? Check out this tutorial.

WARNING: We recommend providing the Meilisearch public key, which is enough to perform search requests.
Read more about Meilisearch authentication.

Styling

docs-searchbar.js comes with a css template. It has to be added in your project in the following way:

In an ES+ environment:

import 'docs-searchbar.js/dist/cdn/docs-searchbar.css'

In a HTML file, the link tag should be added in your header:

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/docs-searchbar.js@latest/dist/cdn/docs-searchbar.min.css"
/>

🎨 Customization

The default behavior of this library fits perfectly for a documentation search bar, but you might need some customizations.

Optional parameters

When calling the docsSearchBar method, you can add optional fields:

queryHook

queryHook takes a callback function as value. This function will be called on every keystroke to transform the typed keywords before querying Meilisearch. By default, it does not do anything, but it is the perfect place for you to add some preprocessing or custom functionality.

transformData

transformData takes a callback function as value. This function will be called on every hit before displaying them. By default, it does not do anything, but it lets you add any post-processing around the data you received from Meilisearch.

handleSelected

handleSelected takes a callback function a value. This function is called when a suggestion is selected (either from a click or a keystroke). By default, it displays anchor links to the results page. Here is an example to override this behavior:

docsSearchBar({
  // ...
  handleSelected: function (input, event, suggestion, datasetNumber, context) {
    // Prevents the default behavior on click and rather opens the suggestion
    // in a new tab.
    if (context.selectionMethod === 'click') {
      input.setVal('')

      const windowReference = window.open(suggestion.url, '_blank')
      windowReference.focus()
    }
  },
})

Note that, by default, you can already open a new tab thanks to the CMD/CTRL + Click action.

The function is called with the following arguments:

  • input: a reference to the search input element. It comes with the .open(), .close(), .getVal() and .setVal() methods.

  • event: the actual event triggering the selection.

  • suggestion: the object representing the current selection. It contains a .url key representing the destination.

  • datasetNumber: this should always be equal to 1 as docs-searchbar.js is searching into one dataset at a time. You can ignore this attribute.

  • context: additional information about the selection. Contains a .selectionMethod key that can be either click, enterKey, tabKey or blur, depending on how the suggestion was selected.

meilisearchOptions

You can forward search parameters to the Meilisearch API by using the meilisearchOptions key. Checkout out the Meilisearch documentation about search parameters.

For example, you might want to increase the number of results displayed in the dropdown:

docsSearchBar({
  meilisearchOptions: {
    limit: 10,
  },
})

enableDarkMode

Allows you to display the searchbar in dark mode. It is useful if your website has dark mode support and you also want the searchbar to appear in a dark version. You can always edit the style of the searchbar to match the style of your website. When the option enableDarkMode is set to auto, the searchbar automatically sets the mode to the system mode.

enableDarkMode has three possible states:

  • false: enforce light mode.
  • true: enforce dark mode.
  • auto: system mode (light or dark).

Example:

docsSearchBar({
  ...
  enableDarkMode: 'auto'
})

Dark mode with enableDarkMode set to auto and system mode set to dark:

docs-searchbar with dark mode

enhancedSearchInput

When set to true, a theme is applied to the search box to improve its appearance. It adds the .searchbox class which can be used to further customise the search box.

Example:

docsSearchBar({
  ...
  enhancedSearchInput: true
})
More Examples

Here is a basic HTML file used in the playground of this repository.

As a more concrete example, you can check out the configuration applied in the Meilisearch plugin for VuePress.

Styling

/* Main dropdown wrapper */
.meilisearch-autocomplete .dsb-dropdown-menu {
  width: 500px;
}

/* Main category */
.meilisearch-autocomplete .docs-searchbar-suggestion--category-header {
  color: darkgray;
  border: 1px solid gray;
}

/* Category */
.meilisearch-autocomplete .docs-searchbar-suggestion--subcategory-column {
  color: gray;
}

/* Title */
.meilisearch-autocomplete .docs-searchbar-suggestion--title {
  font-weight: bold;
  color: black;
}

/* Description */
.meilisearch-autocomplete .docs-searchbar-suggestion--text {
  font-size: 0.8rem;
  color: gray;
}

/* Highlighted text */
.meilisearch-autocomplete .docs-searchbar-suggestion--highlight {
  color: blue;
}

TIPS: When inspecting the dropdown markup with your browser tools, you should add debug: true to your docsSearchBar call to prevent it from closing on inspection.

More Examples

Here is the CSS customization applied in the Meilisearch plugin for VuePress.

🤖 Compatibility with Meilisearch

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present. Please check the issues for more info.

⚙️ 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!

🥇 Credits

Based on Algolia DocSearch repository from this commit.
Due to a lot of future changes in this repository compared to the original one, we don't maintain it as an official fork.


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.

More Repositories

1

meilisearch

A lightning-fast search API that fits effortlessly into your apps, websites, and workflow
Rust
43,248
star
2

meilisearch-js

JavaScript client for the Meilisearch API
TypeScript
672
star
3

meilisearch-php

PHP wrapper for the Meilisearch API
PHP
543
star
4

meilisearch-laravel-scout

MeiliSearch integration for Laravel Scout
PHP
467
star
5

milli

Search engine library for Meilisearch ⚡️
Rust
459
star
6

meilisearch-js-plugins

The search client to use Meilisearch with InstantSearch.
TypeScript
449
star
7

meilisearch-go

Golang wrapper for the Meilisearch API
Go
444
star
8

heed

A fully typed LMDB wrapper with minimum overhead 🐦
Rust
424
star
9

meilisearch-python

Python wrapper for the Meilisearch API
Python
400
star
10

MeiliES

A Rust based event store using the Redis protocol
Rust
326
star
11

meilisearch-rust

Rust wrapper for the Meilisearch API.
Rust
316
star
12

meilisearch-rails

Meilisearch integration for Ruby on Rails
Ruby
273
star
13

docs-scraper

Scrape documentation into Meilisearch
Python
257
star
14

meilisearch-dotnet

.NET wrapper for the Meilisearch API
C#
232
star
15

strapi-plugin-meilisearch

A strapi plugin to add your collections to Meilisearch
JavaScript
208
star
16

mini-dashboard

mini-dashboard for Meilisearch
JavaScript
204
star
17

charabia

Library used by Meilisearch to tokenize queries and documents
Rust
202
star
18

meilisearch-ruby

Ruby SDK for the Meilisearch API
Ruby
186
star
19

meilisearch-react

182
star
20

meilisearch-kubernetes

Meilisearch on Kubernetes Helm charts and manifests
Mustache
181
star
21

arroy

Annoy-inspired Approximate Nearest Neighbors in Rust, based on LMDB and optimized for memory usage 💥
Rust
170
star
22

meilisearch-java

Java client for Meilisearch
Java
163
star
23

meilisearch-vue

148
star
24

documentation

Meilisearch documentation
MDX
132
star
25

integration-guides

Central reference for Meilisearch integrations.
Shell
127
star
26

meilisearch-symfony

Seamless integration of Meilisearch into your Symfony project.
PHP
111
star
27

awesome-meilisearch

A curated list of awesome Meilisearch resources
88
star
28

meilisearch-swift

Swift client for the Meilisearch API
Swift
87
star
29

firestore-meilisearch

Fulltext search on Firebase with Meilisearch
TypeScript
83
star
30

meilisearch-dart

The Meilisearch API client written for Dart
Dart
73
star
31

ecommerce-demo

Nuxt 3 ecommerce site search with filtering and facets powered by Meilisearch
Vue
73
star
32

vuepress-plugin-meilisearch

Add a relevant and typo tolerant search bar to your VuePress
JavaScript
62
star
33

saas-demo

App search in a CRM use case, powered by Meilisearch
PHP
58
star
34

product

Public feedback and ideation discussions for Meilisearch product 🔮
55
star
35

meilisearch-wordpress

WordPress plugin for Meilisearch.
PHP
53
star
36

demos

A list of Meilisearch demos with open-source code and live preview ⚡️
CoffeeScript
43
star
37

gatsby-plugin-meilisearch

A plugin to index your Gatsby content to Meilisearch based on graphQL queries
JavaScript
40
star
38

demo-movies

A website that lets you know where to watch a movie
JavaScript
34
star
39

landing

Meilisearch's landing page
JavaScript
33
star
40

meilisearch-migration

Scripts to update Meilisearch version's.
Shell
32
star
41

devrel

Anything Developer Relations at Meili
CSS
27
star
42

meilisearch-digitalocean

Meilisearch services on DigitalOcean
Python
24
star
43

meilisearch-angular

Instant Meilisearch for Angular Framework
23
star
44

deserr

Deserialization library with focus on error handling
Rust
22
star
45

meilisearch-aws

AWS services for Meilisearch
Python
20
star
46

cargo-flaky

A cargo sub-command to helps you find flaky tests
Rust
20
star
47

meilisearch-gcp

Meilisearch services on GCP
Python
20
star
48

grenad

Tools to sort, merge, write, and read immutable key-value pairs 🍅
Rust
19
star
49

specifications

Track specification elaboration.
18
star
50

madness

an async mdns library for tokio
Rust
17
star
51

demo-finding-crates

Expose all crates from crates.io with MeiliSearch
Rust
17
star
52

scrapix

TypeScript
16
star
53

transplant

Rust
15
star
54

cloud-providers

☁ Meilisearch DevOps Tools for the Cloud ☁
Shell
15
star
55

engine-team

Repository gathering the development process of the core-team
13
star
56

meilisearch-importer

A CLI to import massive CSV and NdJson into Meilisearch
Rust
12
star
57

compute-embeddings

A small tool to compute the embeddings of a list of JSON documents
Rust
10
star
58

cloud-scripts

Cloud scripts for cloud provider agnostic configuration
Shell
9
star
59

demo-finding-rubygems

Alternative search bar for RubyGems
Ruby
8
star
60

minimeili-raft

A small implementation of a dummy Meilisearch running on top of Raft
Rust
7
star
61

demo-MoMA

A MeiliSearch demo using the Museum Of Modern Art Collection
JavaScript
6
star
62

strapi-plugin-meilisearch-v4

Work in progress
JavaScript
6
star
63

searchbar.js

wip
JavaScript
6
star
64

meili-aoc

meili-aoc
Rust
5
star
65

mini-search-engine-presentation

A simple and "short" presentation of the search engine
5
star
66

vercel-demo

A website that lets you know where to watch a movie built on Next.js and Meilisearch, deployed on Vercel with the Meilisearch + Vercel integration.
JavaScript
5
star
67

meilisearch-flutter

[wip] A basic UI kit with Meilisearch search widgets for Flutter
CMake
4
star
68

jayson

Rust
4
star
69

nelson

Rust
4
star
70

demo-finding-pypi

Alternative search bar for PyPI packages
Python
4
star
71

nextjs-starter-meilisearch-table

TypeScript
3
star
72

js-project-boilerplate

A boilerplate providing basic configuration for JavaScript projects in Meilisearch
3
star
73

synonyms

2
star
74

devops-tools

Shell
2
star
75

discord-bot-productboard

JavaScript
2
star
76

strois

A simple non-async S3 client based on the REST API
Rust
2
star
77

datasets

2
star
78

poc-vector-store-recall

A experimental tool that uses the vector store to increase Meilisearch's recall
Rust
2
star
79

.github

1
star
80

actions

Meilisearch Github Actions
JavaScript
1
star
81

devspector

Develop specification inspector
JavaScript
1
star
82

design-team

1
star
83

movies-react-demo

Created with CodeSandbox
HTML
1
star
84

ansible-vm-benchmarks

Ansible Playbook to index datasets on several typology of Instance on a specific Meilisearch version/commit
Rust
1
star
85

akamai-purge

A Rust helper to purge Akamai cache
Rust
1
star
86

poc-heed-codec

A repository to help us define the new design of heed
Rust
1
star
87

mainspector

Main specification inspector
JavaScript
1
star
88

settings_guessr

A tool that guess your settings by using the dataset
Rust
1
star
89

meilisearch-webhook-usage-example

Example of how to use the meilisearch webhook
Rust
1
star
90

meilikeeper

A sync zookeeper client on top of the official C client
Rust
1
star
91

massive-meilisearch-sampling

A program that generates and sends dataset and samples update/deletes to a Meilisearch server
Rust
1
star
92

zookeeper-client-sync

zookeeper-client-sync
Rust
1
star
93

maxicoffee-demo

A small demo for MaxiCoffee with instant-meilisearch
Vue
1
star