File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sqlite3
2
+ import test_data
3
+
4
+ class SearchEngine :
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" )
13
+ print (res .fetchall ())
14
+ # self.index = test_data['documents'][:-1]
15
+ # cur = conn.execute('CREATE TABLE keyvals (key TEXT PRIMARY KEY, value TEXT)')
16
+
17
+ def index_document (self , document ):
18
+ doc_num = 1
19
+ for word in document :
20
+ if word not in self .index :
21
+ self .index [word ] = set ([doc_num ])
22
+ else :
23
+ self .index .add (doc_num )
24
+ print (self .index )
25
+
26
+
27
+ def find_documents (self , search_term ):
28
+ pass
29
+
30
+ def _search_index (self ):
31
+ pass
32
+
33
+ if __name__ == "__main__" :
34
+ SearchEngine ("we should all strive to be happy" )
Original file line number Diff line number Diff line change
1
+ documents = [
2
+ "we should all strive to be happy" ,
3
+ "happiness is all you need" ,
4
+ "a cheerful heart is a happy one" ,
5
+ "no way should we be sad"
6
+ ]
7
+
8
+ search = "happy"
You can’t perform that action at this time.
0 commit comments