Skip to content

Generalize site search for all registered sources and normalize result URLs - #262

Open
kmatsunami wants to merge 1 commit into
mainfrom
codex/add-search-functionality-for-all-media-bkegmq
Open

Generalize site search for all registered sources and normalize result URLs#262
kmatsunami wants to merge 1 commit into
mainfrom
codex/add-search-functionality-for-all-media-bkegmq

Conversation

@kmatsunami

Copy link
Copy Markdown
Collaborator

Motivation

  • Expand the search capability to cover all registered sources instead of the previous two hard-coded sources.
  • Unify duplicate per-site search logic into a single generic extractor to simplify maintenance and add per-source configuration.
  • Ensure discovered result URLs are resolved, domain-checked, and canonicalized to existing seed URL normalization logic.

Description

  • Replaced hard-coded SUPPORTED_SEARCH_SOURCES with REGISTERED_SOURCES and imported normalize_seed_url from manga_watch.sources and switched quote to quote_plus for query encoding.
  • Added _SOURCE_SEARCH_CONFIG to declare each source's search_url and allowed_domains and implemented _search_via_public_site to drive searches for any configured source.
  • Reworked anchor parsing into _extract_anchor_results and added helpers _resolve_result_url, _is_allowed_domain, and _canonical_seed_url_for_source to resolve relative links, enforce allowed domains, and produce canonical seed URLs via normalize_seed_url.
  • Removed source-specific search functions and _normalize_result_url, and built _SEARCHERS dynamically so each registered source uses the generic search path.

Testing

  • Ran updated unit tests in tests/test_source_search.py which assert supported sources and seed URL normalization and they passed.
  • Ran tests/test_discord_command_registration_search.py which validates the expanded search choices and it passed.
  • Ran tests/test_discord_supertwins.py which checks search invocation behavior and it passed.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f228197b4d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 165 to +168
title_attr_match = re.search(r'title="([^"]+)"', match.group(0), re.I | re.S)
title = _normalize_anchor_text(title_attr_match.group(1) if title_attr_match else match.group(2))
if not title:
continue
seed_url = _normalize_result_url(urljoin(base_url, href))
if seed_url in seen_urls:
continue
seen_urls.add(seed_url)
title = canonical_seed_url

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve img alt text when anchor lacks visible title

In _extract_anchor_results, title extraction now only checks the anchor title attribute or stripped inner HTML, and falls back to the URL when that is empty. For card-style search markup where <a> contains only an <img alt="..."> (the case the old champion-cross parser explicitly handled), _normalize_anchor_text returns empty and users see raw URLs instead of work titles in search UI. This degrades result accuracy/usability and is a regression from the previous per-source logic.

Useful? React with 👍 / 👎.

Comment on lines +190 to +191
if normalized.startswith("/"):
normalized = urljoin(search_url, normalized)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve dot-relative hrefs before scheme checks

_resolve_result_url only calls urljoin when href starts with /, so valid relative links like ./work/123 or work/123 are passed to urlsplit with no scheme and then discarded. Since this module is now generic across many sources, dropping non-root-relative anchors can silently remove legitimate results from otherwise successful searches.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant