AddSearch JavaScript Client

1.2.3 · active · verified Tue Apr 21

The `addsearch-js-client` package provides a JavaScript client library for interacting with the AddSearch Search API and Indexing API. It allows developers to easily integrate search functionalities like keyword search, search suggestions, and custom field autocompletion into their web applications or Node.js environments. The current stable version is 1.2.3. The package appears to have a regular release cadence, with multiple minor and patch updates released within recent months, often addressing dependency updates, security vulnerabilities, and new features like AI answers streaming. Key differentiators include its focus on a comprehensive search-as-a-service platform, offering features like fuzzy matching, configurable search operators, and specific indexing capabilities alongside standard search. It supports both browser and Node.js environments and ships with TypeScript types, ensuring type safety for TypeScript projects. The library aims to simplify the integration of complex search features into various JavaScript applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the AddSearch client, performs a basic keyword search, and demonstrates fetching search suggestions and custom field autocompletion results. It includes a placeholder for your AddSearch Sitekey and uses environment variables for secure key handling.

import AddSearchClient from 'addsearch-js-client';

// Replace 'YOUR_PUBLIC_SITEKEY' with your actual 32-character AddSearch Sitekey
const SITEKEY = process.env.ADDSEARCH_SITEKEY ?? 'YOUR PUBLIC SITEKEY';

if (SITEKEY === 'YOUR PUBLIC SITEKEY') {
  console.warn('WARNING: Replace YOUR_PUBLIC_SITEKEY with your actual AddSearch Sitekey to make this example work.');
}

// Create client with your SITEKEY
const client = new AddSearchClient(SITEKEY);

// Define a callback function to handle search results
const handleSearchResults = (res) => {
  console.log('Search Results:', res);
  if (res.hits && res.hits.length > 0) {
    console.log(`Found ${res.hits.length} results. First result title:`, res.hits[0].title);
  } else {
    console.log('No results found for the keyword.');
  }
};

// Execute a search query for 'keyword'
client.search('keyword', handleSearchResults);

// Optionally, fetch search suggestions
const handleSuggestions = (res) => {
  console.log('Search Suggestions:', res);
};
client.suggestions('auto', handleSuggestions);

// Optionally, fetch custom field autocompletion results
const handleAutocomplete = (res) => {
  console.log('Autocomplete Results:', res);
};
client.autocomplete('custom_fields.category', 'pro', handleAutocomplete);

view raw JSON →