What is algoliasearch?
The algoliasearch npm package is a JavaScript client for Algolia, a hosted search API that provides a fast and accurate search experience for websites and mobile applications. The package allows developers to integrate Algolia's search capabilities into their JavaScript applications, enabling features such as full-text search, faceting, filtering, and geolocation queries.
What are algoliasearch's main functionalities?
Search
Perform a search query on an Algolia index and retrieve the results.
const algoliasearch = require('algoliasearch');
const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
const index = client.initIndex('your_index_name');
index.search('query string').then(({ hits }) => {
console.log(hits);
});
Indexing
Add or update a record in an Algolia index.
const algoliasearch = require('algoliasearch');
const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
const index = client.initIndex('your_index_name');
index.saveObject({ objectID: '1', name: 'Foo' }).then(() => {
console.log('Object indexed');
});
Configure Index Settings
Configure settings of an Algolia index to define ranking, attributes for faceting, etc.
const algoliasearch = require('algoliasearch');
const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
const index = client.initIndex('your_index_name');
index.setSettings({
searchableAttributes: ['name', 'description'],
customRanking: ['desc(popularity)']
}).then(() => {
console.log('Settings updated');
});
Manage Indices
List all indices in your Algolia application and manage them.
const algoliasearch = require('algoliasearch');
const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
client.listIndices().then(({ items }) => {
console.log(items);
});
Other packages similar to algoliasearch
elasticsearch
Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. The elasticsearch npm package is the official Elasticsearch client for Node.js. It provides similar search capabilities but is typically self-hosted, unlike Algolia which is a managed service.
solr-node
Solr-node is a client library for interacting with Apache Solr, which is an open-source search platform. Similar to Algolia, it provides full-text search, but it requires self-hosting and manual scaling, whereas Algolia offers a fully managed service.
typesense
Typesense is an open-source, typo-tolerant search engine that provides a similar developer experience to Algolia. The typesense npm package allows you to integrate Typesense into your JavaScript applications. It is designed to be easy to use and deploy, offering an alternative to Algolia with a focus on simplicity and speed.