feat(search): weight subject above body in FTS vector (#14)
CI / backend (push) Successful in 1m5s
CI / frontend (push) Successful in 23s
Deploy Staging / deploy (push) Successful in 38s
CI / backend (pull_request) Successful in 1m17s
CI / frontend (pull_request) Successful in 22s
Security / secrets (push) Successful in 4s
Security / dependencies (push) Successful in 1m2s
Security / secrets (pull_request) Successful in 4s
Security / dependencies (pull_request) Successful in 1m2s
CI / backend (push) Successful in 1m5s
CI / frontend (push) Successful in 23s
Deploy Staging / deploy (push) Successful in 38s
CI / backend (pull_request) Successful in 1m17s
CI / frontend (pull_request) Successful in 22s
Security / secrets (push) Successful in 4s
Security / dependencies (push) Successful in 1m2s
Security / secrets (pull_request) Successful in 4s
Security / dependencies (pull_request) Successful in 1m2s
This commit was merged in pull request #14.
This commit is contained in:
@@ -59,15 +59,17 @@ public class AppDbContext : DbContext, IAppDbContext
|
||||
modelBuilder.Entity<UnsubscribeItem>().HasQueryFilter(e => CurrentUserId == Guid.Empty || e.UserId == CurrentUserId);
|
||||
|
||||
// PostgreSQL full-text search: generated tsvector over subject + body with a
|
||||
// GIN index, maintained by the DB and read-only in code. The tsvector type is
|
||||
// Npgsql-only, so map it only for relational providers and ignore it otherwise
|
||||
// (e.g. the InMemory provider used by tests). Production behaviour is unchanged.
|
||||
// GIN index, maintained by the DB and read-only in code. Subject is weighted 'A'
|
||||
// and body 'B' so ts_rank_cd ranks a subject match above a body-only mention. The
|
||||
// tsvector type is Npgsql-only, so map it only for relational providers and ignore
|
||||
// it otherwise (e.g. the InMemory provider used by tests).
|
||||
if (Database.IsRelational())
|
||||
{
|
||||
modelBuilder.Entity<Email>().Property(e => e.SearchVector)
|
||||
.HasColumnType("tsvector")
|
||||
.HasComputedColumnSql(
|
||||
"to_tsvector('english', coalesce(\"Subject\",'') || ' ' || coalesce(\"BodyText\",''))",
|
||||
"setweight(to_tsvector('english', coalesce(\"Subject\",'')), 'A') || " +
|
||||
"setweight(to_tsvector('english', coalesce(\"BodyText\",'')), 'B')",
|
||||
stored: true);
|
||||
modelBuilder.Entity<Email>().HasIndex(e => e.SearchVector).HasMethod("GIN");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user