Skip to content

Limit Algolia Search to Certain Projects or Doc Types #24

@ceolson01

Description

@ceolson01

Issue at Hand

To accommodate for multiple searches (i.e. one for docs, one for tutorials), we'll need a way to filter a search query's results to only include one particular source.

Proposed Solution

  1. Update Algolia docsearch Config File
  2. Filter by Tags in Search Component

1. Update Algolia docsearch Config File

Our current config file currently includes an entry point for each project's doc section, each with a tags property:

{
  "start_urls": [
    {
      "url": "https://docs.colony.io/colonynetwork/docs-colony/",
      "tags": [
        "colonynetwork"
      ]
    },
    {
      "url": "https://docs.colony.io/colonynetwork/",
      "tags": [
        "colonynetwork"
      ]
    },
    ...
  ],
  ...
}

With tutorials added, it may be good to add a docs tag to each relevant docs url, and a tuts or tutorials tag to each relevant project's tutorials url:

{
  "start_urls": [
    {
      "url": "https://docs.colony.io/colonynetwork/docs-colony/",
      "tags": [
        "colonynetwork",
        "docs"
      ]
    },
    {
      "url": "https://docs.colony.io/colonynetwork/tutorial-first-steps/",
      "tags": [
        "colonynetwork",
        "tutorials"
      ]
    },
    {
      "url": "https://docs.colony.io/colonynetwork/",
      "tags": [
        "colonynetwork",
      ]
    },
    ...
  ],
  ...
}

2. Filter by Tags in Search Component

Algolia's docsearch accepts an algoliaOptions object which you can learn more about here. It accepts these API parameters.

Ideally, the filters should be Search component props, but in it's simplest form, this could look something like:

// Search tutorials only
docsearch({
  algoliaOptions: {
    filters: 'tags:tutorials',
  },
  ...
});

// Search only colonyNetwork docs
docsearch({
  algoliaOptions: {
    filters: 'tags:colonynetwork AND tags:docs',
  },
  ...
});

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions