card Rule lookup #3

Closed
opened 2026-08-16 11:31:46 -05:00 by pyaniz · 1 comment
Owner

Add the ability to look up for specific card text examples in the rules. For example /rules "blood moon" should return all the rules that have the text blood moon in it. This is for rules, not gatherer.

Add the ability to look up for specific card text examples in the rules. For example /rules "blood moon" should return all the rules that have the text blood moon in it. This is for rules, not gatherer.
Author
Owner

Implemented. This turned out to need two separate things, because the literal request doesn't work on its own.

Finding first: the Comprehensive Rules contain zero occurrences of "blood moon". The CR is a rules document and almost never names individual cards, so /rules "blood moon" searching rule text correctly returns nothing. Implementing only the literal request would have looked broken on the exact example in this issue.

1. Phrase search (the literal request)

/rules "double strike" now matches those words adjacently. Previously the query was tokenised and OR'd, so blood moon returned every rule containing blood or moon — 5 results, all noise. Now:

  • quoted query → exact phrase match
  • unquoted query → every word must appear, loosening only if that finds nothing

2. Card lookup (what the example actually needed)

When a text search finds nothing and the query names a card, the bot answers the question being asked instead:

/rules blood moon

The rules don't mention Blood Moon by name — they rarely name cards
at all. These are the rules behind what it does:

Nonbasic Land — 205.4   Any land that doesn't have the supertype "basic."
Enchantment — 303       A card type. An enchantment is a permanent.
Mountain — 305.6        The basic land types are Plains, Island, Swamp…

The bridge is the glossary: 657 of its 739 entries cite a rule number, so a card's type line and oracle text map onto the rules that govern them. Cards with keyword abilities lead with those — Questing Beast returns vigilance (702.20), haste (702.10) and deathtouch (702.2).

Known quirk

/rules lightning bolt returns rule 107.10, which genuinely contains the phrase "a lightning bolt for instant" while describing Future Sight frame icons. It's a correct literal match, so the card path doesn't trigger.

Left literal on purpose: preferring cards would hijack searches for terms that are both a card and a rules concept, such as counterspell. Easy to flip if the card reading is preferred.

Changed

  • bot/rules_engine/search.py — phrase/all/any search modes, glossary concept extraction
  • bot/handlers/rules.py — search order and the card fallback
  • bot/scryfall.py — expose card keywords
  • help text and README

Verified no regressions in the inline !q rules mode or the /ask retrieval path.

Implemented. This turned out to need two separate things, because the literal request doesn't work on its own. **Finding first:** the Comprehensive Rules contain zero occurrences of "blood moon". The CR is a rules document and almost never names individual cards, so `/rules "blood moon"` searching rule text correctly returns nothing. Implementing only the literal request would have looked broken on the exact example in this issue. ### 1. Phrase search (the literal request) `/rules "double strike"` now matches those words adjacently. Previously the query was tokenised and OR'd, so `blood moon` returned every rule containing *blood* or *moon* — 5 results, all noise. Now: - quoted query → exact phrase match - unquoted query → every word must appear, loosening only if that finds nothing ### 2. Card lookup (what the example actually needed) When a text search finds nothing and the query names a card, the bot answers the question being asked instead: ``` /rules blood moon The rules don't mention Blood Moon by name — they rarely name cards at all. These are the rules behind what it does: Nonbasic Land — 205.4 Any land that doesn't have the supertype "basic." Enchantment — 303 A card type. An enchantment is a permanent. Mountain — 305.6 The basic land types are Plains, Island, Swamp… ``` The bridge is the glossary: 657 of its 739 entries cite a rule number, so a card's type line and oracle text map onto the rules that govern them. Cards with keyword abilities lead with those — Questing Beast returns vigilance (702.20), haste (702.10) and deathtouch (702.2). ### Known quirk `/rules lightning bolt` returns rule 107.10, which genuinely contains the phrase "a lightning bolt for instant" while describing Future Sight frame icons. It's a correct literal match, so the card path doesn't trigger. Left literal on purpose: preferring cards would hijack searches for terms that are both a card and a rules concept, such as `counterspell`. Easy to flip if the card reading is preferred. ### Changed - `bot/rules_engine/search.py` — phrase/all/any search modes, glossary concept extraction - `bot/handlers/rules.py` — search order and the card fallback - `bot/scryfall.py` — expose card keywords - help text and README Verified no regressions in the inline `!q` rules mode or the `/ask` retrieval path.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pyaniz/mtg-bot#3
No description provided.