Skip to content

Delete query refined to delete all related nodes of file #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async def post_processing(uri=Form(), userName=Form(), password=Form(), database
try:
graph = create_graph_database_connection(uri, userName, password, database)
tasks = set(map(str.strip, json.loads(tasks)))
count_response = ""
count_response = []
start = time.time()
if "materialize_text_chunk_similarities" in tasks:
await asyncio.to_thread(update_graph, graph)
Expand Down
30 changes: 16 additions & 14 deletions backend/src/graphDB_dataAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,18 @@ def delete_file_from_graph(self, filenames, source_types, deleteEntities:str, me
return count(*) as deletedChunks
"""
query_to_delete_document_and_entities="""
match (d:Document) where d.fileName IN $filename_list and d.fileSource in $source_types_list
detach delete d
with collect(d) as documents
unwind documents as d
match (d)<-[:PART_OF]-(c:Chunk)
detach delete c
with *
match (c)-[:HAS_ENTITY]->(e)
where not exists { (e)<-[:HAS_ENTITY]-()-[:PART_OF]->(d2) where not d2 in documents }
detach delete e
MATCH (d:Document)
WHERE d.fileName IN $filename_list AND d.fileSource IN $source_types_list
WITH COLLECT(d) as documents
UNWIND documents AS d
MATCH (d)<-[:PART_OF]-(c:Chunk)
WITH d, c, documents
OPTIONAL MATCH (c)-[:HAS_ENTITY]->(e)
WHERE NOT EXISTS {
MATCH (e)<-[:HAS_ENTITY]-(c2)-[:PART_OF]->(d2:Document)
WHERE NOT d2 IN documents
}
DETACH DELETE c, e, d
"""
query_to_delete_communities = """
MATCH (c:`__Community__`)
Expand All @@ -301,9 +303,9 @@ def delete_file_from_graph(self, filenames, source_types, deleteEntities:str, me

WITH *
UNWIND range(1, $max_level) AS level
MATCH (c:`__Community__`)
WHERE c.level = level AND NOT EXISTS { (c)<-[:PARENT_COMMUNITY]-(child) }
DETACH DELETE c
MATCH (c1:`__Community__`)
WHERE c1.level = level AND NOT EXISTS { (c1)<-[:PARENT_COMMUNITY]-(child) }
DETACH DELETE c1
"""
param = {"filename_list" : filename_list, "source_types_list": source_types_list}
community_param = {"max_level":MAX_COMMUNITY_LEVELS}
Expand Down Expand Up @@ -456,7 +458,7 @@ def update_node_relationship_count(self,document_name):
if (not document_name) and (community_flag):
result = self.execute_query(NODEREL_COUNT_QUERY_WITH_COMMUNITY)
elif (not document_name) and (not community_flag):
return None
return []
else:
param = {"document_name": document_name}
result = self.execute_query(NODEREL_COUNT_QUERY_WITHOUT_COMMUNITY, param)
Expand Down