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

feat: repos in search #170

Merged
merged 3 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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
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
Loading