deploy: a42e541326
parent
3de4af660d
commit
7b3de39ce8
|
@ -513,9 +513,11 @@ const Search = {
|
||||||
// perform the search on the required terms
|
// perform the search on the required terms
|
||||||
searchTerms.forEach((word) => {
|
searchTerms.forEach((word) => {
|
||||||
const files = [];
|
const files = [];
|
||||||
|
// find documents, if any, containing the query word in their text/title term indices
|
||||||
|
// use Object.hasOwnProperty to avoid mismatching against prototype properties
|
||||||
const arr = [
|
const arr = [
|
||||||
{ files: terms[word], score: Scorer.term },
|
{ files: terms.hasOwnProperty(word) ? terms[word] : undefined, score: Scorer.term },
|
||||||
{ files: titleTerms[word], score: Scorer.title },
|
{ files: titleTerms.hasOwnProperty(word) ? titleTerms[word] : undefined, score: Scorer.title },
|
||||||
];
|
];
|
||||||
// add support for partial matches
|
// add support for partial matches
|
||||||
if (word.length > 2) {
|
if (word.length > 2) {
|
||||||
|
@ -547,8 +549,9 @@ const Search = {
|
||||||
|
|
||||||
// set score for the word in each file
|
// set score for the word in each file
|
||||||
recordFiles.forEach((file) => {
|
recordFiles.forEach((file) => {
|
||||||
if (!scoreMap.has(file)) scoreMap.set(file, {});
|
if (!scoreMap.has(file)) scoreMap.set(file, new Map());
|
||||||
scoreMap.get(file)[word] = record.score;
|
const fileScores = scoreMap.get(file);
|
||||||
|
fileScores.set(word, record.score);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -587,7 +590,7 @@ const Search = {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// select one (max) score for the file.
|
// select one (max) score for the file.
|
||||||
const score = Math.max(...wordList.map((w) => scoreMap.get(file)[w]));
|
const score = Math.max(...wordList.map((w) => scoreMap.get(file).get(w)));
|
||||||
// add result to the result list
|
// add result to the result list
|
||||||
results.push([
|
results.push([
|
||||||
docNames[file],
|
docNames[file],
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue