From bafb13d202f9790dd125684c49b357d6b9931972 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Tue, 30 Jul 2024 18:28:08 -0400 Subject: [PATCH] feat(algolia): configure custom algolia ranking --- .../workflows/algolia/configure-algolia.py | 35 +++++++++++++++++++ .../{ => algolia}/upload-algolia-api.py | 0 .../workflows/{ => algolia}/upload-algolia.py | 0 .github/workflows/ibis-docs-main.yml | 12 +++++-- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/algolia/configure-algolia.py rename .github/workflows/{ => algolia}/upload-algolia-api.py (100%) rename .github/workflows/{ => algolia}/upload-algolia.py (100%) diff --git a/.github/workflows/algolia/configure-algolia.py b/.github/workflows/algolia/configure-algolia.py new file mode 100644 index 000000000000..ad1e13851d13 --- /dev/null +++ b/.github/workflows/algolia/configure-algolia.py @@ -0,0 +1,35 @@ +from __future__ import annotations # noqa: INP001 + +import os + +from algoliasearch.search_client import SearchClient + +api_key = os.environ["ALGOLIA_WRITE_API_KEY"] +app_id = os.environ["ALGOLIA_APP_ID"] +index_name = os.environ["ALGOLIA_INDEX"] + + +def main(): + client = SearchClient.create(app_id, api_key) + index = client.init_index(index_name) + + # Core is a custom attribute set to denote whether a record is part + # of the base expression API, we sort descending so those methods + # show up first in search instead of backend-specific methods + override_default_settings = { + "ranking": [ + "typo", + "words", + "desc(core)", + "filters", + "proximity", + "attribute", + "exact", + ] + } + + index.set_settings(override_default_settings) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/upload-algolia-api.py b/.github/workflows/algolia/upload-algolia-api.py similarity index 100% rename from .github/workflows/upload-algolia-api.py rename to .github/workflows/algolia/upload-algolia-api.py diff --git a/.github/workflows/upload-algolia.py b/.github/workflows/algolia/upload-algolia.py similarity index 100% rename from .github/workflows/upload-algolia.py rename to .github/workflows/algolia/upload-algolia.py diff --git a/.github/workflows/ibis-docs-main.yml b/.github/workflows/ibis-docs-main.yml index 06606cd18db8..8fbf3a723c8c 100644 --- a/.github/workflows/ibis-docs-main.yml +++ b/.github/workflows/ibis-docs-main.yml @@ -71,7 +71,7 @@ jobs: - name: Create and Upload Base Index run: | - python .github/workflows/upload-algolia.py + python .github/workflows/algolia/upload-algolia.py env: ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }} ALGOLIA_APP_ID: TNU9HG3L41 @@ -79,7 +79,15 @@ jobs: - name: Create and Upload API Records to index run: | - python .github/workflows/upload-algolia-api.py + python .github/workflows/algolia/upload-algolia-api.py + env: + ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }} + ALGOLIA_APP_ID: TNU9HG3L41 + ALGOLIA_INDEX: prod_ibis + + - name: Configure custom ranking on Algolia + run: | + python .github/workflows/algolia/configure-algolia-api.py env: ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }} ALGOLIA_APP_ID: TNU9HG3L41