Skip to content

Commit bf73429

Browse files
committed
fix(search) Slightly improved (but still flawed in certain circumstances) results ordering
1 parent e6d9bb4 commit bf73429

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

server/data_form.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
210210
sortString += padLeft(obj.searchImportance || 99, 2);
211211
sortString += padLeft(obj.weighting || 9999, 4);
212212
sortString += obj.text;
213+
console.log(sortString);
213214
return sortString;
214215
}
215216
if (filter) {
@@ -244,9 +245,9 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
244245
}
245246
}
246247
}
247-
var that = this, results = [], moreCount = 0, searchCriteria;
248+
var that = this, results = [], moreCount = 0, searchCriteria, multiMatchPossible = searchFor.includes(' '), modifiedSearchStr = multiMatchPossible ? searchFor.split(' ').join('|') : searchFor;
248249
// Removed the logic that preserved spaces when collection was specified because Louise asked me to.
249-
searchCriteria = { $regex: '^(' + searchFor.split(' ').join('|') + ')', $options: 'i' };
250+
searchCriteria = { $regex: '^(' + modifiedSearchStr + ')', $options: 'i' };
250251
this.searchFunc(searches, function (item, cb) {
251252
var searchDoc = {};
252253
if (filter) {
@@ -292,7 +293,9 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
292293
resultObject = {};
293294
extend(resultObject, results[resultPos]);
294295
// If they have already matched then improve their weighting
295-
resultObject.addHits = Math.max((resultObject.addHits || 9) - 1, 1);
296+
if (multiMatchPossible) {
297+
resultObject.addHits = Math.max((resultObject.addHits || 9) - 1, 1);
298+
}
296299
// remove it from current position
297300
results.splice(resultPos, 1);
298301
// and re-insert where appropriate

server/data_form.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,13 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
285285
var that = this,
286286
results = [],
287287
moreCount = 0,
288-
searchCriteria;
288+
searchCriteria,
289+
multiMatchPossible = searchFor.includes(' '),
290+
modifiedSearchStr = multiMatchPossible ? searchFor.split(' ').join('|') : searchFor;
289291

290292
// Removed the logic that preserved spaces when collection was specified because Louise asked me to.
291-
searchCriteria = {$regex: '^(' + searchFor.split(' ').join('|') + ')', $options: 'i'};
293+
294+
searchCriteria = {$regex: '^(' + modifiedSearchStr + ')', $options: 'i'};
292295

293296
this.searchFunc(
294297
searches,
@@ -340,7 +343,10 @@ DataForm.prototype.internalSearch = function (req, resourcesToSearch, includeRes
340343
resultObject = {};
341344
extend(resultObject, results[resultPos]);
342345
// If they have already matched then improve their weighting
343-
resultObject.addHits = Math.max((resultObject.addHits || 9) - 1, 1);
346+
// TODO: if the search string is B F currently Benjamin Barker scores same as Benjamin Franklin)
347+
if (multiMatchPossible) {
348+
resultObject.addHits = Math.max((resultObject.addHits || 9) - 1, 1);
349+
}
344350
// remove it from current position
345351
results.splice(resultPos, 1);
346352
// and re-insert where appropriate

0 commit comments

Comments
 (0)