mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Checking possible answers in /ask
This commit is contained in:
parent
799930b3e1
commit
5f12284bb8
4 changed files with 51 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ src/extraModules/
|
|||
duplicateRemovingLog/
|
||||
src/extraModules
|
||||
/*.sh
|
||||
extraSubmodules
|
||||
|
|
|
@ -4,6 +4,12 @@ export interface QuestionData {
|
|||
type: string
|
||||
images?: Array<string>
|
||||
hashedImages?: Array<string>
|
||||
possibleAnswers?:
|
||||
| Array<string>
|
||||
| Array<{
|
||||
text: string
|
||||
selectedByUser: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
export interface Question {
|
||||
|
|
|
@ -39,6 +39,7 @@ const commonUselessAnswerParts = [
|
|||
// const commonUselessStringParts = [',', '\\.', ':', '!', '\\+', '\\s*\\.']
|
||||
/* Percent minus for length difference */
|
||||
const lengthDiffMultiplier = 10
|
||||
const noPossibleAnswerMatchPenalty = 5
|
||||
/* Minimum ammount to consider that two questions match during answering */
|
||||
const minMatchAmmount = 75
|
||||
const magicNumber = 0.7 // same as minMatchAmmount, but /100
|
||||
|
@ -467,7 +468,7 @@ function addQuestion(
|
|||
function prepareQuestion(
|
||||
question: string | Question,
|
||||
data: string | QuestionData
|
||||
): Question {
|
||||
): any {
|
||||
let preparedQuestion: Question
|
||||
|
||||
if (typeof question === 'object') {
|
||||
|
@ -567,6 +568,11 @@ function doSearch(
|
|||
}
|
||||
}
|
||||
|
||||
result = setNoPossibleAnswersPenalties(
|
||||
questionToSearch.possibleAnswers,
|
||||
result
|
||||
)
|
||||
|
||||
result = result.sort((q1, q2) => {
|
||||
if (q1.match < q2.match) {
|
||||
return 1
|
||||
|
@ -580,6 +586,42 @@ function doSearch(
|
|||
return result
|
||||
}
|
||||
|
||||
function setNoPossibleAnswersPenalties(
|
||||
possibleAnswers: any,
|
||||
result: any[]
|
||||
): any {
|
||||
if (!Array.isArray(possibleAnswers)) {
|
||||
return result
|
||||
}
|
||||
const noneHasPossibleAnswers = result.every((x) => {
|
||||
return !Array.isArray(x.q.data.possibleAnswers)
|
||||
})
|
||||
if (noneHasPossibleAnswers) return result
|
||||
|
||||
let possibleAnswerMatch = false
|
||||
const updated = result.map((result) => {
|
||||
const hasMatch = result.q.data.possibleAnswers.some((possibleAnswer) => {
|
||||
return possibleAnswers.some((questionPossibleAnswer) => {
|
||||
return questionPossibleAnswer.includes(questionPossibleAnswer)
|
||||
})
|
||||
})
|
||||
if (hasMatch) {
|
||||
possibleAnswerMatch = true
|
||||
} else {
|
||||
result.match = result.match - noPossibleAnswerMatchPenalty
|
||||
result.detailedMatch.qMatch =
|
||||
result.detailedMatch.qMatch - noPossibleAnswerMatchPenalty
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
if (possibleAnswerMatch) {
|
||||
return updated
|
||||
} else {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
// Multi threaded stuff
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2b491e6bec6eee78400e3e042418def12df3243f
|
||||
Subproject commit 57a7ab9fb7e6148e488cc492a8d8fb55de211bf6
|
Loading…
Add table
Add a link
Reference in a new issue