diff --git a/client/db/highlight-query.js b/client/db/highlight-query.js
index ce31dfda2..222cf537f 100644
--- a/client/db/highlight-query.js
+++ b/client/db/highlight-query.js
@@ -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);
}
}
@@ -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);
}
diff --git a/client/db/index.jsx b/client/db/index.jsx
index 107e3c2ef..a45f8ff98 100644
--- a/client/db/index.jsx
+++ b/client/db/index.jsx
@@ -316,6 +316,7 @@ function QueryForm () {
+
diff --git a/database/qbreader/get-query.js b/database/qbreader/get-query.js
index 0695d2dba..dfcd43ef5 100644
--- a/database/qbreader/get-query.js
+++ b/database/qbreader/get-query.js
@@ -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.');
}
@@ -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: `^\\s*${word}\\s*(\\[.*|\\(.*)?$`, $options: caseSensitive ? '' : 'i' } });
+ }
+
andQuery.push({ $or: orQuery });
}
@@ -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: `^\\s*${word}\\s*(\\[.*|\\(.*)?$`, $options: caseSensitive ? '' : 'i' } });
+ }
+
andQuery.push({ $or: orQuery });
}
@@ -294,8 +302,6 @@ function buildQueryAggregation ({ query, difficulties, categories, subcategories
number: 1
}
},
- // { $skip: (pagination - 1) * maxReturnLength },
- // { $limit: maxReturnLength },
{ $project: { reports: 0 } }
];