X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/c8551bf2e5b4f33200ca91b6e8c4cf4a5fc109ee..ddf045e67f3d31777d4dba6e9965ed62a29084ed:/pokedex/lookup.py diff --git a/pokedex/lookup.py b/pokedex/lookup.py index b5b0c6d..1ba3fd1 100644 --- a/pokedex/lookup.py +++ b/pokedex/lookup.py @@ -206,7 +206,10 @@ def lookup(input, valid_types=[], session=None, indices=None, exact_only=False): This function currently ONLY does fuzzy matching if there are no exact matches. - Formes are not returned; "Shaymin" will return only grass Shaymin. + Formes are not returned unless requested; "Shaymin" will return only grass + Shaymin. + + Extraneous whitespace is removed with extreme prejudice. Recognizes: - Names: "Eevee", "Surf", "Run Away", "Payapa Berry", etc. @@ -251,18 +254,20 @@ def lookup(input, valid_types=[], session=None, indices=None, exact_only=False): else: index, speller = open_index() - name = unicode(input).lower() + name = unicode(input).strip().lower() exact = True form = None # Remove any type prefix (pokemon:133) before constructing a query if ':' in name: - prefix_chunk, name = name.split(':', 2) - prefixes = prefix_chunk.split(',') + prefix_chunk, name = name.split(':', 1) + name = name.strip() + if not valid_types: # Only use types from the query string if none were explicitly # provided - valid_types = prefixes + prefixes = prefix_chunk.split(',') + valid_types = [_.strip() for _ in prefixes] # Random lookup if name == 'random': @@ -287,7 +292,7 @@ def lookup(input, valid_types=[], session=None, indices=None, exact_only=False): # If there's a space in the input, this might be a form if ' ' in name: - form, formless_name = name.split(' ', 2) + form, formless_name = name.split(' ', 1) form_query = whoosh.query.Term(u'name', formless_name) \ & whoosh.query.Term(u'forme_name', form) query = query | form_query