Skip to content

Commit

Permalink
update sql
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Oct 20, 2024
1 parent 17a371f commit 823ba33
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
''')

c.execute('CREATE INDEX IF NOT EXISTS idx_word ON words(word);')
c.execute('delete from words;')
c.execute("PRAGMA journal_mode=WAL")

# Insert data
for word, details in data.items():
c.execute('''
INSERT INTO words (word, frequency, translation, ipa) VALUES (?, ?, ?, ?)
INSERT INTO words (word, frequency, translation, ipa) VALUES (?,?,?,?)
''', (word, details['frequency'], '|'.join(details['translation']), details['ipa']))

# Commit the changes and close the connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def query_words_by_prefix(prefix):
with sqlite3.connect('words_with_frequency_and_translation_and_ipa.sqlite3') as conn:
c = conn.cursor()
# The LIKE operator is case-insensitive in SQLite by default
c.execute('SELECT * FROM words WHERE word LIKE ? ORDER BY frequency DESC limit 30', (prefix + '%',))
c.execute('SELECT * FROM words WHERE word LIKE ? ORDER BY frequency DESC limit 10', (prefix + '%',))
results = c.fetchall()
# conn.close()

Expand Down
Binary file not shown.

0 comments on commit 823ba33

Please sign in to comment.