From 1255f844e6438fb19ee582ee7be4168dbd207178 Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Mon, 10 May 2021 14:42:07 -0400 Subject: [PATCH] internal/postgres: insert search_documents path ids The search_documents columns package_path_id and module_path_id are now populated. For golang/go#44142 Change-Id: I1833bfc821f3a3ebe5b71a562e616d0c6b2dc20a Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/318490 Trust: Julie Qiu Run-TryBot: Julie Qiu TryBot-Result: kokoro Reviewed-by: Jonathan Amsterdam --- internal/postgres/search.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/postgres/search.go b/internal/postgres/search.go index cfcf6bdd..7279154e 100644 --- a/internal/postgres/search.go +++ b/internal/postgres/search.go @@ -457,8 +457,10 @@ func groupSearchResults(rs []*internal.SearchResult) []*internal.SearchResult { var upsertSearchStatement = fmt.Sprintf(` INSERT INTO search_documents ( package_path, + package_path_id, version, module_path, + module_path_id, name, synopsis, license_types, @@ -471,9 +473,11 @@ var upsertSearchStatement = fmt.Sprintf(` hll_leading_zeros ) SELECT - p.path, + p1.path, + p1.id, m.version, m.module_path, + p2.id, u.name, d.synopsis, u.license_types, @@ -487,14 +491,15 @@ var upsertSearchStatement = fmt.Sprintf(` SETWEIGHT(TO_TSVECTOR($6), 'C') || SETWEIGHT(TO_TSVECTOR($7), 'D') ), - hll_hash(p.path) & (%d - 1), - hll_zeros(hll_hash(p.path)) + hll_hash(p1.path) & (%d - 1), + hll_zeros(hll_hash(p1.path)) FROM units u - INNER JOIN paths p ON p.id = u.path_id INNER JOIN modules m ON u.module_id = m.id + INNER JOIN paths p1 ON p1.id = u.path_id + LEFT JOIN paths p2 ON p2.path = m.module_path LEFT JOIN documentation d ON u.id = d.unit_id WHERE - p.path = $1 + p1.path = $1 AND m.module_path = $2 AND m.version = $3 LIMIT 1 -- could be multiple build contexts