Skip to content

Commit 1a741e7

Browse files
committed
updated method to create tables if not exists
1 parent cf85162 commit 1a741e7

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Search_Engine/backend.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@
33

44
class SearchEngine:
55
def __init__(self, document1):
6-
# initialize database
7-
conn = sqlite3.connect("searchengine.db")
8-
cur = conn.cursor()
9-
cur.execute("CREATE TABLE DocumentStore(id INTEGER PRIMARY KEY, document TEXT)")
10-
cur.execute("INSERT INTO DocumentStore (document) VALUES (?)", (document1,))
11-
conn.commit()
12-
res = cur.execute("SELECT * FROM DocumentStore")
6+
"""
7+
- Initialize database.
8+
- Check if the tables exist, if not create them
9+
"""
10+
self.conn = sqlite3.connect("searchengine.db")
11+
cur = self.conn.cursor()
12+
res = cur.execute("SELECT name FROM sqlite_master WHERE name='IndexToWord'")
13+
tables_exist = res.fetchone()
14+
# tables_exist = res.fetchall()
15+
if not tables_exist:
16+
self.conn.execute("CREATE TABLE IndexToWord(id INTEGER PRIMARY KEY, document TEXT)")
17+
self.conn.execute('CREATE TABLE WordToIndex (store TEXT)')
18+
# self.conn.commit()
19+
20+
# cur.execute("INSERT INTO DocumentStore (document) VALUES (?)", (document1,))
21+
# self.conn.commit()
22+
res = cur.execute("SELECT name FROM sqlite_master")
1323
print(res.fetchall())
1424
# self.index = test_data['documents'][:-1]
15-
# cur = conn.execute('CREATE TABLE keyvals (key TEXT PRIMARY KEY, value TEXT)')
25+
#
1626

1727
def index_document(self, document):
1828
doc_num = 1

Search_Engine/test.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)