Skip to content

Commit 1e2f09a

Browse files
author
Gerit Wagner
committed
add query database (docs etc.)
1 parent 4489d88 commit 1e2f09a

22 files changed

+11473
-7
lines changed

docs/generate_indices.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# scripts/generate_errors_index.py
2+
import json
3+
import re
4+
from importlib.resources import files
25
from pathlib import Path
36

47
from search_query.constants import QueryErrorCode
@@ -75,3 +78,94 @@ def generate_rst_file(error: QueryErrorCode) -> None:
7578
# f.write(f"- {platform.value}\n")
7679
# # f.write(f" parser/{platform}.rst\n")
7780
# f.write("\n")
81+
82+
83+
query_dir = files("search_query") / "json_db"
84+
output_dir = Path("docs/source/query_database")
85+
rst_dir = output_dir / "queries"
86+
rst_dir.mkdir(parents=True, exist_ok=True)
87+
88+
overview = []
89+
90+
91+
def slugify(name: str) -> str:
92+
return re.sub(r"[^\w\-]+", "-", name.lower()).strip("-")
93+
94+
95+
for file in query_dir.iterdir():
96+
if file.suffix == ".json":
97+
with open(file, encoding="utf-8") as f:
98+
content = json.load(f)
99+
100+
identifier = file.stem
101+
platform = content.get("platform", "")
102+
search_string = content.get("search_string", "")
103+
title = content.get("title", identifier)
104+
description = content.get("description", "")
105+
keywords = content.get("keywords", "")
106+
filename = file.name
107+
authors = " and ".join(x["name"] for x in content.get("authors", []))
108+
license = content.get("license", "")
109+
110+
slug = slugify(identifier)
111+
rst_filename = rst_dir / f"{slug}.rst"
112+
113+
# Write individual .rst file
114+
with open(rst_filename, "w", encoding="utf-8") as rst:
115+
rst.write(
116+
f"""{title}
117+
{'=' * len(title)}
118+
119+
**Identifier**: ``{identifier}``
120+
121+
**Platform**: ``{platform}``
122+
123+
**Keywords**: ``{keywords}``
124+
125+
**Authors**: ``{authors}``
126+
127+
**License**: ``{license}``
128+
129+
**License**: {description}
130+
131+
Load
132+
-----------
133+
134+
.. code-block:: python
135+
136+
from search_query.database import load_query
137+
138+
query = load_query("{filename}")
139+
140+
print(query.to_string())
141+
# {search_string[:80] + "..."}
142+
143+
144+
Search String
145+
-------------
146+
147+
.. raw:: html
148+
149+
<pre style="white-space: pre-wrap; word-break: break-word;">
150+
{search_string}
151+
</pre>
152+
153+
154+
Suggest to `improve this query <https://github.com/CoLRev-Environment/search-query/blob/main/search_query/json_db/{filename}>`_.
155+
"""
156+
)
157+
158+
overview.append(
159+
{
160+
"identifier": f"`{identifier} <queries/{slug}.html>`_",
161+
"platform": platform,
162+
"search_string_snippet": search_string[:80] + "...",
163+
"title": title,
164+
"description": description,
165+
"keywords": keywords,
166+
}
167+
)
168+
169+
# Write overview.json
170+
with open(output_dir / "query_overview.json", "w", encoding="utf-8") as f:
171+
json.dump(overview, f, indent=2)

docs/source/_static/css/custom.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
td {
66
white-space: normal !important;
77
}
8+
9+
10+
pre {
11+
white-space: pre-wrap !important; /* Wrap long lines */
12+
word-wrap: break-word !important; /* Break long words if needed */
13+
}

docs/source/_static/css/jquery.dataTables.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)