Spaces:
Running
Running
Commit ·
3f059ef
1
Parent(s): 743e99a
fix(api): search product field, max_hops, evidence coalesce, sources, stats
Browse files- ai/connection_mapper.py +3 -3
- api/routes/search.py +3 -2
- api/routes/sources.py +2 -2
ai/connection_mapper.py
CHANGED
|
@@ -32,7 +32,7 @@ class ConnectionMapper:
|
|
| 32 |
rows = session.run(
|
| 33 |
"""
|
| 34 |
MATCH path = shortestPath(
|
| 35 |
-
(a {id:$a})-[*1..
|
| 36 |
)
|
| 37 |
RETURN [n IN nodes(path) | {id:n.id, name:n.name,
|
| 38 |
label:labels(n)[0]}] AS nodes,
|
|
@@ -40,7 +40,7 @@ class ConnectionMapper:
|
|
| 40 |
length(path) AS hops
|
| 41 |
LIMIT 10
|
| 42 |
""",
|
| 43 |
-
a=entity_a, b=entity_b
|
| 44 |
).data()
|
| 45 |
|
| 46 |
paths = []
|
|
@@ -102,7 +102,7 @@ class ConnectionMapper:
|
|
| 102 |
"""
|
| 103 |
MATCH (n {id:$id})-[r]-(m)
|
| 104 |
RETURN type(r) AS rel, labels(m)[0] AS node_type,
|
| 105 |
-
m.name AS name, m.id AS mid,
|
| 106 |
m.state AS state
|
| 107 |
LIMIT 30
|
| 108 |
""",
|
|
|
|
| 32 |
rows = session.run(
|
| 33 |
"""
|
| 34 |
MATCH path = shortestPath(
|
| 35 |
+
(a {id:$a})-[*1..$hops]-(b {id:$b})
|
| 36 |
)
|
| 37 |
RETURN [n IN nodes(path) | {id:n.id, name:n.name,
|
| 38 |
label:labels(n)[0]}] AS nodes,
|
|
|
|
| 40 |
length(path) AS hops
|
| 41 |
LIMIT 10
|
| 42 |
""",
|
| 43 |
+
a=entity_a, b=entity_b, hops=max_hops
|
| 44 |
).data()
|
| 45 |
|
| 46 |
paths = []
|
|
|
|
| 102 |
"""
|
| 103 |
MATCH (n {id:$id})-[r]-(m)
|
| 104 |
RETURN type(r) AS rel, labels(m)[0] AS node_type,
|
| 105 |
+
coalesce(m.name, m.title, m.product, m.item_desc, m.id) AS name, m.id AS mid,
|
| 106 |
m.state AS state
|
| 107 |
LIMIT 30
|
| 108 |
""",
|
api/routes/search.py
CHANGED
|
@@ -43,6 +43,7 @@ LABEL_QUERIES = {
|
|
| 43 |
"WHERE toLower(coalesce(n.item_desc,'')) CONTAINS toLower($q) "
|
| 44 |
" OR toLower(coalesce(n.buyer_org,'')) CONTAINS toLower($q) "
|
| 45 |
" OR toLower(coalesce(n.order_id,'')) CONTAINS toLower($q) "
|
|
|
|
| 46 |
"RETURN n.id AS id, coalesce(n.item_desc, n.order_id) AS name, "
|
| 47 |
" null AS state, null AS party LIMIT $limit"),
|
| 48 |
"ministry": ("Ministry",
|
|
@@ -118,8 +119,8 @@ def search_entities(
|
|
| 118 |
results=results[:limit],
|
| 119 |
generated_at=datetime.now().isoformat(),
|
| 120 |
)
|
| 121 |
-
except Exception:
|
| 122 |
-
|
| 123 |
|
| 124 |
with driver.session() as session:
|
| 125 |
if filter_type in ("all", ""):
|
|
|
|
| 43 |
"WHERE toLower(coalesce(n.item_desc,'')) CONTAINS toLower($q) "
|
| 44 |
" OR toLower(coalesce(n.buyer_org,'')) CONTAINS toLower($q) "
|
| 45 |
" OR toLower(coalesce(n.order_id,'')) CONTAINS toLower($q) "
|
| 46 |
+
" OR toLower(coalesce(n.product,'')) CONTAINS toLower($q) "
|
| 47 |
"RETURN n.id AS id, coalesce(n.item_desc, n.order_id) AS name, "
|
| 48 |
" null AS state, null AS party LIMIT $limit"),
|
| 49 |
"ministry": ("Ministry",
|
|
|
|
| 119 |
results=results[:limit],
|
| 120 |
generated_at=datetime.now().isoformat(),
|
| 121 |
)
|
| 122 |
+
except Exception as ft_err:
|
| 123 |
+
logger.debug(f"[Search] Full-text index unavailable: {type(ft_err).__name__}")
|
| 124 |
|
| 125 |
with driver.session() as session:
|
| 126 |
if filter_type in ("all", ""):
|
api/routes/sources.py
CHANGED
|
@@ -44,8 +44,8 @@ def sources_summary(driver=Depends(get_db)):
|
|
| 44 |
rows = s.run(
|
| 45 |
"""
|
| 46 |
MATCH (n)
|
| 47 |
-
WHERE n.source IS NOT NULL
|
| 48 |
-
RETURN n.source AS source, count(*) AS total
|
| 49 |
ORDER BY total DESC
|
| 50 |
"""
|
| 51 |
).data()
|
|
|
|
| 44 |
rows = s.run(
|
| 45 |
"""
|
| 46 |
MATCH (n)
|
| 47 |
+
WHERE n.source IS NOT NULL OR n.dataset IS NOT NULL
|
| 48 |
+
RETURN coalesce(n.dataset, n.source) AS source, count(*) AS total
|
| 49 |
ORDER BY total DESC
|
| 50 |
"""
|
| 51 |
).data()
|