90fb3d33233afcb7a4b71837579fd911c6f06406
2 from sqlalchemy
.sql
import func
4 import pokedex
.db
.tables
as tables
6 def lookup(session
, name
):
7 """Attempts to find some sort of object, given a database session and name.
9 Returns a list of (object, matchiness) tuples. Matchiness is 1 for exact
10 matches. It is possible to get multiple exact matches; for example,
11 'Metronome' will match both the move and the item. In these cases, the
12 results are returned in rough order of "importance", e.g., Pokémon come
13 before moves come before types.
15 This function does fuzzy matching iff there are no exact matches.
17 Formes are not returned; "Shaymin" will return only grass Shaymin.
20 - Pokémon names: "Eevee"
23 q
= session
.query(tables
.Pokemon
) \
24 .filter(func
.lower(tables
.Pokemon
.name
) == name
.lower()) \
25 .filter_by(forme_base_pokemon_id
=None)
29 return [ (result
, 1) ]