All Projects → meilisearch → Meilisearch Js

meilisearch / Meilisearch Js

Licence: mit
Javascript client for the MeiliSearch API

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Meilisearch Js

Aliyun Cli
Alibaba Cloud CLI
Stars: ✭ 561 (+206.56%)
Mutual labels:  sdk, client
Openapi Core Ruby Sdk
Alibaba Cloud Core SDK for Ruby
Stars: ✭ 29 (-84.15%)
Mutual labels:  sdk, client
Milo
Eclipse Milo™ - an open source implementation of OPC UA (IEC 62541).
Stars: ✭ 587 (+220.77%)
Mutual labels:  sdk, client
Sdk
Library for using Grafana' structures in Go programs and client for Grafana REST API.
Stars: ✭ 193 (+5.46%)
Mutual labels:  sdk, client
Meilisearch Python
Python wrapper for the MeiliSearch API
Stars: ✭ 75 (-59.02%)
Mutual labels:  sdk, client
Aliyun Openapi Net Sdk
Alibaba Cloud SDK for .NET
Stars: ✭ 467 (+155.19%)
Mutual labels:  sdk, client
Gentleman
Full-featured, plugin-driven, extensible HTTP client toolkit for Go
Stars: ✭ 886 (+384.15%)
Mutual labels:  sdk, client
Openapi Sdk Php Client
Official repository of the Alibaba Cloud Client for PHP
Stars: ✭ 206 (+12.57%)
Mutual labels:  sdk, client
Aliyun Openapi Java Sdk
Alibaba Cloud SDK for Java
Stars: ✭ 1,170 (+539.34%)
Mutual labels:  sdk, client
Libra Grpc
A lightweight JavaScript library for Libra
Stars: ✭ 69 (-62.3%)
Mutual labels:  sdk, client
Graphql
Simple low-level GraphQL HTTP client for Go
Stars: ✭ 682 (+272.68%)
Mutual labels:  sdk, client
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-43.17%)
Mutual labels:  sdk, client
Vainglory
(*DEPRECATED*: The API no longer exists, so this will no longer work) A Javascript API Client wrapper for Vainglory
Stars: ✭ 32 (-82.51%)
Mutual labels:  sdk, client
Uploadcare Php
PHP API client that handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.
Stars: ✭ 77 (-57.92%)
Mutual labels:  sdk, client
Open62541
Open source implementation of OPC UA (OPC Unified Architecture) aka IEC 62541 licensed under Mozilla Public License v2.0
Stars: ✭ 1,643 (+797.81%)
Mutual labels:  sdk, client
Beefun Pro
Github client for iOS in Swift.
Stars: ✭ 172 (-6.01%)
Mutual labels:  client
Cognitive Face Windows
Windows SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 175 (-4.37%)
Mutual labels:  sdk
Dingtalkchatbotsdk
钉钉群机器人(.net跨平台)
Stars: ✭ 172 (-6.01%)
Mutual labels:  sdk
Gpu performance api
GPU Performance API for AMD GPUs
Stars: ✭ 170 (-7.1%)
Mutual labels:  sdk
Ios Consent Sdk
Configurable consent SDK for iOS
Stars: ✭ 178 (-2.73%)
Mutual labels:  sdk

MeiliSearch-JavaScript

MeiliSearch JavaScript

MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ

npm version Tests Prettier License Bors enabled

⚡ The MeiliSearch API client written for JavaScript

MeiliSearch JavaScript is the MeiliSearch API client for JavaScript developers.

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

Table of Contents

📖 Documentation

See our Documentation or our API References.

🔧 Installation

With npm:

npm install meilisearch

With yarn:

yarn add meilisearch

🏃‍♀️ Run MeiliSearch

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

For example, if you use Docker:

docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

NB: you can also download MeiliSearch from Homebrew or APT.

Import

Depending on the environment on which you are using MeiliSearch, imports may differ.

Import Syntax

Usage in a ES module environment:

import { MeiliSearch } from 'meilisearch'

const client = new MeiliSearch({
  host: 'http://127.0.0.1:7700',
  apiKey: 'masterKey',
})

