File tree Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Original file line number Diff line number Diff line change 3
3
4
4
class SearchEngine :
5
5
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" )
13
23
print (res .fetchall ())
14
24
# self.index = test_data['documents'][:-1]
15
- # cur = conn.execute('CREATE TABLE keyvals (key TEXT PRIMARY KEY, value TEXT)')
25
+ #
16
26
17
27
def index_document (self , document ):
18
28
doc_num = 1
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments