Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

Algolia logo Algolia

Query your Algolia data using Twig

About

Algolia for Craft CMS allows you to easily pull search results from Algolia into your Twig templates or through REST API endpoints.

Template Usage

Browse an index

Additional search parameters can be provided in the params object.

{% for result in craft.algolia.browse({
    index: "indexName",
    query: "optional query",
    params: {
      distinct: true,
      getRankingInfo: true
    }
  })
%}

{% endfor %}

Search an index

Additional search parameters can be provided in the params object.

{% set search = craft.algolia.search({
    index: "indexName",
    query: "optional query",
    params: {
      hitsPerPage: 5,
      page: 7
    }
  })
%}

{% for hit in search.hits %}

{% endfor %}

Perform a multiple query search

Additional search parameters can be provided in each queries object.

{% set search = craft.algolia.multipleQueries([
    {
      indexName: "indexName1",
      query: "optional query"
    },
    {
      indexName: "indexName2",
      query: "optional query"
    }
  ])
%}

{% for group in search.results %}
  {% for hit in group.hits %}

  {% endfor %}
{% endfor %}

Using JSON REST API controllers

In additional to Twig variables you can make a POST request to one of the following controller endpoints. The same index, query and optional attributes are available when you make your POST request.

NOTE: The following examples use Axios for making API requests

Browse an index

Additional search parameters can be provided in the params object.

axios.post("/actions/algolia/default/browse", {
  index: "indexName",
  query: "optional query",
  params: {
    distinct: true,
    getRankingInfo: true
  }
}, {
  headers: {
    "X-CSRF-Token": YOUR_CRAFT_CSRF_TOKEN
  }
});

Search an index

Additional search parameters can be provided in the params object.

axios.post("/actions/algolia/default/search", {
  index: "indexName",
  query: "optional query",
  params: {
    hitsPerPage: 5,
    page: 7
  }
}, {
  headers: {
    "X-CSRF-Token": YOUR_CRAFT_CSRF_TOKEN
  }
});

Perform a multiple query search

Additional search parameters can be provided in each queries object.

axios.post("/actions/algolia/default/multiple-queries", {
  queries: [
    {
      indexName: "indexName1",
      query: "optional query"
    },
    {
      indexName: "indexName2",
      query: "optional query"
    }
  ]
}, {
  headers: {
    "X-CSRF-Token": YOUR_CRAFT_CSRF_TOKEN
  }
});

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation

Install Algolia from the Craft CMS Plugin Store!

Attribution

This plugin is powered by the Algolia PHP API client. The client and icon/logo belong to Algolia.

About

πŸ” Interface with Algolia through Craft CMS

Resources

License

Packages

No packages published