Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Add FTS (Full-Text-Search)
Better server starter
  • Loading branch information
EndermanPC committed Feb 8, 2024
1 parent daf5b49 commit 7913e37
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 13 deletions.
Binary file added FTS/__pycache__/initializer.cpython-312.pyc
Binary file not shown.
Binary file added FTS/__pycache__/update.cpython-312.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions FTS/initializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sqlite3

def Initializer_Virtual_Table():
conn = sqlite3.connect('./database/search-index.db')

conn.execute('''CREATE VIRTUAL TABLE IF NOT EXISTS information_fts
USING FTS5(site_id, link, title, text, description, keywords, shorttext, added)''')

conn.close()
12 changes: 12 additions & 0 deletions FTS/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sqlite3

def Update_Virtual_Table():
conn = sqlite3.connect('./database/search-index.db')

conn.execute('DELETE FROM information_fts')
conn.execute('''INSERT INTO information_fts(site_id, link, title, text, description, keywords, shorttext, added)
SELECT site_id, link, title, text, description, keywords, shorttext, added FROM information''')

conn.commit()

conn.close()
1 change: 0 additions & 1 deletion acc.sh

This file was deleted.

18 changes: 18 additions & 0 deletions adpn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from datetime import datetime
import os
import shutil
import sqlite3
import subprocess
from FTS.initializer import Initializer_Virtual_Table
from FTS.update import Update_Virtual_Table
from account.userid import get_user_id
from account.username import get_username
from initializer.database import Initializer_Database
from log.write import log, sys_log
from account.loader import account_database_loader
from account.reliability import get_user_reliability
Expand Down Expand Up @@ -99,6 +104,7 @@ def change_reliability_by_user_id(user_id, new_reliability):

if reliability is None:
print("Account does not exist.")
exit()
elif reliability >= 4:
print('Logged in successfully.')
else:
Expand All @@ -110,10 +116,22 @@ def change_reliability_by_user_id(user_id, new_reliability):

if command == "exit":
exit()
elif command == "start":
yn = input('Do you want to start the server including: Search, Account [y/n]: ')
if (yn != 'n'):
Initializer_Database()
Initializer_Virtual_Table()
Update_Virtual_Table()
subprocess.call("start server1", shell=True)
subprocess.call("start server2", shell=True)
print('The server has been started successfully.')
sys_log('Start Server', str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
elif command == "check":
compare_databases()
elif command == "sync":
synchronization_databases()
elif command == "sync-fts":
Update_Virtual_Table()
elif command == "log":
with open('log.txt', 'r') as file:
for line in file:
Expand Down
1 change: 0 additions & 1 deletion adpn.sh

This file was deleted.

3 changes: 0 additions & 3 deletions all.bat

This file was deleted.

Binary file added database/users-account.db
Binary file not shown.
Binary file modified initializer/__pycache__/loader.cpython-312.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SYS: Loaded: users-account.db
SYS: Initializer Database: search-index.db
SYS: Initializer Censorship Database: censorship.db
SYS: Create Users Account Database: users-account.db
SYS: Start Server: 2024-02-08 18:24:56
SYS: Loaded: users-account.db
SYS: Loaded: search-index.db
4 changes: 0 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import streamlit as st
import time

from initializer.loader import database_loader
from manager.manager import *
from search.index import Search_Data
from initializer.database import Initializer_Database

Initializer_Database()

conn = database_loader()

Expand Down
1 change: 0 additions & 1 deletion run.sh

This file was deleted.

Binary file modified search/__pycache__/index.cpython-312.pyc
Binary file not shown.
5 changes: 2 additions & 3 deletions search/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
def Search_Data(conn, keyword):
cursor = conn.cursor()

cursor.execute('''SELECT * FROM information
WHERE title LIKE ? OR text LIKE ? OR description LIKE ? OR keywords LIKE ? OR shorttext LIKE ?''',
('%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%', '%' + keyword + '%'))
cursor.execute('''SELECT * FROM information_fts
WHERE information_fts MATCH ?''', (keyword,))

rows = cursor.fetchall()
conn.close()
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7913e37

Please sign in to comment.