[changes] Optimize the Cypher query statement
This commit is contained in:
@@ -339,6 +339,19 @@ LIMIT $limit
|
|||||||
SEARCH_ENTITIES_BY_NAME_OR_ALIAS = """
|
SEARCH_ENTITIES_BY_NAME_OR_ALIAS = """
|
||||||
CALL db.index.fulltext.queryNodes("entitiesFulltext", $q) YIELD node AS e, score
|
CALL db.index.fulltext.queryNodes("entitiesFulltext", $q) YIELD node AS e, score
|
||||||
WHERE ($end_user_id IS NULL OR e.end_user_id = $end_user_id)
|
WHERE ($end_user_id IS NULL OR e.end_user_id = $end_user_id)
|
||||||
|
WITH e, score
|
||||||
|
UNION
|
||||||
|
MATCH (e:ExtractedEntity)
|
||||||
|
WHERE ($end_user_id IS NULL OR e.end_user_id = $end_user_id)
|
||||||
|
AND e.aliases IS NOT NULL
|
||||||
|
AND ANY(alias IN e.aliases WHERE toLower(alias) CONTAINS toLower($q))
|
||||||
|
WITH e,
|
||||||
|
CASE
|
||||||
|
WHEN ANY(alias IN e.aliases WHERE toLower(alias) = toLower($q)) THEN 1.0
|
||||||
|
WHEN ANY(alias IN e.aliases WHERE toLower(alias) STARTS WITH toLower($q)) THEN 0.9
|
||||||
|
ELSE 0.8
|
||||||
|
END AS score
|
||||||
|
WITH DISTINCT e, MAX(score) AS score
|
||||||
OPTIONAL MATCH (s:Statement)-[:REFERENCES_ENTITY]->(e)
|
OPTIONAL MATCH (s:Statement)-[:REFERENCES_ENTITY]->(e)
|
||||||
OPTIONAL MATCH (c:Chunk)-[:CONTAINS]->(s)
|
OPTIONAL MATCH (c:Chunk)-[:CONTAINS]->(s)
|
||||||
RETURN e.id AS id,
|
RETURN e.id AS id,
|
||||||
@@ -360,32 +373,6 @@ RETURN e.id AS id,
|
|||||||
e.last_access_time AS last_access_time,
|
e.last_access_time AS last_access_time,
|
||||||
COALESCE(e.access_count, 0) AS access_count,
|
COALESCE(e.access_count, 0) AS access_count,
|
||||||
score
|
score
|
||||||
UNION
|
|
||||||
MATCH (e:ExtractedEntity)
|
|
||||||
WHERE ($end_user_id IS NULL OR e.end_user_id = $end_user_id)
|
|
||||||
AND e.aliases IS NOT NULL
|
|
||||||
AND ANY(alias IN e.aliases WHERE toLower(alias) CONTAINS toLower($q))
|
|
||||||
OPTIONAL MATCH (s:Statement)-[:REFERENCES_ENTITY]->(e)
|
|
||||||
OPTIONAL MATCH (c:Chunk)-[:CONTAINS]->(s)
|
|
||||||
RETURN e.id AS id,
|
|
||||||
e.name AS name,
|
|
||||||
e.end_user_id AS end_user_id,
|
|
||||||
e.entity_type AS entity_type,
|
|
||||||
e.created_at AS created_at,
|
|
||||||
e.expired_at AS expired_at,
|
|
||||||
e.entity_idx AS entity_idx,
|
|
||||||
e.statement_id AS statement_id,
|
|
||||||
e.description AS description,
|
|
||||||
e.aliases AS aliases,
|
|
||||||
e.name_embedding AS name_embedding,
|
|
||||||
e.connect_strength AS connect_strength,
|
|
||||||
collect(DISTINCT s.id) AS statement_ids,
|
|
||||||
collect(DISTINCT c.id) AS chunk_ids,
|
|
||||||
COALESCE(e.activation_value, e.importance_score, 0.5) AS activation_value,
|
|
||||||
COALESCE(e.importance_score, 0.5) AS importance_score,
|
|
||||||
e.last_access_time AS last_access_time,
|
|
||||||
COALESCE(e.access_count, 0) AS access_count,
|
|
||||||
0.8 AS score
|
|
||||||
ORDER BY score DESC
|
ORDER BY score DESC
|
||||||
LIMIT $limit
|
LIMIT $limit
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user