Skip to content

Commit 6612ed6

Browse files
authored
Merge pull request #1969 from CreditMutuelArkea/fix/DERCBOT-1676_fix_search_inconsistency
[DERCBOT-1676] Fix dialog date filters and add comprehensive tests
2 parents 9d26392 + 714da49 commit 6612ed6

File tree

9 files changed

+363
-36
lines changed

9 files changed

+363
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ environment.dev.ts
1818
*.launch
1919
.settings/
2020
*.sublime-workspace
21+
.cursor/*
2122

2223
# IDE - VSCode
2324
.vscode/*

bot/admin/server/src/main/kotlin/model/DialogsSearchQuery.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ data class DialogsSearchQuery(
4949
val dialogSort: SortDirection? = null,
5050
val annotationCreationDateFrom: ZonedDateTime? = null,
5151
val annotationCreationDateTo: ZonedDateTime? = null,
52-
val dialogCreationDateFrom: ZonedDateTime? = null,
53-
val dialogCreationDateTo: ZonedDateTime? = null,
5452
val feedback: FeedbackVote? = null,
53+
val dialogActivityFrom: ZonedDateTime? = null,
54+
val dialogActivityTo: ZonedDateTime? = null,
5555
) : PaginatedQuery() {
5656
fun toDialogReportQuery(): DialogReportQuery {
5757
return DialogReportQuery(
@@ -79,9 +79,9 @@ data class DialogsSearchQuery(
7979
dialogSort = dialogSort,
8080
annotationCreationDateFrom = annotationCreationDateFrom,
8181
annotationCreationDateTo = annotationCreationDateTo,
82-
dialogCreationDateFrom = dialogCreationDateFrom,
83-
dialogCreationDateTo = dialogCreationDateTo,
8482
feedback = feedback,
83+
dialogActivityFrom = dialogActivityFrom,
84+
dialogActivityTo = dialogActivityTo,
8585
)
8686
}
8787
}

bot/admin/web/src/app/analytics/dialogs/dialogs-list/dialogs-list-filters/dialogs-list-filters.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@
111111
placeholder="Data collected after"
112112
nbTooltip="Show dialogs containing messages created after this date"
113113
[nbDatepicker]="from_date"
114-
formControlName="dialogCreationDateFrom"
114+
formControlName="dialogActivityFrom"
115115
/>
116116
<button
117-
*ngIf="!!getFormControl('dialogCreationDateFrom').value"
117+
*ngIf="!!getFormControl('dialogActivityFrom').value"
118118
nbButton
119119
nbSuffix
120120
ghost
121121
nbTooltip="Clear"
122122
type="button"
123-
(click)="resetControl(getFormControl('dialogCreationDateFrom'))"
123+
(click)="resetControl(getFormControl('dialogActivityFrom'))"
124124
>
125125
<nb-icon icon="x"></nb-icon>
126126
</button>
@@ -148,16 +148,16 @@
148148
placeholder="Data collected before"
149149
nbTooltip="Show dialogs containing messages created before this date"
150150
[nbDatepicker]="to_date"
151-
formControlName="dialogCreationDateTo"
151+
formControlName="dialogActivityTo"
152152
/>
153153
<button
154-
*ngIf="!!getFormControl('dialogCreationDateTo').value"
154+
*ngIf="!!getFormControl('dialogActivityTo').value"
155155
nbButton
156156
nbSuffix
157157
ghost
158158
nbTooltip="Clear"
159159
type="button"
160-
(click)="resetControl(getFormControl('dialogCreationDateTo'))"
160+
(click)="resetControl(getFormControl('dialogActivityTo'))"
161161
>
162162
<nb-icon icon="x"></nb-icon>
163163
</button>

bot/admin/web/src/app/analytics/dialogs/dialogs-list/dialogs-list-filters/dialogs-list-filters.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ interface DialogListFiltersForm {
4949
intentsToHide?: FormControl<string[]>;
5050
isGenAiRagDialog?: FormControl<boolean>;
5151
dialogSort?: FormControl<SortOrder>;
52-
dialogCreationDateFrom?: FormControl<Date>;
53-
dialogCreationDateTo?: FormControl<Date>;
52+
dialogActivityFrom?: FormControl<Date>;
53+
dialogActivityTo?: FormControl<Date>;
5454
withAnnotations?: FormControl<boolean>;
5555
annotationStates?: FormControl<AnnotationState[]>;
5656
annotationReasons?: FormControl<AnnotationReason[]>;
@@ -126,8 +126,8 @@ export class DialogsListFiltersComponent implements OnInit {
126126
intentsToHide: new FormControl([]),
127127
isGenAiRagDialog: new FormControl(),
128128
dialogSort: new FormControl(),
129-
dialogCreationDateFrom: new FormControl(),
130-
dialogCreationDateTo: new FormControl(),
129+
dialogActivityFrom: new FormControl(),
130+
dialogActivityTo: new FormControl(),
131131
withAnnotations: new FormControl(),
132132
annotationStates: new FormControl([]),
133133
annotationReasons: new FormControl([]),

bot/admin/web/src/app/analytics/dialogs/dialogs-list/dialogs-list.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ export class DialogsListComponent implements OnInit, OnChanges, OnDestroy {
149149
this.filters.intentsToHide,
150150
this.filters.isGenAiRagDialog,
151151
this.filters.dialogSort,
152-
this.filters.dialogCreationDateFrom,
153-
this.filters.dialogCreationDateTo,
152+
this.filters.dialogActivityFrom,
153+
this.filters.dialogActivityTo,
154154
this.filters.withAnnotations,
155155
this.filters.annotationStates,
156156
this.filters.annotationReasons,

bot/admin/web/src/app/analytics/dialogs/dialogs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export class DialogReportQuery extends PaginatedQuery {
4343
public intentsToHide?: string[],
4444
public isGenAiRagDialog?: boolean,
4545
public dialogSort?: SortOrder,
46-
public dialogCreationDateFrom?: Date,
47-
public dialogCreationDateTo?: Date,
46+
public dialogActivityFrom?: Date,
47+
public dialogActivityTo?: Date,
4848
public withAnnotations?: boolean,
4949
public annotationStates?: AnnotationState[],
5050
public annotationReasons?: AnnotationReason[],

bot/engine/src/main/kotlin/admin/dialog/DialogReportQuery.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ data class DialogReportQuery(
3939
val dialogId: String? = null,
4040
val intentName: String? = null,
4141
val exactMatch: Boolean = false,
42-
val from: ZonedDateTime? = null,
43-
val to: ZonedDateTime? = null,
4442
val connectorType: ConnectorType? = null,
4543
/**
4644
* Display test dialogs.
@@ -68,7 +66,15 @@ data class DialogReportQuery(
6866
val dialogSort: SortDirection? = null,
6967
val annotationCreationDateFrom: ZonedDateTime? = null,
7068
val annotationCreationDateTo: ZonedDateTime? = null,
71-
val dialogCreationDateFrom: ZonedDateTime? = null,
72-
val dialogCreationDateTo: ZonedDateTime? = null,
7369
val feedback: FeedbackVote? = null,
70+
/**
71+
* Filter dialogs that had activity during the specified period.
72+
* A dialog is included if:
73+
* - At least one action exists with date >= dialogActivityFrom (if set)
74+
* - At least one action exists with date <= dialogActivityTo (if set)
75+
* Note: These conditions can be satisfied by different actions.
76+
* Both bounds are inclusive.
77+
*/
78+
val dialogActivityFrom: ZonedDateTime? = null,
79+
val dialogActivityTo: ZonedDateTime? = null,
7480
)

