fix(kb.gbapp): Simple search prioritized correctly.

This commit is contained in:
Rodrigo Rodriguez 2021-03-31 08:40:51 -03:00
parent 7046d63457
commit 8136e34f1e
2 changed files with 17 additions and 27 deletions

View file

@ -165,7 +165,6 @@ export class AskDialog extends IGBDialog {
return step.endDialog(); return step.endDialog();
} }
const locale = step.context.activity.locale; const locale = step.context.activity.locale;
// Stops any content on projector. // Stops any content on projector.

View file

@ -145,9 +145,9 @@ export class KBService implements IGBKBService {
// Extracts questionId from URL. // Extracts questionId from URL.
const id = url.substr(url.lastIndexOf('-') + 1); const id = url.substr(url.lastIndexOf('-') + 1);
// Extracts botId from URL. // Extracts botId from URL.
let path = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi; let path = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi;
const botId = url.replace(path, ($0, $1, $2, $3) => { const botId = url.replace(path, ($0, $1, $2, $3) => {
return $3.substr($3.indexOf('/')); return $3.substr($3.indexOf('/'));
@ -190,7 +190,7 @@ export class KBService implements IGBKBService {
const service = new CSService(); const service = new CSService();
let question = await service.getQuestionFromAlternateText(instanceId, text); let question = await service.getQuestionFromAlternateText(instanceId, text);
if (question !== null) { if (!question) {
question = await GuaribasQuestion.findOne({ question = await GuaribasQuestion.findOne({
where: { where: {
instanceId: instanceId, instanceId: instanceId,
@ -223,6 +223,15 @@ export class KBService implements IGBKBService {
searchScore: number, searchScore: number,
subjects: GuaribasSubject[] subjects: GuaribasSubject[]
): Promise<KBServiceSearchResults> { ): Promise<KBServiceSearchResults> {
// Try simple search first.
const data = await this.getAnswerByText(instance.instanceId, query);
if (data) {
GBLog.info(`Simple SEARCH called.`);
return { answer: data.answer, questionId: data.question.questionId };
}
// Builds search query. // Builds search query.
query = query.toLowerCase(); query = query.toLowerCase();
@ -240,9 +249,9 @@ export class KBService implements IGBKBService {
} }
} }
let notSearched = true;
// tslint:disable:no-unsafe-any // No direct match found, so Search is used.
if (instance.searchKey !== null && GBConfigService.get('STORAGE_DIALECT') === 'mssql') { if (instance.searchKey !== null && GBConfigService.get('STORAGE_DIALECT') === 'mssql') {
const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey); const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey);
const results = await client.indexes const results = await client.indexes
@ -267,7 +276,7 @@ export class KBService implements IGBKBService {
GBLog.info( GBLog.info(
`SEARCH WILL BE USED with score: ${returnedScore} > required (searchScore): ${searchScore}` `SEARCH WILL BE USED with score: ${returnedScore} > required (searchScore): ${searchScore}`
); );
notSearched = false;
return { answer: value, questionId: values[0].questionId }; return { answer: value, questionId: values[0].questionId };
} else { } else {
@ -294,24 +303,6 @@ export class KBService implements IGBKBService {
return { answer: undefined, questionId: 0 }; return { answer: undefined, questionId: 0 };
} }
} }
// DISABLED: Searches via Database "WHERE" command.
// if (notSearched) {
// const data = await this.getAnswerByText(instance.instanceId, query);
// if (data) {
// GBLog.info(
// `SEARCH called.`
// );
// return { answer: data.answer, questionId: data.question.questionId };
// } else {
// GBLog.info(`SEARCH NOT called getAnswerByText not found answers in database.`);
// return { answer: undefined, questionId: 0 };
// }
// }
// TODO: Add more sources....
} }
public async getSubjectItems(instanceId: number, parentId: number): Promise<GuaribasSubject[]> { public async getSubjectItems(instanceId: number, parentId: number): Promise<GuaribasSubject[]> {
@ -333,7 +324,7 @@ export class KBService implements IGBKBService {
// tslint:disable-next-line: no-null-keyword // tslint:disable-next-line: no-null-keyword
subject3: null, subject3: null,
// tslint:disable-next-line: no-null-keyword // tslint:disable-next-line: no-null-keyword
subject4: null, subject4: null,
// tslint:disable-next-line: no-null-keyword // tslint:disable-next-line: no-null-keyword
instanceId: instanceId instanceId: instanceId
}; };
@ -369,7 +360,7 @@ export class KBService implements IGBKBService {
instanceId: number, instanceId: number,
packageId: number packageId: number
): Promise<GuaribasQuestion[]> { ): Promise<GuaribasQuestion[]> {
GBLog.info(`Now reading file ${filePath}...`); GBLog.info(`Now reading file ${filePath}...`);
const workbook = new Excel.Workbook(); const workbook = new Excel.Workbook();
const data = await workbook.xlsx.readFile(filePath); const data = await workbook.xlsx.readFile(filePath);