Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safety check for highlighting where field is undefined #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 8 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,14 @@ function applyHighlighting(pouch, opts, rows, fieldBoosts,
var text = getText(fieldBoost, doc);
// TODO: this is fairly naive highlighting code; could improve
// the regex
Object.keys(queryTerms).forEach(function (queryTerm) {
var regex = new RegExp('(' + queryTerm + '[a-z]*)', 'gi');
var replacement = pre + '$1' + post;
text = text.replace(regex, replacement);
row.highlighting[fieldName] = text;
});
if (text) {
Object.keys(queryTerms).forEach(function (queryTerm) {
var regex = new RegExp('(' + queryTerm + '[a-z]*)', 'gi');
var replacement = pre + '$1' + post;
text = text.replace(regex, replacement);
row.highlighting[fieldName] = text;
});
}
});
});
})).then(function () {
Expand Down