forked from PrivateCoffee/wikimore
fix(search): properly escape and format search queries
Refined the search URL construction to correctly escape and format the search queries by replacing spaces with underscores and escaping characters. This ensures more accurate search results and improved reliability of the search functionality. Fixes #6.
This commit is contained in:
parent
301cf90778
commit
6cc25796a2
1 changed files with 5 additions and 1 deletions
|
@ -205,7 +205,11 @@ def search_results(project, lang, query):
|
|||
|
||||
logger.debug(f"Searching {base_url} for {query}")
|
||||
|
||||
url = f"{base_url}/w/api.php?action=query&format=json&list=search&srsearch={query}"
|
||||
srquery = escape(query.replace(" ", "_"), True)
|
||||
|
||||
url = (
|
||||
f"{base_url}/w/api.php?action=query&format=json&list=search&srsearch={srquery}"
|
||||
)
|
||||
with urllib.request.urlopen(url) as response:
|
||||
data = json.loads(response.read().decode())
|
||||
search_results = data["query"]["search"]
|
||||
|
|
Loading…
Reference in a new issue