mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Search till first 100% result only
This commit is contained in:
parent
f87e165084
commit
8d2bc709f3
2 changed files with 53 additions and 9 deletions
|
@ -1099,6 +1099,7 @@ function GetApp(): ModuleType {
|
|||
question: question,
|
||||
subjName: subj,
|
||||
questionData: recData,
|
||||
firstMatchOnly: true, // search till the first match only
|
||||
},
|
||||
})
|
||||
.then((taskResult) => {
|
||||
|
|
|
@ -315,11 +315,16 @@ function questionToString(question: Question) {
|
|||
// ---------------------------------------------------------------------------------------------------------
|
||||
// Subject
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
function searchQuestion(subj: Subject, question: Question, subjName: string) {
|
||||
function searchQuestion(
|
||||
subj: Subject,
|
||||
question: Question,
|
||||
subjName: string,
|
||||
firstMatchOnly?: Boolean
|
||||
) {
|
||||
assert(question)
|
||||
|
||||
let result = []
|
||||
subj.Questions.forEach((currentQuestion) => {
|
||||
subj.Questions.every((currentQuestion) => {
|
||||
const percent = compareQuestionObj(
|
||||
currentQuestion,
|
||||
subjName,
|
||||
|
@ -335,6 +340,12 @@ function searchQuestion(subj: Subject, question: Question, subjName: string) {
|
|||
detailedMatch: percent,
|
||||
})
|
||||
}
|
||||
|
||||
if (firstMatchOnly && percent.avg === 100) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
result = result.sort((q1, q2) => {
|
||||
|
@ -438,7 +449,8 @@ function doSearch(
|
|||
data: Array<Subject>,
|
||||
subjName: string,
|
||||
question: Question | string,
|
||||
questionData?: QuestionData
|
||||
questionData?: QuestionData,
|
||||
firstMatchOnly?: Boolean
|
||||
): any {
|
||||
let result = []
|
||||
|
||||
|
@ -446,14 +458,26 @@ function doSearch(
|
|||
|
||||
assert(questionToSearch.data)
|
||||
|
||||
data.forEach((subj) => {
|
||||
data.every((subj) => {
|
||||
if (
|
||||
subjName
|
||||
.toLowerCase()
|
||||
.includes(getSubjNameWithoutYear(subj.Name).toLowerCase())
|
||||
) {
|
||||
logger.DebugLog(`Searching in ${subj.Name} `, 'searchworker', 2)
|
||||
result = result.concat(searchQuestion(subj, questionToSearch, subjName))
|
||||
const subjRes = searchQuestion(
|
||||
subj,
|
||||
questionToSearch,
|
||||
subjName,
|
||||
firstMatchOnly
|
||||
)
|
||||
result = result.concat(subjRes)
|
||||
if (firstMatchOnly) {
|
||||
return subjRes.every((sr) => {
|
||||
return sr.match < 100
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -469,9 +493,22 @@ function doSearch(
|
|||
'searchworker',
|
||||
1
|
||||
)
|
||||
data.forEach((subj) => {
|
||||
result = result.concat(searchQuestion(subj, questionToSearch, subjName))
|
||||
data.every((subj) => {
|
||||
const subjRes = searchQuestion(
|
||||
subj,
|
||||
questionToSearch,
|
||||
subjName,
|
||||
firstMatchOnly
|
||||
)
|
||||
result = result.concat(subjRes)
|
||||
if (firstMatchOnly) {
|
||||
return subjRes.every((sr) => {
|
||||
return sr.match < 100
|
||||
})
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if (result.length > 0) {
|
||||
logger.DebugLog(
|
||||
`FIXME: '${subjName}' gave no result but '' did!`,
|
||||
|
@ -505,7 +542,7 @@ if (!isMainThread) {
|
|||
|
||||
parentPort.on('message', (msg) => {
|
||||
if (msg.type === 'work') {
|
||||
const { subjName, question, questionData } = msg.data
|
||||
const { subjName, question, questionData, firstMatchOnly } = msg.data
|
||||
const index = msg.index
|
||||
const searchIn = msg.data.searchIn
|
||||
|
||||
|
@ -520,7 +557,13 @@ if (!isMainThread) {
|
|||
try {
|
||||
qdbs.forEach((qdb) => {
|
||||
if (searchIn === 'all' || searchIn.includes(qdb.index)) {
|
||||
const res = doSearch(qdb.data, subjName, question, questionData)
|
||||
const res = doSearch(
|
||||
qdb.data,
|
||||
subjName,
|
||||
question,
|
||||
questionData,
|
||||
firstMatchOnly
|
||||
)
|
||||
searchResult = [...searchResult, ...res]
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue