|
|
|
@ -110,13 +110,20 @@ class IndexData:
|
|
|
|
|
|
|
|
|
|
def has_indexes(self, user_id):
|
|
|
|
|
try:
|
|
|
|
|
return len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}"))) > 0
|
|
|
|
|
return (
|
|
|
|
|
len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}"))) > 0
|
|
|
|
|
)
|
|
|
|
|
except Exception:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def has_search_indexes(self, user_id):
|
|
|
|
|
try:
|
|
|
|
|
return len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search"))) > 0
|
|
|
|
|
return (
|
|
|
|
|
len(
|
|
|
|
|
os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search"))
|
|
|
|
|
)
|
|
|
|
|
> 0
|
|
|
|
|
)
|
|
|
|
|
except Exception:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
@ -125,7 +132,9 @@ class IndexData:
|
|
|
|
|
self.queryable_index = index
|
|
|
|
|
|
|
|
|
|
# Create a folder called "indexes/{USER_ID}" if it doesn't exist already
|
|
|
|
|
Path(f"{EnvService.save_path()}/indexes/{user_id}").mkdir(parents=True, exist_ok=True)
|
|
|
|
|
Path(f"{EnvService.save_path()}/indexes/{user_id}").mkdir(
|
|
|
|
|
parents=True, exist_ok=True
|
|
|
|
|
)
|
|
|
|
|
# Save the index to file under the user id
|
|
|
|
|
file = f"{file_name}_{date.today().month}_{date.today().day}"
|
|
|
|
|
# If file is > 93 in length, cut it off to 93
|
|
|
|
@ -145,8 +154,12 @@ class IndexData:
|
|
|
|
|
# First, clear all the files inside it
|
|
|
|
|
for file in os.listdir(EnvService.find_shared_file(f"indexes/{user_id}")):
|
|
|
|
|
os.remove(EnvService.find_shared_file(f"indexes/{user_id}/{file}"))
|
|
|
|
|
for file in os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search")):
|
|
|
|
|
os.remove(EnvService.find_shared_file(f"indexes/{user_id}_search/{file}"))
|
|
|
|
|
for file in os.listdir(
|
|
|
|
|
EnvService.find_shared_file(f"indexes/{user_id}_search")
|
|
|
|
|
):
|
|
|
|
|
os.remove(
|
|
|
|
|
EnvService.find_shared_file(f"indexes/{user_id}_search/{file}")
|
|
|
|
|
)
|
|
|
|
|
except Exception:
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
@ -792,7 +805,9 @@ class Index_handler:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Save the composed index
|
|
|
|
|
tree_index.save_to_disk(EnvService.save_path() / "indexes" / str(user_id) / name)
|
|
|
|
|
tree_index.save_to_disk(
|
|
|
|
|
EnvService.save_path() / "indexes" / str(user_id) / name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.index_storage[user_id].queryable_index = tree_index
|
|
|
|
|
|
|
|
|
@ -822,7 +837,9 @@ class Index_handler:
|
|
|
|
|
name = f"composed_index_{date.today().month}_{date.today().day}.json"
|
|
|
|
|
|
|
|
|
|
# Save the composed index
|
|
|
|
|
simple_index.save_to_disk(EnvService.save_path() / "indexes" / str(user_id) / name)
|
|
|
|
|
simple_index.save_to_disk(
|
|
|
|
|
EnvService.save_path() / "indexes" / str(user_id) / name
|
|
|
|
|
)
|
|
|
|
|
self.index_storage[user_id].queryable_index = simple_index
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|