Include Script Tag

Usage in an HTML (or alike) file:

<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/bundles/meilisearch.umd.js'></script>
<script>
  const client = new MeiliSearch({
    host: 'http://127.0.0.1:7700',
    apiKey: 'masterKey',
  })
</script>

Require Syntax

Usage in a back-end node environment

const { MeiliSearch } = require('meilisearch')

const client = new MeiliSearch({
  host: 'http://127.0.0.1:7700',
  apiKey: 'masterKey',
})

React Native

To make this package work with React Native, please add the react-native-url-polyfill.

🎬 Getting Started

Add Documents

const { MeiliSearch } = require('meilisearch')
// Or if you are in a ES environment
import { MeiliSearch } from 'meilisearch'

;(async () => {
  const client = new MeiliSearch({
    host: 'http://127.0.0.1:7700',
    apiKey: 'masterKey',
  })

  // An index is where the documents are stored.
  const index = client.index('movies')

  const documents = [
      { id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
      { id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
      { id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
      { id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
      { id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
      { id: 6, title: 'Philadelphia', genres: ['Drama'] },
  ]

  // If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
  let response = await index.addDocuments(documents)

  console.log(response) // => { "updateId": 0 }
})()

With the updateId, you can check the status (enqueued, processed or failed) of your documents addition using the update endpoint.

Basic Search

// MeiliSearch is typo-tolerant:
const search = await index.search('philoudelphia')
console.log(search)

Output:

{
  "hits": [
    {
      "id": "6",
      "title": "Philadelphia",
      "genres": ["Drama"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "processingTimeMs": 1,
  "query": "philoudelphia"
}

Custom Search

All the supported options are described in the search parameters section of the documentation.

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
    filters: 'id >= 1'
  }
)
{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action", "Adventure"],
      "_formatted": {
        "id": 2,
        "title": "<em>Wonder</em> Woman",
        "genres": ["Action", "Adventure"]
      }
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

Placeholder Search

Placeholder search makes it possible to receive hits based on your parameters without having any query (q). To enable faceted search on your dataset you need to add genres in the settings.

await index.search(
  '',
  {
    facetFilters: ['genres:fantasy'],
    facetsDistribution: ['genres']
  }
)
{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action","Adventure"]
    },
    {
      "id": 5,
      "title": "Moana",
      "genres": ["Fantasy","Action"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 2,
  "processingTimeMs": 0,
  "query": "",
  "facetsDistribution": {
    "genres": {
      "Drama": 0,
      "Action": 2,
      "Science Fiction": 0,
      "Fantasy": 1,
      "Romance": 0,
      "Adventure": 1
    }
  }

Abortable Search

You can abort a pending search request by providing an AbortSignal to the request.

const controller = new AbortController()

index
  .search('wonder', {}, 'POST', {
    signal: controller.signal,
  })
  .then((response) => {
    /** ... */
  })
  .catch((e) => {
    /** Catch AbortError here. */
  })

controller.abort()

🤖 Compatibility with MeiliSearch

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

💡 Learn More

The following sections may interest you:

This repository also contains more examples.

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

📜 API Resources

Search

  • Make a search request:

client.index<T>('xxx').search(query: string, options: SearchParams = {}, method: 'POST' | 'GET' = 'POST', config?: Partial<Request>): Promise<SearchResponse<T>>

Indexes

  • List all indexes:

client.listIndexes(): Promise<IndexResponse[]>

  • Create new index:

client.createIndex<T>(uid: string, options?: IndexOptions): Promise<Index<T>>

  • Create a local reference to an index:

client.index<T>(uid: string): Index<T>

  • Get an index:

client.getIndex<T>(uid: string): Index<T>

  • Get or create index if it does not exist

client.getOrCreateIndex<T>(uid: string, options?: IndexOptions): Promise<Index<T>>

  • Get Index information:

index.getRawInfo(): Promise<IndexResponse>

  • Update Index:

client.updateIndex(uid): Promise<Index> Or using the index object: index.update(data: IndexOptions): Promise<Index>

  • Delete Index:

client.deleteIndex(uid): Promise<void> Or using the index object: index.delete(): Promise<void>

  • Get specific index stats

index.getStats(): Promise<IndexStats>

  • Return Index instance with updated information:

index.fetchInfo(): Promise<Index>

  • Get Primary Key of an Index:

index.fetchPrimaryKey(): Promise<string | undefined>

Updates

  • Get One update info:

index.getUpdateStatus(updateId: number): Promise<Update>

  • Get all updates info:

index.getAllUpdateStatus(): Promise<Update[]>

  • Wait for pending update:

index.waitForPendingUpdate(updateId: number, { timeOutMs?: number, intervalMs?: number }): Promise<Update>

Documents

  • Add or replace multiple documents:

index.addDocuments(documents: Document<T>[]): Promise<EnqueuedUpdate>

  • Add or update multiple documents:

index.updateDocuments(documents: Document<T>[]): Promise<EnqueuedUpdate>

  • Get Documents:

index.getDocuments(params: getDocumentsParams): Promise<Document<T>[]>

  • Get one document:

index.getDocument(documentId: string): Promise<Document<T>>

  • Delete one document:

index.deleteDocument(documentId: string | number): Promise<EnqueuedUpdate>

  • Delete multiple documents:

index.deleteDocuments(documentsIds: string[] | number[]): Promise<EnqueuedUpdate>

  • Delete all documents:

index.deleteAllDocuments(): Promise<Types.EnqueuedUpdate>

Settings

  • Get settings:

index.getSettings(): Promise<Settings>

  • Update settings:

index.updateSettings(settings: Settings): Promise<EnqueuedUpdate>

  • Reset settings:

index.resetSettings(): Promise<EnqueuedUpdate>

Synonyms

  • Get synonyms:

index.getSynonyms(): Promise<object>

  • Update synonyms:

index.updateSynonyms(synonyms: object): Promise<EnqueuedUpdate>

  • Reset synonyms:

index.resetSynonyms(): Promise<EnqueuedUpdate>

Stop-words

  • Get Stop Words index.getStopWords(): Promise<string[]>

  • Update Stop Words index.updateStopWords(string[]): Promise<EnqueuedUpdate>

  • Reset Stop Words index.resetStopWords(): Promise<EnqueuedUpdate>

Ranking rules

  • Get Ranking Rules index.getRankingRules(): Promise<string[]>

  • Update Ranking Rules index.updateRankingRules(rankingRules: string[]): Promise<EnqueuedUpdate>

  • Reset Ranking Rules index.resetRankingRules(): Promise<EnqueuedUpdate>

Distinct Attribute

  • Get Distinct Attribute index.getDistinctAttribute(): Promise<string | void>

  • Update Distinct Attribute index.updateDistinctAttribute(distinctAttribute: string): Promise<EnqueuedUpdate>

  • Reset Distinct Attribute index.resetDistinctAttribute(): Promise<EnqueuedUpdate>

Searchable Attributes

  • Get Searchable Attributes index.getSearchableAttributes(): Promise<string[]>

  • Update Searchable Attributes index.updateSearchableAttributes(searchableAttributes: string[]): Promise<EnqueuedUpdate>

  • Reset Searchable Attributes index.resetSearchableAttributes(): Promise<EnqueuedUpdate>

Displayed Attributes

  • Get Displayed Attributes index.getDisplayedAttributes(): Promise<string[]>

  • Update Displayed Attributes index.updateDisplayedAttributes(displayedAttributes: string[]): Promise<EnqueuedUpdate>

  • Reset Displayed Attributes index.resetDisplayedAttributes(): Promise<EnqueuedUpdate>

Keys

  • Get keys

client.getKeys(): Promise<Keys>

Healthy

  • Check if the server is healthy

client.isHealthy(): Promise<true>

Stats

  • Get database stats

client.stats(): Promise<Stats>

Version

  • Get binary version

client.version(): Promise<Version>

Dumps

  • Trigger a dump creation process

client.createDump(): Promise<Types.EnqueuedDump>

  • Get the status of a dump creation process

client.getDumpStatus(dumpUid: string): Promise<Types.EnqueuedDump>


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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].