How to use the algoliasearch function in algoliasearch

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 / 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 / create-instantsearch-app / autocomplete.js / src / app.js View on Github external
import algoliasearch from 'algoliasearch';
import autocomplete from 'autocomplete.js';

const client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
const index = client.initIndex('instant_search');

autocomplete('#searchBox input[type=search]', { hint: false }, [
  {
    source: autocomplete.sources.hits(index, { hitsPerPage: 5 }),
    displayKey: 'name',
    templates: {
      suggestion(suggestion) {
        return suggestion._highlightResult.name.value;
      },
    },
  },
]).on('autocomplete:selected', (event, suggestion, dataset) => {
  console.log({ suggestion, dataset });
});
github pubpub / pubpub / client / containers / Search / Search.js View on Github external
setClient() {
		const allowedModes = ['pubs', 'pages'];
		if (allowedModes.indexOf(this.state.mode) > -1) {
			let key;
			if (this.state.mode === 'pubs') {
				key = this.props.searchData.pubsSearchKey;
			}
			if (this.state.mode === 'pages') {
				key = this.props.searchData.pagesSearchKey;
			}
			this.client = algoliasearch(this.props.searchData.searchId, key);
			this.index = this.client.initIndex(this.state.mode);
		}
	}
github quanglam2807 / webcatalog / src / renderer / store / actions / search.js View on Github external
export const search = () => (dispatch, getState) => {
  const query = getState().search.get('query');

  if (!query || query.length < 1) return;

  window.Intercom('trackEvent', 'search', { query });

  dispatch({
    type: SET_SEARCH_STATUS,
    status: LOADING,
  });

  const client = algoliasearch(
    process.env.ALGOLIASEARCH_APPLICATION_ID,
    process.env.ALGOLIASEARCH_API_KEY_SEARCH,
  );
  const index = client.initIndex('apps');
  index.search(query, { hitsPerPage: 48 })
    .then((content) => {
      dispatch(batchActions([
        {
          type: SET_SEARCH_STATUS,
          status: DONE,
        },
        {
          type: SET_SEARCH_HITS,
          hits: content.hits,
        },
      ]));
github quanglam2807 / webcatalog / src / ui / store / helpers / searchAsync.js View on Github external
new Promise((resolve, reject) => {
    const client = algoliasearch(ALGOLIA_APPLICATION_ID, ALGOLIA_APPLICATION_KEY);
    const index = client.initIndex('webcatalog');
    index.search(query, params, (err, content) => {
      if (err) {
        reject(err);
        return;
      }

      resolve(content);
    });
  });
github algolia / talksearch-scraper / src_old / routes.js View on Github external
import algoliasearch from 'algoliasearch';

import {
  getChannelID,
  getChannelAvatar,
  getPlaylistID,
  getVideo,
  recursiveGetVideosList,
} from './youtube';

import { indexVideos, indexMetadata } from './algolia';

const client = algoliasearch(process.env.APP_ID, process.env.API_KEY);

async function getYoutubeChannel(channelId, customIndexName) {
  const playlistId = await getPlaylistID(channelId);
  const videos = await recursiveGetVideosList(channelId, playlistId);
  return { videos, indexName: videos[0].channel };
}

async function getYoutubeVideo(videoId, customIndexName) {
  const video = await getVideo(videoId);
  return {
    videos: [video],
    indexName: `${video.channel}-video-${video.id}`,
  };
}

async function getYoutubePlaylist(playlistId, customIndexName) {
github listcommunity / support / src / algoliaSearch.js View on Github external
import AlgoliaSearch from "algoliasearch";
import debounce from "lodash.debounce";
import chunk from "lodash.chunk";
import difference from "lodash.difference";

const algolia = new AlgoliaSearch(
  process.env.REACT_APP_ALGOLIA_APP_ID,
  process.env.REACT_APP_ALGOLIA_API_KEY
);

const index = algolia.initIndex("repositories");
let data = {};

const searchStats = function(batchSize = 1000) {
  const ids = Object.keys(data);
  const batches = chunk(ids, batchSize);

  batches.forEach(batch => {
    const filters = batch.map(f => `objectID:${f}`).join(" OR ");

    index.search({ filters, hitsPerPage: batchSize }, (success, content) => {
      try {
github GetStream / Winds / api / src / utils / search / index.js View on Github external
import algolia from 'algoliasearch';
import config from '../../config';
import util from 'util';
import logger from '../../utils/logger';

if (config.algolia.appId && config.algolia.writeKey && config.algolia.index) {
	const client = algolia(config.algolia.appId, config.algolia.writeKey);
	const index = client.initIndex(config.algolia.index);

	module.exports = async (data) => {
		if (!data.type) {
			throw new Error('Missing data.type key and value.');
		}
		await util.promisify(index.addObject.bind(index))(data);
	};

	module.exports.indexMany = async (data) => {
		await util.promisify(index.addObjects.bind(index))(data);
	};
} else {
	module.exports = async () => {
		logger.info('Faking search indexing');
	};

algoliasearch

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

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis