Skip to content

Commit d9473cf

Browse files
authored
docs(algolia): add custom attributes to backend and core methods (#9730)
1 parent 47d97ea commit d9473cf

File tree

5 files changed

+90
-6
lines changed

5 files changed

+90
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations # noqa: INP001
2+
3+
import os
4+
5+
from algoliasearch.search_client import SearchClient
6+
7+
api_key = os.environ["ALGOLIA_WRITE_API_KEY"]
8+
app_id = os.environ["ALGOLIA_APP_ID"]
9+
index_name = os.environ["ALGOLIA_INDEX"]
10+
11+
12+
def main():
13+
client = SearchClient.create(app_id, api_key)
14+
index = client.init_index(index_name)
15+
16+
# Core is a custom attribute set to denote whether a record is part
17+
# of the base expression API, we sort descending so those methods
18+
# show up first in search instead of backend-specific methods
19+
override_default_settings = {
20+
"ranking": [
21+
"typo",
22+
"words",
23+
"desc(core)",
24+
"filters",
25+
"proximity",
26+
"attribute",
27+
"exact",
28+
]
29+
}
30+
31+
index.set_settings(override_default_settings)
32+
33+
34+
if __name__ == "__main__":
35+
main()

.github/workflows/upload-algolia-api.py renamed to .github/workflows/algolia/upload-algolia-api.py

+34-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,40 @@ def _create_api_record_from_method_line(base_url, method):
6262
"objectID": f"{base_url}{anchor}",
6363
"href": f"{base_url}{anchor}",
6464
"title": name,
65-
"text": desc,
66-
"crumbs": ["Expression API", "API", f"{section} expressions"],
65+
"backend": "core",
66+
"core": 1,
67+
"crumbs": ["Expression API", "API", f"{section} expression"],
6768
}
69+
if desc:
70+
record["text"] = desc
6871

6972
return record
7073

7174

75+
def adjust_backend_custom_attributes(backend_records):
76+
"""Adjusts attributes of the Algolia records.
77+
78+
Two custom attribute changes:
79+
One is the name of the backend, which we can possibly use for grouping
80+
or filtering results.
81+
82+
The other is a marker of whether the record is part of the core
83+
expression API, which we can use to sort results so that generic table
84+
expressions appear above backend-specific ones in the case of
85+
name-collisions.
86+
87+
We also strip out the "text" attribute if it's empty
88+
"""
89+
backend_name = backend_records[0]["title"].split(".", 1)[0]
90+
for record in backend_records:
91+
record["backend"] = backend_name
92+
record["core"] = 0
93+
if not record["text"]:
94+
record.pop("text")
95+
96+
return backend_records
97+
98+
7299
def main():
73100
client = SearchClient.create(app_id, api_key)
74101
index = client.init_index(index_name)
@@ -106,8 +133,12 @@ def main():
106133
# Here, we load those records and upload them to the Algolia index
107134
records = []
108135
for record_json in glob.glob("docs/backends/*.json"):
136+
print(f"Loading {record_json} methods...") # noqa:T201
109137
with open(record_json) as f:
110-
records.extend(json.load(f))
138+
backend_records = json.load(f)
139+
backend_records = adjust_backend_custom_attributes(backend_records)
140+
records.extend(backend_records)
141+
print(f"Uploading {len(records)} records to {index.name=}") # noqa:T201
111142
index.save_objects(records)
112143

113144

.github/workflows/ibis-docs-main.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,23 @@ jobs:
7171
7272
- name: Create and Upload Base Index
7373
run: |
74-
python .github/workflows/upload-algolia.py
74+
python .github/workflows/algolia/upload-algolia.py
7575
env:
7676
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
7777
ALGOLIA_APP_ID: TNU9HG3L41
7878
ALGOLIA_INDEX: prod_ibis
7979

8080
- name: Create and Upload API Records to index
8181
run: |
82-
python .github/workflows/upload-algolia-api.py
82+
python .github/workflows/algolia/upload-algolia-api.py
83+
env:
84+
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
85+
ALGOLIA_APP_ID: TNU9HG3L41
86+
ALGOLIA_INDEX: prod_ibis
87+
88+
- name: Configure custom ranking on Algolia
89+
run: |
90+
python .github/workflows/algolia/configure-algolia-api.py
8391
env:
8492
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
8593
ALGOLIA_APP_ID: TNU9HG3L41

docs/backends/_utils.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ def find_member_with_docstring(member):
3636
return member
3737

3838
cls = member.parent
39-
for base in cls.resolved_bases:
39+
resolved_bases = cls.resolved_bases
40+
# If we're a SQLBackend (likely) then also search through to `BaseBackend``
41+
if resolved_bases and (sqlbackend := resolved_bases[0]).name == "SQLBackend":
42+
for base in sqlbackend.resolved_bases:
43+
if base not in resolved_bases:
44+
resolved_bases.append(base)
45+
46+
# Remove `CanCreateSchema` and `CanListSchema` since they are deprecated
47+
# and we don't want to document their existence.
48+
filtered_bases = filter(lambda x: "schema" not in x.name.lower(), resolved_bases)
49+
for base in filtered_bases:
4050
try:
4151
parent_member = get_callable(base, member.name)
4252
except KeyError:

0 commit comments

Comments
 (0)