mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Removed whoosh hacks; 0.3 obviates them. #15
This commit is contained in:
parent
16072ceb44
commit
0300e01cff
2 changed files with 2 additions and 33 deletions
|
@ -86,10 +86,6 @@ def open_index(directory=None, session=None, recreate=False):
|
||||||
table=whoosh.fields.STORED,
|
table=whoosh.fields.STORED,
|
||||||
row_id=whoosh.fields.STORED,
|
row_id=whoosh.fields.STORED,
|
||||||
language=whoosh.fields.STORED,
|
language=whoosh.fields.STORED,
|
||||||
|
|
||||||
# Whoosh 0.2 explodes when using a file-stored schema with no TEXT
|
|
||||||
# columns. Appease it
|
|
||||||
dummy=whoosh.fields.TEXT,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
index = whoosh.index.create_in(directory, schema=schema,
|
index = whoosh.index.create_in(directory, schema=schema,
|
||||||
|
@ -124,38 +120,11 @@ def open_index(directory=None, session=None, recreate=False):
|
||||||
|
|
||||||
writer.commit()
|
writer.commit()
|
||||||
|
|
||||||
# XXX GIHWEGREHKG
|
|
||||||
old__schema = whoosh.spelling.SpellChecker._schema
|
|
||||||
def new__schema(self):
|
|
||||||
schema = old__schema(self)
|
|
||||||
schema.add('dummy', whoosh.fields.TEXT)
|
|
||||||
return schema
|
|
||||||
whoosh.spelling.SpellChecker._schema = new__schema
|
|
||||||
|
|
||||||
# Construct and populate a spell-checker index. Quicker to do it all
|
# Construct and populate a spell-checker index. Quicker to do it all
|
||||||
# at once, as every call to add_* does a commit(), and those seem to be
|
# at once, as every call to add_* does a commit(), and those seem to be
|
||||||
# expensive
|
# expensive
|
||||||
speller = whoosh.spelling.SpellChecker(index.storage, indexname='spelling')
|
speller = whoosh.spelling.SpellChecker(index.storage, indexname='spelling')
|
||||||
# WARNING: HERE BE DRAGONS
|
speller.add_words(speller_entries)
|
||||||
# whoosh.spelling refuses to index things that don't look like words.
|
|
||||||
# Unfortunately, this doesn't work so well for Pokémon (Mr. Mime,
|
|
||||||
# Porygon-Z, etc.), and attempts to work around it lead to further
|
|
||||||
# complications.
|
|
||||||
# The below is copied from SpellChecker.add_scored_words without the check
|
|
||||||
# for isalpha(). XXX get whoosh patched to make this unnecessary!
|
|
||||||
writer = speller.index(create=True).writer()
|
|
||||||
for word in speller_entries:
|
|
||||||
fields = {"word": word, "score": 1}
|
|
||||||
for size in xrange(speller.mingram, speller.maxgram + 1):
|
|
||||||
nga = whoosh.analysis.NgramAnalyzer(size)
|
|
||||||
gramlist = [t.text for t in nga(word)]
|
|
||||||
if len(gramlist) > 0:
|
|
||||||
fields["start%s" % size] = gramlist[0]
|
|
||||||
fields["end%s" % size] = gramlist[-1]
|
|
||||||
fields["gram%s" % size] = " ".join(gramlist)
|
|
||||||
writer.add_document(**fields)
|
|
||||||
writer.commit()
|
|
||||||
# end copy-pasta
|
|
||||||
|
|
||||||
return index, speller
|
return index, speller
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ setup(
|
||||||
version = '0.1',
|
version = '0.1',
|
||||||
packages = find_packages(),
|
packages = find_packages(),
|
||||||
package_data = { '': 'data' },
|
package_data = { '': 'data' },
|
||||||
install_requires=['SQLAlchemy>=0.5.1', 'whoosh>=0.2.0'],
|
install_requires=['SQLAlchemy>=0.5.1', 'whoosh>=0.3.0b1'],
|
||||||
|
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|
Loading…
Reference in a new issue