conversation add title keyword query

This commit is contained in:
Gil Zhang 2024-08-22 12:09:53 +08:00
parent 4825a51f80
commit f2e021ffd9
3 changed files with 14 additions and 9 deletions

View file

@ -7,6 +7,7 @@ public class ConversationFilter
/// Conversation Id
/// </summary>
public string? Id { get; set; }
public string? Title { get; set; }
public string? AgentId { get; set; }
public string? Status { get; set; }
public string? Channel { get; set; }

View file

@ -293,6 +293,10 @@ namespace BotSharp.Core.Repository
{
matched = matched && record.Id == filter.Id;
}
if (filter?.Title != null)
{
matched = matched && record.Title.Contains(filter.Title);
}
if (filter?.AgentId != null)
{
matched = matched && record.AgentId == filter.AgentId;

View file

@ -1,9 +1,5 @@
using Amazon.Util.Internal;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Repositories.Filters;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System.Collections.Immutable;
namespace BotSharp.Plugin.MongoStorage.Repository;
@ -66,7 +62,7 @@ public partial class MongoRepository
var statesDeleted = _dc.ConversationStates.DeleteMany(filterSates);
var dialogDeleted = _dc.ConversationDialogs.DeleteMany(filterDialog);
var convDeleted = _dc.Conversations.DeleteMany(filterConv);
return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0 || statesDeleted.DeletedCount > 0
|| exeLogDeleted.DeletedCount > 0 || promptLogDeleted.DeletedCount > 0
|| contentLogDeleted.DeletedCount > 0 || stateLogDeleted.DeletedCount > 0;
@ -237,6 +233,10 @@ public partial class MongoRepository
{
convFilters.Add(convBuilder.Eq(x => x.Id, filter.Id));
}
if (!string.IsNullOrEmpty(filter?.Title))
{
convFilters.Add(convBuilder.Regex(x => x.Title, new BsonRegularExpression(filter.Title, "i")));
}
if (!string.IsNullOrEmpty(filter?.AgentId))
{
convFilters.Add(convBuilder.Eq(x => x.AgentId, filter.AgentId));
@ -380,7 +380,7 @@ public partial class MongoRepository
{
break;
}
conversationIds = conversationIds.Concat(candidates).Distinct().ToList();
if (conversationIds.Count >= batchSize)
{
@ -419,7 +419,7 @@ public partial class MongoRepository
// Handle truncated dialogs
var truncatedDialogs = foundDialog.Dialogs.Where((x, idx) => idx < foundIdx).ToList();
// Handle truncated states
var refTime = foundDialog.Dialogs.ElementAt(foundIdx).MetaData.CreateTime;
var stateFilter = Builders<ConversationStateDocument>.Filter.Eq(x => x.ConversationId, conversationId);
@ -457,7 +457,7 @@ public partial class MongoRepository
var truncatedBreakpoints = breakpoints.Where(x => x.CreatedTime < refTime).ToList();
foundStates.Breakpoints = truncatedBreakpoints;
}
// Update
_dc.ConversationStates.ReplaceOne(stateFilter, foundStates);
}
@ -492,7 +492,7 @@ public partial class MongoRepository
_dc.ContentLogs.DeleteMany(contentLogBuilder.And(contentLogFilters));
_dc.StateLogs.DeleteMany(stateLogBuilder.And(stateLogFilters));
}
return deletedMessageIds;
}