Skip to content

Commit

Permalink
fix(kb.gbapp): Simple search prioritized correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Mar 31, 2021
1 parent 7046d63 commit 8136e34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
1 change: 0 additions & 1 deletion packages/kb.gbapp/dialogs/AskDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class AskDialog extends IGBDialog {
return step.endDialog();
}


const locale = step.context.activity.locale;

// Stops any content on projector.
Expand Down
43 changes: 17 additions & 26 deletions packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export class KBService implements IGBKBService {
// Extracts questionId from URL.

const id = url.substr(url.lastIndexOf('-') + 1);

// Extracts botId from URL.

let path = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/gi;
const botId = url.replace(path, ($0, $1, $2, $3) => {
return $3.substr($3.indexOf('/'));
Expand Down Expand Up @@ -190,7 +190,7 @@ export class KBService implements IGBKBService {
const service = new CSService();
let question = await service.getQuestionFromAlternateText(instanceId, text);

if (question !== null) {
if (!question) {
question = await GuaribasQuestion.findOne({
where: {
instanceId: instanceId,
Expand Down Expand Up @@ -223,6 +223,15 @@ export class KBService implements IGBKBService {
searchScore: number,
subjects: GuaribasSubject[]
): 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.

query = query.toLowerCase();
Expand All @@ -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') {
const client = new SearchService(instance.searchHost.split('.')[0], instance.searchKey);
const results = await client.indexes
Expand All @@ -267,7 +276,7 @@ export class KBService implements IGBKBService {
GBLog.info(
`SEARCH WILL BE USED with score: ${returnedScore} > required (searchScore): ${searchScore}`
);
notSearched = false;


return { answer: value, questionId: values[0].questionId };
} else {
Expand All @@ -294,24 +303,6 @@ export class KBService implements IGBKBService {
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[]> {
Expand All @@ -333,7 +324,7 @@ export class KBService implements IGBKBService {
// tslint:disable-next-line: no-null-keyword
subject3: null,
// tslint:disable-next-line: no-null-keyword
subject4: null,
subject4: null,
// tslint:disable-next-line: no-null-keyword
instanceId: instanceId
};
Expand Down Expand Up @@ -369,7 +360,7 @@ export class KBService implements IGBKBService {
instanceId: number,
packageId: number
): Promise<GuaribasQuestion[]> {
GBLog.info(`Now reading file ${filePath}...`);
GBLog.info(`Now reading file ${filePath}...`);
const workbook = new Excel.Workbook();
const data = await workbook.xlsx.readFile(filePath);

Expand Down

0 comments on commit 8136e34

Please sign in to comment.