Skip to content

Commit

Permalink
make full text call optional to not 500
Browse files Browse the repository at this point in the history
  • Loading branch information
cutoffthetop committed Nov 20, 2024
1 parent b7fda72 commit a375ff3
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 70 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changes

- clean up non-functional cypher query style issues

### Deprecated

### Removed

### Fixed

- do not raise server error when search query is not found

### Security

## [0.23.0] - 2024-11-19
Expand Down
2 changes: 1 addition & 1 deletion mex/backend/graph/cypher/exists_merged_item.cql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Returns:
-#>
RETURN EXISTS {
MATCH (:<<node_labels|join("|")>> {identifier: $identifier})
} as exists;
} AS exists;
8 changes: 4 additions & 4 deletions mex/backend/graph/cypher/fetch_extracted_or_rule_items.cql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Returns:
CALL () {
<%- block match_clause -%>
<%- if filter_by_query_string %>
CALL db.index.fulltext.queryNodes("search_index", $query_string)
OPTIONAL CALL db.index.fulltext.queryNodes("search_index", $query_string)
YIELD node AS hit, score
<%- endif %>
OPTIONAL MATCH (n:<<rule_labels|join("|")>>|<<extracted_labels|join("|")>>)
Expand Down Expand Up @@ -47,16 +47,16 @@ CALL () {
label: type(r),
position: r.position,
value: referenced.identifier
} ELSE NULL END as ref
} ELSE NULL END AS ref
UNION
OPTIONAL MATCH (n)-[r]->(nested:<<nested_labels|join("|")>>)
RETURN CASE WHEN nested IS NOT NULL THEN {
label: type(r),
position: r.position,
value: properties(nested)
} ELSE NULL END as ref
} ELSE NULL END AS ref
}
WITH n, collect(ref) as refs
WITH n, collect(ref) AS refs
RETURN n{.*, entityType: head(labels(n)), _refs: refs}
ORDER BY n.identifier, n.entityType ASC
SKIP $skip
Expand Down
8 changes: 4 additions & 4 deletions mex/backend/graph/cypher/fetch_identities.cql
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ WHERE
<%- endif -%>
<%- endif %>
RETURN
merged.identifier as stableTargetId,
primary_source.identifier as hadPrimarySource,
n.identifierInPrimarySource as identifierInPrimarySource,
n.identifier as identifier
merged.identifier AS stableTargetId,
primary_source.identifier AS hadPrimarySource,
n.identifierInPrimarySource AS identifierInPrimarySource,
n.identifier AS identifier
ORDER BY n.identifier ASC
LIMIT $limit;
12 changes: 6 additions & 6 deletions mex/backend/graph/cypher/fetch_merged_items.cql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Returns:
CALL () {
<%- block match_clause -%>
<%- if filter_by_query_string %>
CALL db.index.fulltext.queryNodes("search_index", $query_string)
OPTIONAL CALL db.index.fulltext.queryNodes("search_index", $query_string)
YIELD node AS hit, score
<%- endif %>
OPTIONAL MATCH (n:<<rule_labels|join("|")>>|<<extracted_labels|join("|")>>)-[:stableTargetId]->(merged:<<merged_labels|join("|")>>)
Expand All @@ -35,7 +35,7 @@ CALL () {
<<and_()>>merged.identifier = $stable_target_id
<%- endif %>
<<and_()>>ANY(label IN labels(merged) WHERE label IN $labels)
WITH DISTINCT merged as merged
WITH DISTINCT merged AS merged
<%- endblock %>
RETURN COUNT(merged) AS total
}
Expand All @@ -49,18 +49,18 @@ CALL () {
label: type(r),
position: r.position,
value: referenced.identifier
} ELSE NULL END as ref
} ELSE NULL END AS ref
UNION
OPTIONAL MATCH (n)-[r]->(nested:<<nested_labels|join("|")>>)
RETURN CASE WHEN nested IS NOT NULL THEN {
label: type(r),
position: r.position,
value: properties(nested)
} ELSE NULL END as ref
} ELSE NULL END AS ref
}
WITH merged, n, collect(ref) as refs
WITH merged, n, collect(ref) AS refs
ORDER BY merged.identifier, n.identifier, head(labels(n)) ASC
WITH merged, collect(n{.*, entityType: head(labels(n)), _refs: refs}) as n
WITH merged, collect(n{.*, entityType: head(labels(n)), _refs: refs}) AS n
RETURN merged{entityType: head(labels(merged)), identifier: merged.identifier, components: n}
SKIP $skip
LIMIT $limit
Expand Down
6 changes: 3 additions & 3 deletions mex/backend/graph/cypher/merge_edges.cql
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ CALL (source) {
RETURN edge
<%- endfor %>
<%- else %>
RETURN null as edge
RETURN null AS edge
<%- endif %>
}
WITH source, count(edge) as merged, collect(edge) as edges
WITH source, count(edge) AS merged, collect(edge) AS edges
CALL (source, edges) {
MATCH (source)-[outdated_edge]->(:<<merged_labels|join("|")>>)
WHERE NOT outdated_edge IN edges
DELETE outdated_edge
RETURN count(outdated_edge) as pruned
RETURN count(outdated_edge) AS pruned
}
RETURN merged, pruned, edges;
6 changes: 3 additions & 3 deletions mex/backend/graph/cypher/merge_item.cql
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ ON CREATE SET value_<<index>> = $nested_values[<<index>>]
ON MATCH SET value_<<index>> += $nested_values[<<index>>]
<%- endfor %>
WITH current,
[<<range(nested_edge_labels|count)|map("ensure_prefix", "edge_")|join(", ")>>] as edges,
[<<range(nested_edge_labels|count)|map("ensure_prefix", "value_")|join(", ")>>] as values
[<<range(nested_edge_labels|count)|map("ensure_prefix", "edge_")|join(", ")>>] AS edges,
[<<range(nested_edge_labels|count)|map("ensure_prefix", "value_")|join(", ")>>] AS values
CALL (current, values) {
MATCH (current)-[]->(outdated_node:<<nested_labels|join("|")>>)
WHERE NOT outdated_node IN values
DETACH DELETE outdated_node
RETURN count(outdated_node) as pruned
RETURN count(outdated_node) AS pruned
}
RETURN current, edges, values, pruned;
2 changes: 1 addition & 1 deletion mex/backend/merged/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def search_merged_items(
skip: Annotated[int, Query(ge=0, le=10e10)] = 0,
limit: Annotated[int, Query(ge=1, le=100)] = 10,
) -> MergedItemSearch:
"""Search for merged items by query text or by type and id."""
"""Search for merged items by query text or by type and identifier."""
return search_merged_items_in_graph(
q,
identifier,
Expand Down
4 changes: 3 additions & 1 deletion tests/extracted/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,16 @@ def test_search_extracted_items_mocked(
},
),
("?stableTargetId=thisIdDoesNotExist", {"items": [], "total": 0}),
("?q=queryNotFound", {"items": [], "total": 0}),
],
ids=[
"limit 1",
"skip 1",
"entity type contact points",
"full text search",
"stable target id filter",
"empty result",
"identifier not found",
"full text not found",
],
)
@pytest.mark.usefixtures("load_dummy_data")
Expand Down
Loading

0 comments on commit a375ff3

Please sign in to comment.