Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DERCBOT-1385] Do not retrieve “Inboxed” phrases with FAQ questions. #1835

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.bson.conversions.Bson
import org.litote.kmongo.Id
import org.litote.kmongo.MongoOperator.and
import org.litote.kmongo.MongoOperator.eq
import org.litote.kmongo.MongoOperator.ne
import org.litote.kmongo.MongoOperator.`in`
import org.litote.kmongo.aggregate
import org.litote.kmongo.and
import org.litote.kmongo.ascending
Expand Down Expand Up @@ -298,7 +298,7 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
// join FaqDefinition with IntentDefinition
joinOnIntentDefinition(),
// join FaqDefinition with ClassifiedSentence
joinOnClassifiedSentenceStatusNotDeleted(applicationDefinition._id),
joinOnClassifiedSentenceStatus(applicationDefinition._id),
// unwind : to flat faq array into an object
FaqQueryResult::faq.unwind(),
match(
Expand Down Expand Up @@ -459,9 +459,10 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
)

/**
* Perform a lookup join from the FaqDefinition.intentId on ClassifiedSentence.classification.intentId and avoid returning deleted sentences
* Perform a lookup join from the FaqDefinition.intentId on ClassifiedSentence.classification.intentId,
* while ClassifiedSentence::status is 'validated' or 'in model'
*/
private fun FaqQuery.joinOnClassifiedSentenceStatusNotDeleted(applicationId: Id<ApplicationDefinition>) =
private fun FaqQuery.joinOnClassifiedSentenceStatus(applicationId: Id<ApplicationDefinition>) =
//inspired from https://github.com/Litote/kmongo/blob/master/kmongo-core-tests/src/main/kotlin/org/litote/kmongo/AggregateTypedTest.kt#L322
lookup(
CLASSIFIED_SENTENCE_COLLECTION,
Expand All @@ -479,13 +480,12 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
ClassifiedSentence::classification / Classification::intentId,
"\$\$$FAQ_INTENTID"
),
//filter on current applicationId
// filter on current applicationId
eq from listOf(ClassifiedSentence::applicationId, applicationId),
// do not take classified sentences with deleted status because of the BuildWorker scheduled delay (1 second)
// needed to check and erase the ones with deleted status each
ne from listOf(
// filter on classified sentence
`in` from listOf(
ClassifiedSentence::status,
ClassifiedSentenceStatus.deleted
listOf(ClassifiedSentenceStatus.validated, ClassifiedSentenceStatus.model)
)
),
)
Expand Down