Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/db/highlight-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function highlightTossupQuery ({ tossup, regExp, searchType = 'all', igno
tossup.question = insertHighlightTokensHelper(tossup.question, tossup.question_sanitized, word);
}

if (searchType === 'answer' || searchType === 'all') {
if (searchType === 'answer' || searchType === 'exactAnswer' || searchType === 'all') {
tossup.answer = insertHighlightTokensHelper(tossup.answer, tossup.answer_sanitized, word);
}
}
Expand All @@ -31,7 +31,7 @@ export function highlightBonusQuery ({ bonus, regExp, searchType = 'all', ignore
}
}

if (searchType === 'answer' || searchType === 'all') {
if (searchType === 'answer' || searchType === 'exactAnswer' || searchType === 'all') {
for (let i = 0; i < bonus.answers.length; i++) {
bonus.answers[i] = insertHighlightTokensHelper(bonus.answers[i], bonus.answers_sanitized[i], word);
}
Expand Down
1 change: 1 addition & 0 deletions client/db/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function QueryForm () {
<option value='all'>All text</option>
<option value='question'>Question</option>
<option value='answer'>Answer</option>
<option value='exactAnswer'>Exact answer</option>
</select>
</div>
<div className='col-6 col-md-3 mb-2'>
Expand Down
10 changes: 9 additions & 1 deletion database/qbreader/get-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function validateOptions ({

if (!searchType) {
searchType = 'all';
} else if (!['question', 'answer', 'all'].includes(searchType)) {
} else if (!['question', 'answer', 'exactAnswer', 'all'].includes(searchType)) {
throw new Error('Invalid search type specified.');
}

Expand Down Expand Up @@ -184,6 +184,10 @@ async function getTossupQuery (options) {
orQuery.push({ answer_sanitized: { $regex: word, $options: caseSensitive ? '' : 'i' } });
}

if (searchType === 'exactAnswer') {
orQuery.push({ answer_sanitized: { $regex: `^${word}`, $options: caseSensitive ? '' : 'i' } });
}

andQuery.push({ $or: orQuery });
}

Expand Down Expand Up @@ -225,6 +229,10 @@ async function getBonusQuery (options) {
orQuery.push({ answers_sanitized: { $regex: word, $options: caseSensitive ? '' : 'i' } });
}

if (searchType === 'exactAnswer') {
orQuery.push({ answers_sanitized: { $regex: `^${word}`, $options: caseSensitive ? '' : 'i' } });
}

andQuery.push({ $or: orQuery });
}

Expand Down