js-typesense-client
v1.1.2
Published
This npm package is a JavaScript client for communicating with the Typesense search engine. With this package you can create, update, delete and query data in your Typesense cluster.
Downloads
1
Maintainers
Readme
js-typesense-client
This npm package is a JavaScript client for communicating with the Typesense search engine. With this package you can create, update, delete and query data in your Typesense cluster.
Installation
npm install js-typesense-client
Prepare the typesense client
import { Client, Typesense } from 'js-typesense-client';
// set typesense collection, endpoint and key
const client = new Client('your_endpoint', 'your_collection', 'your_key');
// initialize Typesense and set the complete endpoint for the typesense search
const typesense = new Typesense();
typesense.setUrl(client.url());
// add optional query by fields that are not filters (like title, description, ...)
typesense.setQueryByFields(['title']);
Create filters
import { Filter, Filters } from 'js-typesense-client';
// create single filter type terms
const category = new Filter('category', 'terms', { facet: true, queryable: true });
category.setValue(['IMMOBILE RESIDENZIALE']);
// create single filter type range
const price = new Filter('price', 'range', { sortable: true });
// range
category.setValue([5000, 25000]);
// comparison operators
category.setValue([25000], '>=');
// import the filters
const filters = new Filters();
filters.import([category, price]);
Search
// the 2nd parameter (optional) override the default settings and adds the q
const response = await typesense.search(filters, { q: 'villa', page: 4, sort_by: 'price:asc' });