mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Fixed use of split() in lookup. Now strips whitespace. #94
This commit is contained in:
parent
b409a0cadf
commit
5deb9b2d16
1 changed files with 11 additions and 6 deletions
|
@ -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
|
This function currently ONLY does fuzzy matching if there are no exact
|
||||||
matches.
|
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:
|
Recognizes:
|
||||||
- Names: "Eevee", "Surf", "Run Away", "Payapa Berry", etc.
|
- 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:
|
else:
|
||||||
index, speller = open_index()
|
index, speller = open_index()
|
||||||
|
|
||||||
name = unicode(input).lower()
|
name = unicode(input).strip().lower()
|
||||||
exact = True
|
exact = True
|
||||||
form = None
|
form = None
|
||||||
|
|
||||||
# Remove any type prefix (pokemon:133) before constructing a query
|
# Remove any type prefix (pokemon:133) before constructing a query
|
||||||
if ':' in name:
|
if ':' in name:
|
||||||
prefix_chunk, name = name.split(':', 2)
|
prefix_chunk, name = name.split(':', 1)
|
||||||
prefixes = prefix_chunk.split(',')
|
name = name.strip()
|
||||||
|
|
||||||
if not valid_types:
|
if not valid_types:
|
||||||
# Only use types from the query string if none were explicitly
|
# Only use types from the query string if none were explicitly
|
||||||
# provided
|
# provided
|
||||||
valid_types = prefixes
|
prefixes = prefix_chunk.split(',')
|
||||||
|
valid_types = [_.strip() for _ in prefixes]
|
||||||
|
|
||||||
# Random lookup
|
# Random lookup
|
||||||
if name == 'random':
|
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 there's a space in the input, this might be a form
|
||||||
if ' ' in name:
|
if ' ' in name:
|
||||||
form, formless_name = name.split(' ', 2)
|
form, formless_name = name.split(' ', 1)
|
||||||
form_query = whoosh.query.Term(u'name', formless_name) \
|
form_query = whoosh.query.Term(u'name', formless_name) \
|
||||||
& whoosh.query.Term(u'forme_name', form)
|
& whoosh.query.Term(u'forme_name', form)
|
||||||
query = query | form_query
|
query = query | form_query
|
||||||
|
|
Loading…
Reference in a new issue