🗑️ Remove the shit simple search vector

This commit is contained in:
2025-10-26 02:45:15 +08:00
parent bf1c8e0a85
commit 83fa2568aa
6 changed files with 1985 additions and 40 deletions

View File

@@ -70,8 +70,6 @@ public class SnPost : ModelBase, IIdentifiedResource, IActivity
[Column(TypeName = "jsonb")] public List<SnCloudFileReferenceObject> Attachments { get; set; } = []; [Column(TypeName = "jsonb")] public List<SnCloudFileReferenceObject> Attachments { get; set; } = [];
[JsonIgnore] public NpgsqlTsVector SearchVector { get; set; } = null!;
public Guid PublisherId { get; set; } public Guid PublisherId { get; set; }
public SnPublisher Publisher { get; set; } = null!; public SnPublisher Publisher { get; set; } = null!;

View File

@@ -82,11 +82,6 @@ public class AppDatabase(
.HasForeignKey(ps => ps.PublisherId) .HasForeignKey(ps => ps.PublisherId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<SnPost>()
.HasGeneratedTsVectorColumn(p => p.SearchVector, "simple", p => new { p.Title, p.Description, p.Content })
.HasIndex(p => p.SearchVector)
.HasMethod("GIN");
modelBuilder.Entity<SnPost>() modelBuilder.Entity<SnPost>()
.HasOne(p => p.RepliedPost) .HasOne(p => p.RepliedPost)
.WithMany() .WithMany()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
using Microsoft.EntityFrameworkCore.Migrations;
using NpgsqlTypes;
#nullable disable
namespace DysonNetwork.Sphere.Migrations
{
/// <inheritdoc />
public partial class RemovePostSearchVector : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "ix_posts_search_vector",
table: "posts");
migrationBuilder.DropColumn(
name: "search_vector",
table: "posts");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<NpgsqlTsVector>(
name: "search_vector",
table: "posts",
type: "tsvector",
nullable: false)
.Annotation("Npgsql:TsVectorConfig", "simple")
.Annotation("Npgsql:TsVectorProperties", new[] { "title", "description", "content" });
migrationBuilder.CreateIndex(
name: "ix_posts_search_vector",
table: "posts",
column: "search_vector")
.Annotation("Npgsql:IndexMethod", "GIN");
}
}
}

View File

@@ -10,7 +10,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NodaTime; using NodaTime;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using NpgsqlTypes;
#nullable disable #nullable disable
@@ -531,14 +530,6 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("uuid") .HasColumnType("uuid")
.HasColumnName("replied_post_id"); .HasColumnName("replied_post_id");
b.Property<NpgsqlTsVector>("SearchVector")
.IsRequired()
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("tsvector")
.HasColumnName("search_vector")
.HasAnnotation("Npgsql:TsVectorConfig", "simple")
.HasAnnotation("Npgsql:TsVectorProperties", new[] { "Title", "Description", "Content" });
b.Property<List<ContentSensitiveMark>>("SensitiveMarks") b.Property<List<ContentSensitiveMark>>("SensitiveMarks")
.HasColumnType("jsonb") .HasColumnType("jsonb")
.HasColumnName("sensitive_marks"); .HasColumnName("sensitive_marks");
@@ -589,11 +580,6 @@ namespace DysonNetwork.Sphere.Migrations
b.HasIndex("RepliedPostId") b.HasIndex("RepliedPostId")
.HasDatabaseName("ix_posts_replied_post_id"); .HasDatabaseName("ix_posts_replied_post_id");
b.HasIndex("SearchVector")
.HasDatabaseName("ix_posts_search_vector");
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("SearchVector"), "GIN");
b.ToTable("posts", (string)null); b.ToTable("posts", (string)null);
}); });

View File

@@ -6,7 +6,6 @@ using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto; using DysonNetwork.Shared.Proto;
using DysonNetwork.Shared.Registry; using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere.Poll; using DysonNetwork.Sphere.Poll;
using DysonNetwork.Sphere.WebReader; using DysonNetwork.Sphere.WebReader;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -85,7 +84,6 @@ public class PostController(
[FromQuery(Name = "categories")] List<string>? categories = null, [FromQuery(Name = "categories")] List<string>? categories = null,
[FromQuery(Name = "tags")] List<string>? tags = null, [FromQuery(Name = "tags")] List<string>? tags = null,
[FromQuery(Name = "query")] string? queryTerm = null, [FromQuery(Name = "query")] string? queryTerm = null,
[FromQuery(Name = "vector")] bool queryVector = false,
[FromQuery(Name = "media")] bool onlyMedia = false, [FromQuery(Name = "media")] bool onlyMedia = false,
[FromQuery(Name = "shuffle")] bool shuffle = false, [FromQuery(Name = "shuffle")] bool shuffle = false,
[FromQuery(Name = "replies")] bool? includeReplies = null, [FromQuery(Name = "replies")] bool? includeReplies = null,
@@ -161,9 +159,6 @@ public class PostController(
if (!string.IsNullOrWhiteSpace(queryTerm)) if (!string.IsNullOrWhiteSpace(queryTerm))
{ {
if (queryVector)
query = query.Where(p => p.SearchVector.Matches(EF.Functions.ToTsQuery(queryTerm)));
else
query = query.Where(p => query = query.Where(p =>
(p.Title != null && EF.Functions.ILike(p.Title, $"%{queryTerm}%")) || (p.Title != null && EF.Functions.ILike(p.Title, $"%{queryTerm}%")) ||
(p.Description != null && EF.Functions.ILike(p.Description, $"%{queryTerm}%")) || (p.Description != null && EF.Functions.ILike(p.Description, $"%{queryTerm}%")) ||