2018/7/16
Tag : Algolia

Algoliaで検索結果をタグで絞り込む

Algolia試してみる | mersy note
https://note.mersy418.com/article/try-algolia

前回の続き。

データの持ち方

これの Categories のようにタグは配列で入れる必要がありそう

{
    "name": "3-Year Unlimited Cloud Storage Service Activation Card - Other",
    "description": "Enjoy 3 years of unlimited Cloud storage service with [...]",
    "brand": "Pogoplug",
    "categories": [
      "Best Buy Gift Cards",
      "Entertainment Gift Cards"
    ],
    "hierarchicalCategories": {
      "lvl0": "Best Buy Gift Cards",
      "lvl1": "Best Buy Gift Cards > Entertainment Gift Cards"
    },

設定はこの辺の話っぽい。

InstantSearch.js | refinementList
https://community.algolia.com/instantsearch.js/v2/widgets/refinementList.html

管理画面側での設定

管理画面側で Display Settings の Faceting の設定が必要だった。

なるほどなー。

https://note.mersy418.com/search.html

js側で表示数の制御とか。

search.addWidget(
  instantsearch.widgets.refinementList({
    container: '#tags',
    attributeName: 'tags',
    operator: 'and',
    limit: 30,
    templates: {
      header: 'tags'
    }
  })
);

関係ありそうなドキュメントとか。

Faceting | Searching Guide | Algolia Documentation
https://www.algolia.com/doc/guides/searching/faceting/#declaring-attributes-for-faceting
attributesForFaceting parameter | Parameter | API Reference | Algolia Documentation
https://www.algolia.com/doc/api-reference/api-parameters/attributesForFaceting/
Default filters with InstantSearch.js | Tutorials | Algolia Documentation
https://www.algolia.com/doc/tutorials/search-ui/instant-search/filtering/add-default-filters/instantsearchjs/