algolia/algolia-search-bundle

This package is abandoned and no longer maintained. The author suggests using the algolia/search-bundle package instead.

Installs: 224 652

Dependents: 3

Suggesters: 0

Stars: 159

Watchers: 58

Forks: 57

Open Issues: 14

Type:symfony-bundle


README

The readme/code you are seeing is part of the upcoming release 4.0

This readme/code introduces the upcoming Algolia SearchBundle v4, the next major release of our Algolia Symfony Integration. This release includes several new features along with the latest bug fixes and improvements:

  • Integration of the PHP Client v2
  • Waitable operations
  • Autocompletion, improved DX and many others

Development Status: 4.0.0-alpha2

Upgrade Guide: Upgrade Guide

You'd like to contribute? Before start, we want to let you know that your feedback is important to us! Please consider start using this v4 today! Found a bug or see something that can improved? Report it here: github.com/algolia/search-bundle/issues.

Algolia for Symfony

The perfect starting point to integrate Algolia within your Symfony project

Build Status Total Downloads Latest Version License

DocumentationPHPLaravelCommunity ForumStack OverflowReport a bugSupport

✨ Features

  • Compatible with Symfony 3.4 LTS and Symfony 4.0 (and later).
  • Simple: You can get started with only 5 lines of YAML
  • Standard: It leverages Normalizers to convert entities for indexing
  • Dev-friendly: It lets you disable HTTP calls easily (while running tests, for example)
  • Future-ready: It lets you unsubscribe from doctrine events easily to use a messaging/queue system.

💡 Getting Started

First, install Algolia Search Bundle Integration via the composer package manager:

composer require algolia/search-bundle

You will also need to provide the Algolia App ID and Admin API key. By default, they are loaded from environment variables ALGOLIA_APP_ID and ALGOLIA_API_KEY.

If you use .env config file, you can set them there.

ALGOLIA_APP_ID=XXXXXXXXXX
ALGOLIA_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

If you don't use environment variables, you can set them in your parameters.yml.

parameters:
    env(ALGOLIA_APP_ID): XXXXXXXXXX
    env(ALGOLIA_API_KEY): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Indexing data

First, we need to define which entities should be indexed in Algolia. Each entry under the indices config key must contain at least the 2 following attributes:

  • name is the canonical name of the index in Algolia
  • class is the full name of the entity to index

Example:

algolia_search:
  indices:
    - name: posts
      class: App\Entity\Post

Via CLI

Once your indices config is ready, you can use the built-in console command to batch import all existing data.

# Import all indices
php bin/console search:import

# Choose what indices to reindex by passing the index name
php bin/console search:import --indices=posts,comments

Before re-indexing everything, you may want to clear the index first, see how to remove data.

Simple Search

In this example we'll search for posts. The search method will query Algolia to get matching results and then will create a doctrine collection. The data are pulled from the database (that's why you need to pass the Doctrine Manager).

$em = $this->getDoctrine()->getManagerForClass(Post::class);

$posts = $this->searchService->search($em, Post::class, 'query');

For full documentation, visit the Algolia Symfony Search Bundle.

📄 License

Algolia Symfony Search Bundle is an open-sourced software licensed under the MIT license.