Server names and admin log full-text search (#6327)

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
Julian Giebel
2022-03-13 18:36:48 +01:00
committed by GitHub
parent bd3fc84488
commit 414d226ec5
13 changed files with 2424 additions and 8 deletions

View File

@@ -1,8 +1,10 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using NpgsqlTypes;
namespace Content.Server.Database
{
@@ -59,6 +61,10 @@ namespace Content.Server.Database
"NOT inet '::ffff:0.0.0.0/96' >>= address");
// ReSharper restore StringLiteralTypo
modelBuilder.Entity<AdminLog>()
.HasIndex(l => l.Message)
.IsTsVectorExpressionIndex("english");
foreach(var entity in modelBuilder.Model.GetEntityTypes())
{
foreach(var property in entity.GetProperties())
@@ -68,5 +74,10 @@ namespace Content.Server.Database
}
}
}
public override IQueryable<AdminLog> SearchLogs(IQueryable<AdminLog> query, string searchText)
{
return query.Where(log => EF.Functions.ToTsVector("english", log.Message).Matches(searchText));
}
}
}