Skip to content

Commit

Permalink
internal/postgres: insert search_documents path ids
Browse files Browse the repository at this point in the history
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 <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
julieqiu committed May 13, 2021
1 parent 1726a85 commit 1255f84
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/postgres/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 1255f84

Please sign in to comment.