Search till first 100% result only

This commit is contained in:
mrfry 2020-12-23 19:10:55 +01:00
parent f87e165084
commit 8d2bc709f3
2 changed files with 53 additions and 9 deletions

View file

@ -1099,6 +1099,7 @@ function GetApp(): ModuleType {
question: question, question: question,
subjName: subj, subjName: subj,
questionData: recData, questionData: recData,
firstMatchOnly: true, // search till the first match only
}, },
}) })
.then((taskResult) => { .then((taskResult) => {

View file

@ -315,11 +315,16 @@ function questionToString(question: Question) {
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
// Subject // Subject
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
function searchQuestion(subj: Subject, question: Question, subjName: string) { function searchQuestion(
subj: Subject,
question: Question,
subjName: string,
firstMatchOnly?: Boolean
) {
assert(question) assert(question)
let result = [] let result = []
subj.Questions.forEach((currentQuestion) => { subj.Questions.every((currentQuestion) => {
const percent = compareQuestionObj( const percent = compareQuestionObj(
currentQuestion, currentQuestion,
subjName, subjName,
@ -335,6 +340,12 @@ function searchQuestion(subj: Subject, question: Question, subjName: string) {
detailedMatch: percent, detailedMatch: percent,
}) })
} }
if (firstMatchOnly && percent.avg === 100) {
return false
}
return true
}) })
result = result.sort((q1, q2) => { result = result.sort((q1, q2) => {
@ -438,7 +449,8 @@ function doSearch(
data: Array<Subject>, data: Array<Subject>,
subjName: string, subjName: string,
question: Question | string, question: Question | string,
questionData?: QuestionData questionData?: QuestionData,
firstMatchOnly?: Boolean
): any { ): any {
let result = [] let result = []
@ -446,14 +458,26 @@ function doSearch(
assert(questionToSearch.data) assert(questionToSearch.data)
data.forEach((subj) => { data.every((subj) => {
if ( if (
subjName subjName
.toLowerCase() .toLowerCase()
.includes(getSubjNameWithoutYear(subj.Name).toLowerCase()) .includes(getSubjNameWithoutYear(subj.Name).toLowerCase())
) { ) {
logger.DebugLog(`Searching in ${subj.Name} `, 'searchworker', 2) 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', 'searchworker',
1 1
) )
data.forEach((subj) => { data.every((subj) => {
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
}) })
if (result.length > 0) { if (result.length > 0) {
logger.DebugLog( logger.DebugLog(
`FIXME: '${subjName}' gave no result but '' did!`, `FIXME: '${subjName}' gave no result but '' did!`,
@ -505,7 +542,7 @@ if (!isMainThread) {
parentPort.on('message', (msg) => { parentPort.on('message', (msg) => {
if (msg.type === 'work') { if (msg.type === 'work') {
const { subjName, question, questionData } = msg.data const { subjName, question, questionData, firstMatchOnly } = msg.data
const index = msg.index const index = msg.index
const searchIn = msg.data.searchIn const searchIn = msg.data.searchIn
@ -520,7 +557,13 @@ if (!isMainThread) {
try { try {
qdbs.forEach((qdb) => { qdbs.forEach((qdb) => {
if (searchIn === 'all' || searchIn.includes(qdb.index)) { 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] searchResult = [...searchResult, ...res]
} }
}) })