SCSearchAgent leaves a unexpected filtered result

When I repeatedly applied filters, a previous filtered result seems to remain after the filter value changed. To demonstrate it, I modified the method SearchInteral in the SCSearchAgent in the mipsdk-samples-plugin as follows:

private void SearchInternal(Guid sessionId, DateTime from, DateTime to, IEnumerable<Item> items,
    bool ascendingSortOrder, CancellationToken cancellationToken)
{
    // This implementation is for demo purposes only: creates dummy search result per camera.
    // Respecting the provided sort order(i.e.delivering results in that order) can help reduce "flickering results" in the results
    // list in Smart Client. Since this sample is based on random trigger times, respecting the sort order does not make much sense.
    // If however you retrieve results from a database or similar, it is very much encouraged to respect the provided sort order.
 
    var totalSpan = (to - from).TotalMilliseconds;
    var ordinal = 0;
    var speciesValue = (StringFilterValue)SearchCriteria.GetFilterValues(SpeciesFilter).FirstOrDefault();
    var activityValue = (BoolFilterValue)SearchCriteria.GetFilterValues(ActivityFilter).FirstOrDefault();
    var rnd = new Random(37);
    if (activityValue != null && activityValue.Value)
    {
        return;
    }
 
    foreach (Item camera in items)
    {
        if (cancellationToken.IsCancellationRequested)
        {
            break;
        }
 
        var triggerTime = totalSpan * rnd.NextDouble();
        const string title = "Animal found!";
        var endTime = from.AddMilliseconds(triggerTime + totalSpan / 5);
        foreach (var ss in
        Enumerable.Range(0, 5000)
            .Select(x =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return Guid.Empty;
                }
 
                var id = GuidUtil.Create(SCAnimalsSearchAgentPlugin.PluginId,
                    title,
                    camera.FQID.ObjectId.ToString(),
                    from.AddMilliseconds(triggerTime).Ticks.ToString(CultureInfo.InvariantCulture),
                    endTime.Ticks.ToString(CultureInfo.InvariantCulture), ordinal.ToString());
                var result = new AnimalsSearchResultData(id)
                {
                    Title = title,
                    Item = camera,
                    RelatedItems = null,
                    BeginTime = from.AddMilliseconds(triggerTime - totalSpan / 10),
                    TriggerTime = from.AddMilliseconds(triggerTime),
                    EndTime = endTime,
                    WarningText = activityValue != null && activityValue.Value && ordinal == 1 ? $"Animal is eating" : "",
                    Species = speciesValue != null ? speciesValue.Text : PickRandomSpecies(rnd),
                    Ordinal = ordinal++,
                };
                FireSearchResultsReadyEvent(sessionId, new[] { result });
                return id;
            })
        ) { }
    }
}

In the above code, when ‘Animals eating’ is filtered, returning no result is intended. However, in runtime, a result remains.

I am attaching a video that shows this behavior.

Hello,

Thank you for letting us know about the issue, and the great demonstration steps. We were able to reproduce it consistently. It’s a bug in MIPSDK, specifically, a race condition when quickly starting and stopping searches. What happens is that the last batch of partial results from one search session sometimes appear in the next search session.

We have created an bug on our backlog, and we expect to release a fix for in one of our future releases.