Skip to content

Commit

Permalink
Fix: Ignore invalid content (fixes #68) (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck authored Oct 4, 2023
1 parent d785c9a commit 306b8c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions js/SearchableModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default class SearchableModel {
const type = this.model.get('_type');
const shouldIgnore = hideTypes.includes(type) || (type === 'component' && hideComponents.includes(component));
if (shouldIgnore) return false;
const displayTitle = this.model.get('displayTitle').trim();
const title = this.model.get('title').trim();
const displayTitle = this.model.get('displayTitle')?.trim();
const title = this.model.get('title')?.trim();
const hasTitleOrDisplayTitle = Boolean(displayTitle || title);
return hasTitleOrDisplayTitle;
}
Expand Down
7 changes: 4 additions & 3 deletions js/SearchablePhrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export default class SearchablePhrase {
? config._ignoreWords
: config._ignoreWords.split(',');
const minimumWordLength = config._minimumWordLength;
this.words = this.safePhrase
.match(matchNotWordBoundaries)
.map(chunk => chunk.replace(trimReplaceNonWordCharacters, ''))
this.words = {};
const matchedWords = this.safePhrase.match(matchNotWordBoundaries);
if (matchedWords === null) return;
this.words = matchedWords.map(chunk => chunk.replace(trimReplaceNonWordCharacters, ''))
.filter(word => word.length >= minimumWordLength)
.reduce((wordCounts, word) => {
word = word.toLowerCase();
Expand Down

0 comments on commit 306b8c4

Please sign in to comment.