Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
meilisearch
Advanced tools
ā” 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!
See our Documentation or our API References.
With npm
:
npm install meilisearch
With yarn
:
yarn add 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 MeiliSearch from 'meilisearch'
const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
<script src="https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.umd.js"></script>
<script>
const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
client.listIndexes().then(res => {
console.log({ res });
})
</script>
const MeiliSearch = require('meilisearch')
const client = new MeiliSearch({
host: 'http://127.0.0.1:7700',
apiKey: 'masterKey',
})
To make this package work with React Native, please add the react-native-url-polyfill.
const MeiliSearch = require('meilisearch')
// Or if you are on a front-end 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('books') // If your index exists
const documents = [
{ book_id: 123, title: 'Pride and Prejudice' },
{ book_id: 456, title: 'Le Petit Prince' },
{ book_id: 1, title: 'Alice In Wonderland' },
{ book_id: 1344, title: 'The Hobbit' },
{ book_id: 4, title: 'Harry Potter and the Half-Blood Prince', genre: 'fantasy' },
{ book_id: 42, title: "The Hitchhiker's Guide to the Galaxy", genre: 'fantasy' }
]
// 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.
// MeiliSearch is typo-tolerant:
const search = await index.search('harry pottre')
console.log(search)
Output:
{
"hits": [
{
"book_id": 4,
"title": "Harry Potter and the Half-Blood Prince"
}
],
"offset": 0,
"limit": 20,
"nbHits": 1,
"exhaustiveNbHits": false,
"processingTimeMs": 1,
"query": "harry pottre"
}
All the supported options are described in the search parameters section of the documentation.
await index.search(
'prince',
{
attributesToHighlight: ['*'],
filters: 'book_id > 10'
}
)
{
"hits": [
{
"book_id": 456,
"title": "Le Petit Prince",
"_formatted": {
"book_id": 456,
"title": "Le Petit <em>Prince</em>"
}
}
],
"offset": 0,
"limit": 20,
"nbHits": 1,
"exhaustiveNbHits": false,
"processingTimeMs": 0,
"query": "prince"
}
Placeholder search makes it possible to receive hits based on your parameters without having any query (q
).
await index.search(
'',
{
facetFilters: ['genre:fantasy'],
facetsDistribution: ['genre']
}
)
{
"hits": [
{
"id": 4,
"title": "Harry Potter and the Half-Blood Prince",
"genre": "fantasy"
},
{
"id": 42,
"title": "The Hitchhiker's Guide to the Galaxy",
"genre": "fantasy"
}
],
"offset": 0,
"limit": 20,
"nbHits": 2,
"exhaustiveNbHits": false,
"processingTimeMs": 0,
"query": "",
"facetsDistribution": { "genre": { "fantasy": 2 } },
"exhaustiveFacetsCount": true
}
You can abort a pending search request by providing an AbortSignal to the request.
const controller = new AbortController()
index
.search('prince', {}, 'POST', {
signal: controller.signal,
})
.then((response) => {
/** ... */
})
.catch((e) => {
/** Catch AbortError here. */
})
controller.abort()
This package only guarantees the compatibility with the version v0.18.1 of MeiliSearch.
The following sections may interest you:
This repository also contains more examples.
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!
client.getIndex<T>('xxx').search(query: string, options: SearchParams = {}, method: 'POST' | 'GET' = 'POST', config?: Partial<Request>): Promise<SearchResponse<T>>
client.listIndexes(): Promise<IndexResponse[]>
client.createIndex<T>(uid: string, options?: IndexOptions): Promise<Index<T>>
client.index<T>(uid: string): Index<T>
client.getIndex<T>(uid: string): Index<T>
client.getOrCreateIndex<T>(uid: string, options?: IndexOptions): Promise<Index<T>>
index.getRawInfo(): Promise<IndexResponse>
client.updateIndex(uid): Promise<Index>
Or using the index object:
index.update(data: IndexOptions): Promise<Index>
client.deleteIndex(uid): Promise<void>
Or using the index object:
index.delete(): Promise<void>
index.getStats(): Promise<IndexStats>
index.fetchInfo(): Promise<Index>
index.fetchPrimaryKey(): Promise<string | undefined>
index.getUpdateStatus(updateId: number): Promise<Update>
index.getAllUpdateStatus(): Promise<Update[]>
index.waitForPendingUpdate(updateId: number, { timeOutMs?: number, intervalMs?: number }): Promise<Update>
index.addDocuments(documents: Document<T>[]): Promise<EnqueuedUpdate>
index.updateDocuments(documents: Document<T>[]): Promise<EnqueuedUpdate>
index.getDocuments(params: getDocumentsParams): Promise<Document<T>[]>
index.getDocument(documentId: string): Promise<Document<T>>
index.deleteDocument(documentId: string | number): Promise<EnqueuedUpdate>
index.deleteDocuments(documentsIds: string[] | number[]): Promise<EnqueuedUpdate>
index.deleteAllDocuments(): Promise<Types.EnqueuedUpdate>
index.getSettings(): Promise<Settings>
index.updateSettings(settings: Settings): Promise<EnqueuedUpdate>
index.resetSettings(): Promise<EnqueuedUpdate>
index.getSynonyms(): Promise<object>
index.updateSynonyms(synonyms: object): Promise<EnqueuedUpdate>
index.resetSynonyms(): Promise<EnqueuedUpdate>
Get Stop Words
index.getStopWords(): Promise<string[]>
Update Stop Words
index.updateStopWords(string[]): Promise<EnqueuedUpdate>
Reset Stop Words
index.resetStopWords(): Promise<EnqueuedUpdate>
Get Ranking Rules
index.getRankingRules(): Promise<string[]>
Update Ranking Rules
index.updateRankingRules(rankingRules: string[]): Promise<EnqueuedUpdate>
Reset Ranking Rules
index.resetRankingRules(): Promise<EnqueuedUpdate>
Get Distinct Attribute
index.getDistinctAttribute(): Promise<string | void>
Update Distinct Attribute
index.updateDistinctAttribute(distinctAttribute: string): Promise<EnqueuedUpdate>
Reset Distinct Attribute
index.resetDistinctAttribute(): Promise<EnqueuedUpdate>
Get Searchable Attributes
index.getSearchableAttributes(): Promise<string[]>
Update Searchable Attributes
index.updateSearchableAttributes(searchableAttributes: string[]): Promise<EnqueuedUpdate>
Reset Searchable Attributes
index.resetSearchableAttributes(): Promise<EnqueuedUpdate>
Get Displayed Attributes
index.getDisplayedAttributes(): Promise<string[]>
Update Displayed Attributes
index.updateDisplayedAttributes(displayedAttributes: string[]): Promise<EnqueuedUpdate>
Reset Displayed Attributes
index.resetDisplayedAttributes(): Promise<EnqueuedUpdate>
client.getKeys(): Promise<Keys>
client.isHealthy(): Promise<true>
client.stats(): Promise<Stats>
client.version(): Promise<Version>
client.createDump(): Promise<Types.EnqueuedDump>
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.
FAQs
The Meilisearch JS client for Node.js and the browser.
The npm package meilisearch receives a total of 44,636 weekly downloads. As such, meilisearch popularity was classified as popular.
We found that meilisearch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.