diff --git a/src/home/issues-search.ts b/src/home/issues-search.ts index 82be9f40..36999499 100644 --- a/src/home/issues-search.ts +++ b/src/home/issues-search.ts @@ -9,6 +9,7 @@ export class IssueSearch { body: 0.25, fuzzy: 0.25, meta: 0.125, + repo: 0.1, }; private readonly _config: SearchConfig = { @@ -71,6 +72,7 @@ export class IssueSearch { bodyMatches: [] as string[], labelMatches: [] as string[], numberMatch: false, + repoMatch: false, fuzzyMatches: [] as Array<{ original: string; matched: string; @@ -86,6 +88,7 @@ export class IssueSearch { body: this._searchScorer.calculateBodyScore(issue, searchTerms, matchDetails), fuzzy: enableFuzzy ? this._searchScorer.calculateFuzzyScore(searchableContent, searchTerms, matchDetails) : 0, meta: this._searchScorer.calculateMetaScore(issue, searchTerms, matchDetails), + repo: this._searchScorer.calculateRepoScore(issue, searchTerms, matchDetails), }; // Calculate weighted total score @@ -153,6 +156,7 @@ export class IssueSearch { labelMatches: [], numberMatch: false, fuzzyMatches: [], + repoMatch: false, }, }; } diff --git a/src/home/search/search-scorer.ts b/src/home/search/search-scorer.ts index 89adad72..06059ccd 100644 --- a/src/home/search/search-scorer.ts +++ b/src/home/search/search-scorer.ts @@ -91,6 +91,24 @@ export class SearchScorer { return score; } + public calculateRepoScore(issue: GitHubIssue, searchTerms: string[], matchDetails: SearchResult["matchDetails"]): number { + let score = 0; + if (issue.repository_url) { + const repoName = issue.repository_url.split("/").pop()?.toLowerCase() || ""; + const orgName = issue.repository_url.split("/").slice(-2)[0].toLowerCase() || ""; + searchTerms.forEach((term) => { + if (repoName.startsWith(term.toLowerCase())) { + matchDetails.repoMatch = true; + score += term.length / repoName.length; + } + if (orgName.startsWith(term.toLowerCase())) { + score += term.length / orgName.length; + } + }); + } + return score; + } + public calculateFuzzyScore(content: string, searchTerms: string[], matchDetails: SearchResult["matchDetails"]): number { let score = 0; const contentWords = this._tokenizeContent(content); diff --git a/src/home/types/search-types.ts b/src/home/types/search-types.ts index 8b25d226..bafa5fbb 100644 --- a/src/home/types/search-types.ts +++ b/src/home/types/search-types.ts @@ -11,6 +11,7 @@ export interface SearchResult { matched: string; score: number; }>; + repoMatch: boolean; }; } @@ -19,6 +20,7 @@ export interface SearchWeights { body: number; fuzzy: number; meta: number; + repo: number; } export interface SearchConfig {