Skip to content

Commit

Permalink
Merge pull request #170 from zugdev/repos-in-search
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Nov 30, 2024
2 parents 36570a0 + a7dbe5e commit b2efa02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/home/issues-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class IssueSearch {
body: 0.25,
fuzzy: 0.25,
meta: 0.125,
repo: 0.1,
};

private readonly _config: SearchConfig = {
Expand Down Expand Up @@ -71,6 +72,7 @@ export class IssueSearch {
bodyMatches: [] as string[],
labelMatches: [] as string[],
numberMatch: false,
repoMatch: false,
fuzzyMatches: [] as Array<{
original: string;
matched: string;
Expand All @@ -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
Expand Down Expand Up @@ -153,6 +156,7 @@ export class IssueSearch {
labelMatches: [],
numberMatch: false,
fuzzyMatches: [],
repoMatch: false,
},
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/home/search/search-scorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/home/types/search-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface SearchResult {
matched: string;
score: number;
}>;
repoMatch: boolean;
};
}

Expand All @@ -19,6 +20,7 @@ export interface SearchWeights {
body: number;
fuzzy: number;
meta: number;
repo: number;
}

export interface SearchConfig {
Expand Down

0 comments on commit b2efa02

Please sign in to comment.