igdb search + capped http reads: native fulltext, full-page fetch
search_games used `where name ~ "<q>"*`: prefix-only, diacritic- and word-order-sensitive -- "MARVEL Tōkon" found nothing though IGDB has it. Switch to IGDB's native `search` clause (relevance-ranked, diacritic-insensitive). fetch_url and image downloads read bodies with content.read(n), which returns only the first buffered chunk (~7 KB): pages collapsed to their <title>. httpread.read_capped collects chunks up to the byte cap; image downloads read limit+1 so over-limit files are still rejected instead of cached truncated (IMG-10). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+12
-6
@@ -56,8 +56,12 @@ class IGDBQuery(object):
|
||||
return requests.post(igdb_url, headers=headers, data=query_body)
|
||||
|
||||
@staticmethod
|
||||
def build_query(fields, filters=None, limit=10, offset=None):
|
||||
query = f"fields {','.join(fields) if fields is not None and len(fields) > 0 else '*'}; limit {limit};"
|
||||
def build_query(fields, filters=None, limit=10, offset=None, search_term=None):
|
||||
query = ""
|
||||
if search_term:
|
||||
escaped = search_term.replace("\\", "\\\\").replace('"', '\\"')
|
||||
query += f'search "{escaped}"; '
|
||||
query += f"fields {','.join(fields) if fields is not None and len(fields) > 0 else '*'}; limit {limit};"
|
||||
if offset is not None:
|
||||
query += f" offset {offset};"
|
||||
if filters:
|
||||
@@ -65,12 +69,12 @@ class IGDBQuery(object):
|
||||
query += " where " + " & ".join(filter_statements) + ";"
|
||||
return query
|
||||
|
||||
def generalized_igdb_query(self, params, endpoint, fields, additional_filters=None, limit=10, offset=None):
|
||||
def generalized_igdb_query(self, params, endpoint, fields, additional_filters=None, limit=10, offset=None, search_term=None):
|
||||
all_filters = {key: f'~ "{value}"*' for key, value in params.items() if value}
|
||||
if additional_filters:
|
||||
all_filters.update(additional_filters)
|
||||
|
||||
query = self.build_query(fields, all_filters, limit, offset)
|
||||
query = self.build_query(fields, all_filters, limit, offset, search_term)
|
||||
data = self.send_igdb_request(endpoint, query)
|
||||
print(f"{endpoint}: {query} -> {data}")
|
||||
return data
|
||||
@@ -134,9 +138,10 @@ class IGDBQuery(object):
|
||||
return None
|
||||
|
||||
try:
|
||||
# Search for games with fuzzy matching
|
||||
# IGDB native full-text search: diacritic- and word-order-insensitive,
|
||||
# unlike a `name ~ "..."*` prefix filter
|
||||
games = self.generalized_igdb_query(
|
||||
{"name": query.strip()},
|
||||
{},
|
||||
"games",
|
||||
[
|
||||
"id",
|
||||
@@ -155,6 +160,7 @@ class IGDBQuery(object):
|
||||
],
|
||||
additional_filters={"game_type": "= 0"}, # Main games only (IGDB renamed category -> game_type)
|
||||
limit=limit,
|
||||
search_term=query.strip(),
|
||||
)
|
||||
|
||||
if not games:
|
||||
|
||||
Reference in New Issue
Block a user