Skip to content

Commit cf85162

Browse files
committed
pushed ability to create db
1 parent 9f1cc69 commit cf85162

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Search_Engine/backend.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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")

Search_Engine/test_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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"

0 commit comments

Comments
 (0)