Updated
This commit is contained in:
30
EonaCat.Logger.LogServer/Services/ISearchService.cs
Normal file
30
EonaCat.Logger.LogServer/Services/ISearchService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using LogCentral.Server.Data;
|
||||
using LogCentral.Server.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LogCentral.Server.Services;
|
||||
|
||||
public interface ISearchService
|
||||
{
|
||||
Task<List<LogEntry>> SearchAsync(string query, int limit = 100);
|
||||
}
|
||||
|
||||
public class SearchService : ISearchService
|
||||
{
|
||||
private readonly LogCentralDbContext _context;
|
||||
|
||||
public SearchService(LogCentralDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<List<LogEntry>> SearchAsync(string query, int limit = 100)
|
||||
{
|
||||
return await _context.LogEntries
|
||||
.Where(l => EF.Functions.Like(l.Message, $"%{query}%") ||
|
||||
EF.Functions.Like(l.Exception ?? "", $"%{query}%"))
|
||||
.OrderByDescending(l => l.Timestamp)
|
||||
.Take(limit)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user