How to use algoliasearch - 10 common examples

To help you get started, we’ve selected a few algoliasearch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pubpub / pubpub / searchSync / searchSync.js View on Github external
/* eslint-disable no-console */
import Promise from 'bluebird';
import algoliasearch from 'algoliasearch';
import { Pub, Page } from '../server/models';
import { getPubSearchData, getPageSearchData } from '../workers/utils/searchUtils';

const client = algoliasearch(process.env.ALGOLIA_ID, process.env.ALGOLIA_KEY);
const pubsIndex = client.initIndex('pubs');
const pagesIndex = client.initIndex('pages');

console.log('Beginning search sync');

let records = 0;
const findAndIndexPubs = (pubIds) => {
	return getPubSearchData(pubIds).then((pubSyncData) => {
		records += pubSyncData.length;
		return pubsIndex.addObjects(pubSyncData);
	});
};

const findAndIndexPages = (pageIds) => {
	return getPageSearchData(pageIds).then((pageSyncData) => {
		records += pageSyncData.length;
github algolia / angular-instantsearch / src / create-ssr-algolia-client.ts View on Github external
import * as algoliasearchProxy from 'algoliasearch/index';
import * as encodeProxy from 'querystring-es3/encode';

import { VERSION } from './version';

// AOT + Rollup workaround
// https://github.com/rollup/rollup/issues/1267#issuecomment-296395734

const algoliasearch = algoliasearchProxy.default || algoliasearchProxy;
const encode = encodeProxy.default || encodeProxy;

export function createSSRAlgoliaClient({
  httpClient,
  HttpHeaders,
  transferState,
  makeStateKey,
}) {
  console.warn(
    '`createSSRAlgoliaClient` is deprecated in favor of `createSSRSearchClient` to be plugged to `searchClient`.'
  );

  return (_, appId, apiKey) =>
    createSSRSearchClient({
      appId,
      apiKey,
github algolia / docsearch / src / lib / DocSearch.js View on Github external
? autocompleteOptions.debug
        : false;
    // eslint-disable-next-line no-param-reassign
    autocompleteOptions.debug = debug || autocompleteOptionsDebug;
    this.autocompleteOptions = autocompleteOptions;
    this.autocompleteOptions.cssClasses =
      this.autocompleteOptions.cssClasses || {};
    this.autocompleteOptions.cssClasses.prefix =
      this.autocompleteOptions.cssClasses.prefix || 'ds';

    // eslint-disable-next-line no-param-reassign
    handleSelected = handleSelected || this.handleSelected;

    this.isSimpleLayout = layout === 'simple';

    this.client = algoliasearch(this.appId, this.apiKey);
    this.client.addAlgoliaAgent(`docsearch.js ${version}`);

    if (enhancedSearchInput) {
      this.input = DocSearch.injectSearchBox(this.input);
    }

    this.autocomplete = autocomplete(this.input, autocompleteOptions, [
      {
        source: this.getAutocompleteSource(transformData, queryHook),
        templates: {
          suggestion: DocSearch.getSuggestionTemplate(this.isSimpleLayout),
          footer: templates.footer,
          empty: DocSearch.getEmptyTemplate(),
        },
      },
    ]);
github bayesimpact / bob-emploi / frontend / client / src / components / suggestions.tsx View on Github external
function fetchJob(jobName: string, jobId: string): Promise {
  const algoliaClient = algoliasearch(JobSuggest.algoliaApp, JobSuggest.algoliaApiKey)
  const jobIndex = algoliaClient.initIndex(JobSuggest.algoliaIndex)
  // First fetch by name.
  return jobIndex.search(jobName).
    // Check the code OGR is right (if given)
    then(getFirstHitWithCodeOgr(jobId)).
    // If nothing found, fetch by code OGR.
    then((hit): Promise => hit ? Promise.resolve(hit) :
      jobIndex.search(jobId).then(getFirstHitWithCodeOgr(jobId))).
    then(jobFromSuggestion)
}
github birkir / react-native-appstore / src / store / index.js View on Github external
if (__DEV__) {
  // This becomes handy to debug network requests in Chrome DevTools
  XMLHttpRequest = GLOBAL.originalXMLHttpRequest
    ? GLOBAL.originalXMLHttpRequest
    : GLOBAL.XMLHttpRequest;
}
/* eslint-enable */

// Create new Apollo client
const client = new ApolloClient({
  link: new HttpLink({ uri: config.API_URL }),
  cache: new InMemoryCache(),
});

// Algolia client
const algolia = algoliasearch(config.ALGOLIA_APP_ID, config.ALGOLIA_API_KEY);

export default class Store {

  ui = new UI();

  algolia = {
    client: algolia,
    apps: algolia.initIndex('apps'),
  };

  async setup() {
    return true;
  }
}

/**
github bayesimpact / bob-emploi / frontend / client / src / components / suggestions.tsx View on Github external
public componentDidMount(): void {
    const {
      algoliaApp,
      algoliaApiKey,
      algoliaIndex,
      display,
      displayValue,
      hitsPerPage,
      onChange,
      onSuggestSelect,
      suggestionTemplate,
      ...extraProps
    } = this.props
    const algoliaClient = algoliasearch(algoliaApp, algoliaApiKey)
    const displayFunc = display ||
      ((suggestion): React.ReactNode => this.props.displayKey && suggestion[this.props.displayKey])
    const handleSelected = (event, suggestion): void => {
      const displaySuggestion = displayFunc(suggestion)
      onSuggestSelect && onSuggestSelect(event, displaySuggestion, suggestion)
      onChange && onChange(event, displaySuggestion, suggestion)
    }
    // TODO(pascal): Rething this pattern as this is not compatible with React.
    // Modifying the DOM without React is somewhat OK, but here it changes the
    // main DOM element of this component which confuses React when trying to
    // update the components before it.
    const suggest = autocomplete(this.node.current, extraProps, [
      {
        display: displayFunc,
        source: autocomplete.sources.hits(
          algoliaClient.initIndex(algoliaIndex), {hitsPerPage: hitsPerPage}),
github bayesimpact / bob-emploi / frontend / client / src / components / suggestions.tsx View on Github external
function fetchFirstSuggestedJob(jobName: string): Promise {
  const algoliaClient = algoliasearch(JobSuggest.algoliaApp, JobSuggest.algoliaApiKey)
  const jobIndex = algoliaClient.initIndex(JobSuggest.algoliaIndex)
  return jobIndex.search(jobName).then((results): bayes.bob.Job|null => {
    const firstJobSuggestion = results.hits && results.hits[0]
    if (!firstJobSuggestion) {
      return null
    }
    const firstSuggestedJob = jobFromSuggestion(firstJobSuggestion)
    // TODO(florian): Check that the job has the expected RomeId.
    return firstSuggestedJob
  })
}
github algolia / angular-instantsearch / src / instantsearch / instantsearch.ts View on Github external
OnDestroy,
  Output,
  EventEmitter,
  Inject,
  PLATFORM_ID,
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

import * as algoliasearchProxy from 'algoliasearch/lite';
import instantsearch from 'instantsearch.js/es';
import { AlgoliaSearchHelper } from 'algoliasearch-helper';

import { Widget } from '../base-widget';
import { VERSION } from '../version';

const algoliasearch = algoliasearchProxy.default || algoliasearchProxy;

export type SearchRequest = {
  indexName: string;
  params: SearchRequestParameters;
};

export type SearchForFacetValuesRequest = {
  indexName: string;
  params: SearchForFacetValuesRequestParameters;
};

// Documentation: https://www.algolia.com/doc/api-reference/search-api-parameters/
export type SearchParameters = {
  // Attributes
  attributesToRetrieve?: string[];
  restrictSearchableAttributes?: string[];
github algolia / vue-instantsearch / src / __tests__ / store.js View on Github external
test('can create a Store instance from an algolia client', () => {
  const client = algoliaClient('appId', 'apiKey');
  const store = createFromAlgoliaClient(client);
  expect(store).toBeInstanceOf(Store);
  expect(store.algoliaClient).toBe(client);
});
github algolia / angular-instantsearch / src / __tests__ / create-ssr-search-client.spec.ts View on Github external
it('passes user agents', () => {
    const addAlgoliaAgent = jest.fn();

    algoliasearch.mockImplementation(() => {
      return {
        addAlgoliaAgent,
      };
    });

    const ssrSearchClient = createSSRSearchClient({
      appId: 'test',
      apiKey: 'test',
      httpClient: null,
      HttpHeaders: null,
      makeStateKey: null,
      transferState: null,
    });

    expect(addAlgoliaAgent).toHaveBeenCalledTimes(3);
    expect(addAlgoliaAgent).toHaveBeenCalledWith(

algoliasearch

A fully-featured and blazing-fast JavaScript API client to interact with Algolia API.

MIT
Latest version published 4 days ago

Package Health Score

85 / 100
Full package analysis