Skip to content

Commit

Permalink
[DERCBOT-1250] FAQ by namespace (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
assouktim authored Nov 19, 2024
1 parent 3d8ae57 commit d390019
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bot/admin/server/src/main/kotlin/BotAdminVerticle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ open class BotAdminVerticle : AdminVerticle() {
val applicationDefinition = front.getApplicationById(applicationId.toId())
if (context.organization == applicationDefinition?.namespace) {
try {
FaqAdminService.searchTags(applicationDefinition._id.toString())
FaqAdminService.searchTags(applicationDefinition.name, context.organization)
} catch (t: Exception) {
logger.error(t)
badRequest("Error searching faq tags: ${t.message}")
Expand Down
11 changes: 7 additions & 4 deletions bot/admin/server/src/main/kotlin/FaqAdminService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object FaqAdminService {
createOrUpdateUtterances(query, application, intent._id, userLogin)

val existingFaqInCurrentApplication =
faqDefinitionDAO.getFaqDefinitionByIntentIdAndBotId(intent._id, query.applicationName)
faqDefinitionDAO.getFaqDefinitionByIntentIdAndBotIdAndNamespace(intent._id, application.name, application.namespace)

val i18nLabel: I18nLabel = manageI18nLabelUpdate(query, application.namespace, existingFaqInCurrentApplication)

Expand Down Expand Up @@ -242,7 +242,10 @@ object FaqAdminService {
applicationDefinition: ApplicationDefinition, faqSettings: FaqSettings
) {

val listFaq = faqDefinitionDAO.getFaqDefinitionByBotId(applicationDefinition.name)
val listFaq = faqDefinitionDAO.getFaqDefinitionByBotIdAndNamespace(
applicationDefinition.name,
applicationDefinition.namespace
)

listFaq.forEach {
val currentIntent = it.intentId.let {
Expand Down Expand Up @@ -438,8 +441,8 @@ object FaqAdminService {
return Pair(notYetPresentSentences.toList(), noMorePresentSentences.toList())
}

fun searchTags(applicationId: String): List<String> {
return faqDefinitionDAO.getTags(applicationId)
fun searchTags(botId: String, namespace: String): List<String> {
return faqDefinitionDAO.getTags(botId, namespace)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ object ApplicationConfigurationService :
ConfigurationRepository.entityTypeByName(name)?.obfuscated ?: true

override fun getFaqsDefinitionByApplicationId(id: Id<ApplicationDefinition>): List<FaqDefinition> =
getApplicationById(id)?.let { faqDefinitionDAO.getFaqDefinitionByBotId(it.name) } ?: arrayListOf()
getApplicationById(id)?.let { faqDefinitionDAO.getFaqDefinitionByBotIdAndNamespace(it.name, it.namespace) } ?: arrayListOf()

override fun getFaqDefinitionByIntentId(id: Id<IntentDefinition>): FaqDefinition? =
faqDefinitionDAO.getFaqDefinitionByIntentId(id)
Expand Down
10 changes: 6 additions & 4 deletions nlp/front/service/src/main/kotlin/storage/FaqDefinitionDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ interface FaqDefinitionDAO {

/**
* Retrieve faqDefinition by filtering on the application name [id][ApplicationDefinition]
* @param id the application name
* @param botId the application name
* @param namespace the namespace
*/
fun getFaqDefinitionByBotId(id: String): List<FaqDefinition>
fun getFaqDefinitionByBotIdAndNamespace(botId: String, namespace: String): List<FaqDefinition>

fun listenFaqDefinitionChanges(listener: () -> Unit)

Expand All @@ -60,8 +61,9 @@ interface FaqDefinitionDAO {
* Retrieve faqDefinition by filtering on intent id [intentId][IntentDefinition] and the application name[botId][ApplicationDefinition]
* @param intentId intent id
* @param botId the application name
* @param namespace the namespace
*/
fun getFaqDefinitionByIntentIdAndBotId(intentId: Id<IntentDefinition>, botId: String): FaqDefinition?
fun getFaqDefinitionByIntentIdAndBotIdAndNamespace(intentId: Id<IntentDefinition>, botId: String, namespace: String): FaqDefinition?

/**
* Retrieve faq details with total count numbers according to the filter present un [FaqQuery]
Expand All @@ -75,7 +77,7 @@ interface FaqDefinitionDAO {
i18nIds: List<Id<I18nLabel>>? = null
): Pair<List<FaqQueryResult>, Long>

fun getTags(botId: String): List<String>
fun getTags(botId: String, namespace: String): List<String>

/**
* Make migration
Expand Down
32 changes: 21 additions & 11 deletions nlp/front/storage-mongo/src/main/kotlin/FaqDefinitionMongoDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
return col.findOneById(id)
}

override fun getFaqDefinitionByBotId(id: String): List<FaqDefinition> {
return col.find(FaqDefinition::botId eq id).into(ArrayList())
override fun getFaqDefinitionByBotIdAndNamespace(botId: String, namespace: String): List<FaqDefinition> {
return col.find(
and(
FaqDefinition::botId eq botId,
FaqDefinition::namespace eq namespace
)
).into(ArrayList())
}

override fun getFaqDefinitionByIntentId(id: Id<IntentDefinition>): FaqDefinition? {
Expand All @@ -140,8 +145,12 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
return col.find(FaqDefinition::i18nId `in` ids).into(ArrayList())
}

override fun getFaqDefinitionByIntentIdAndBotId(intentId: Id<IntentDefinition>, botId: String): FaqDefinition? {
return col.findOne(FaqDefinition::intentId eq intentId, FaqDefinition::botId eq botId)
override fun getFaqDefinitionByIntentIdAndBotIdAndNamespace(intentId: Id<IntentDefinition>, botId: String, namespace: String): FaqDefinition? {
return col.findOne(
FaqDefinition::intentId eq intentId,
FaqDefinition::namespace eq namespace,
FaqDefinition::botId eq botId
)
}

override fun save(faqDefinition: FaqDefinition) {
Expand Down Expand Up @@ -194,14 +203,15 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
/**
* Retrieve tags according to the applicationId present in IntentDefinition with aggregation
* @param botId : the botId
* @param namespace: the namespace
* @return a string list of tags
*/
override fun getTags(botId: String): List<String> {
override fun getTags(botId: String, namespace: String): List<String> {
return col.aggregate<FaqDefinitionTag>(
joinOnIntentDefinition(),
match(
andNotNull(
filterOnBotId(botId)
filterOnNamespaceAndBotId(botId, namespace)
)
),
// unwind : to flat tags array into an object
Expand Down Expand Up @@ -300,7 +310,7 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
filterI18nIds(i18nIds)
),
andNotNull(
filterOnBotId(applicationDefinition.name),
filterOnNamespaceAndBotId(applicationDefinition.name, applicationDefinition.namespace),
filterTags(),
filterEnabled(),
)
Expand Down Expand Up @@ -336,7 +346,7 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
match(
andNotNull(
andNotNull(
filterOnBotId(applicationDefinition.name),
filterOnNamespaceAndBotId(applicationDefinition.name, applicationDefinition.namespace),
filterTags(),
filterEnabled(),
filterCurrentApplicationClassifiedSentence(applicationDefinition._id),
Expand Down Expand Up @@ -402,10 +412,10 @@ object FaqDefinitionMongoDAO : FaqDefinitionDAO {
private fun FaqQuery.filterEnabled(): Bson? = if (enabled == null) null else FaqQueryResult::enabled eq enabled

/**
* Filter on the botId
* Filter on the botId and the namespace
*/
private fun filterOnBotId(botId: String): Bson =
FaqDefinition::botId eq botId
private fun filterOnNamespaceAndBotId(botId: String, namespace: String): Bson =
and(FaqDefinition::botId eq botId, FaqDefinition::namespace eq namespace)

/**
* Group aggregation pipeline to recompose and group data after multiple unwind especially due to utterances unwind
Expand Down

0 comments on commit d390019

Please sign in to comment.