bot/storage-mongo/src/main/kotlin/UserTimelineMongoDAO.kt

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ import org.litote.kmongo.eq
112112
import org.litote.kmongo.from
113113
import org.litote.kmongo.group
114114
import org.litote.kmongo.gt
115+
import org.litote.kmongo.gte
115116
import org.litote.kmongo.`in`
116117
import org.litote.kmongo.json
117118
import org.litote.kmongo.limit
118119
import org.litote.kmongo.lt
120+
import org.litote.kmongo.lte
119121
import org.litote.kmongo.match
120122
import org.litote.kmongo.not
121123
import org.litote.kmongo.orderBy
@@ -737,8 +739,6 @@ internal object UserTimelineMongoDAO : UserTimelineDAO, UserReportDAO, DialogRep
737739
if (query.playerId != null || query.displayTests) null else Test eq false,
738740
if (query.playerId == null) null else PlayerIds.id eq query.playerId!!.id,
739741
if (dialogIds.isEmpty()) null else _id `in` dialogIds,
740-
if (from == null) null else DialogCol_.LastUpdateDate gt from?.toInstant(),
741-
if (to == null) null else DialogCol_.LastUpdateDate lt to?.toInstant(),
742742
if (connectorType == null) null else Stories.actions.state.targetConnectorType.id eq connectorType!!.id,
743743
if (query.intentName.isNullOrBlank()) null else Stories.currentIntent.name_ eq query.intentName,
744744
if (query.ratings.isNotEmpty()) DialogCol_.Rating `in` query.ratings.toSet() else null,
@@ -758,23 +758,17 @@ internal object UserTimelineMongoDAO : UserTimelineDAO, UserReportDAO, DialogRep
758758
if (annotationCreationDateFrom == null) {
759759
null
760760
} else {
761-
Stories.actions.annotation.creationDate gt annotationCreationDateFrom?.toInstant()
761+
Stories.actions.annotation.creationDate gte annotationCreationDateFrom?.toInstant()
762762
},
763763
if (annotationCreationDateTo == null) {
764764
null
765765
} else {
766-
Stories.actions.annotation.creationDate lt annotationCreationDateTo?.toInstant()
767-
},
768-
if (dialogCreationDateFrom == null) {
769-
null
770-
} else {
771-
Stories.actions.date gt dialogCreationDateFrom?.toInstant()
772-
},
773-
if (dialogCreationDateTo == null) {
774-
null
775-
} else {
776-
Stories.actions.date lt dialogCreationDateTo?.toInstant()
766+
Stories.actions.annotation.creationDate lte annotationCreationDateTo?.toInstant()
777767
},
768+
buildDialogActivityFilter(
769+
query.dialogActivityFrom,
770+
query.dialogActivityTo,
771+
),
778772
)
779773
logger.debug { "dialog search query: $filter" }
780774
val c = dialogCol.withReadPreference(secondaryPreferred())
@@ -1204,6 +1198,32 @@ internal object UserTimelineMongoDAO : UserTimelineDAO, UserReportDAO, DialogRep
12041198
toDate?.let { filters += lte("stories.actions.date", it.toInstant()) }
12051199
}
12061200

1201+
/**
1202+
* Builds a filter for dialogs that had activity during the specified period.
1203+
*
1204+
* A dialog is included if:
1205+
* - At least one action exists with date >= activityFrom (if set)
1206+
* - At least one action exists with date <= activityTo (if set)
1207+
*
1208+
* Note: These conditions can be satisfied by different actions.
1209+
* Both bounds are inclusive.
1210+
*
1211+
* @param activityFrom optional start date filter (inclusive)
1212+
* @param activityTo optional end date filter (inclusive)
1213+
* @return Bson filter expression, or null if both dates are null
1214+
*/
1215+
private fun buildDialogActivityFilter(
1216+
activityFrom: ZonedDateTime?,
1217+
activityTo: ZonedDateTime?,
1218+
): Bson? {
1219+
val conditions =
1220+
listOfNotNull(
1221+
activityFrom?.let { Stories.actions.date gte it.toInstant() },
1222+
activityTo?.let { Stories.actions.date lte it.toInstant() },
1223+
)
1224+
return if (conditions.isEmpty()) null else and(conditions)
1225+
}
1226+
12071227
/**
12081228
* Calculates dialog statistics for a given [DialogStatsQuery].
12091229
*

0 commit comments

Comments
 (0)