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

Only show relevant repositories on explore page #19361

Merged
merged 36 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1dc8fde
Only show relevant repositories (part 1)
Apr 9, 2022
89caf08
Show information message to indicate filtered results
Apr 9, 2022
8bff6db
Merge branch 'main' into filter-explore-repo
Apr 9, 2022
254c4c7
Add control logic
Apr 9, 2022
08bb17f
Fix grammar
Apr 9, 2022
2998580
Move inline style to _explore.less
Apr 9, 2022
95b3be9
Correctify comment
Apr 9, 2022
47f7419
Fix linter
Apr 9, 2022
68a2395
Restrict if statement
Apr 9, 2022
7aab29a
Merge branch 'main' into filter-explore-repo
Apr 10, 2022
455b84b
Merge branch 'main' into filter-explore-repo
Apr 12, 2022
aa8223f
Enhance setting naming
Apr 15, 2022
82c6b6e
Merge branch 'main' into filter-explore-repo
Apr 15, 2022
5d5a501
Fix empty topics
Apr 25, 2022
db9d821
Always use filtering logic for recentupdate sort
Apr 25, 2022
5f4279d
Merge branch 'main' into filter-explore-repo
Apr 25, 2022
7b4ba21
Merge branch 'main' into filter-explore-repo
Apr 28, 2022
4fe22ef
Add no_filter to pager
Apr 30, 2022
fbe9744
Merge branch 'main' into filter-explore-repo
Apr 30, 2022
621b4bd
Merge branch 'main' into filter-explore-repo
May 5, 2022
b7d6a4c
Add more checks
May 14, 2022
36f38ae
Merge branch 'main' into filter-explore-repo
May 14, 2022
a502cf7
Merge branch 'main' into filter-explore-repo
May 28, 2022
d11a339
Apply suggestions from code review
Jun 17, 2022
4e406cb
Merge branch 'main' into filter-explore-repo
Jul 4, 2022
bc970ec
Improve wording
Jul 4, 2022
d385200
Fix translation
Jul 4, 2022
838c3e6
Merge branch 'main' into filter-explore-repo
6543 Jul 4, 2022
e8dcc7b
Merge branch 'main' into filter-explore-repo
Jul 6, 2022
5e293b7
Merge branch 'main' into filter-explore-repo
6543 Jul 25, 2022
8c4ff3c
Merge branch 'main' into filter-explore-repo
6543 Aug 9, 2022
5a6dc2d
Merge branch 'main' into filter-explore-repo
Aug 20, 2022
87b9b75
Merge branch 'main' into filter-explore-repo
6543 Aug 22, 2022
259de77
Merge branch 'main' into filter-explore-repo
Aug 22, 2022
93b4d37
Merge branch 'main' into filter-explore-repo
6543 Aug 25, 2022
6c17f9c
Merge branch 'main' into filter-explore-repo
6543 Aug 25, 2022
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 custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,10 @@ ROUTER = console
;;
;; Whether to enable a Service Worker to cache frontend assets
;USE_SERVICE_WORKER = false
;;
;; Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
;; A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).
;ONLY_SHOW_RELEVANT_REPOS = false

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 2 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
- `USE_SERVICE_WORKER`: **false**: Whether to enable a Service Worker to cache frontend assets.
- `ONLY_SHOW_RELEVANT_REPOS`: **false** Whether to only show relevant repos on the explore page when no keyword is specified and default sorting is used.
A repo is considered irrelevant if it's a fork or if it has no metadata (no description, no icon, no topic).

### UI - Admin (`ui.admin`)

Expand Down
31 changes: 29 additions & 2 deletions models/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ type SearchRepoOptions struct {
HasMilestones util.OptionalBool
// LowerNames represents valid lower names to restrict to
LowerNames []string
// When specified true, apply some filters over the conditions:
// - Don't show forks, when opts.Fork is OptionalBoolNone.
// - Do not display repositories that don't have a description, an icon and topics.
OnlyShowRelevant bool
}

// SearchOrderBy is used to sort the result
Expand Down Expand Up @@ -463,8 +467,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true})))
}

if opts.Fork != util.OptionalBoolNone {
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
if opts.Fork != util.OptionalBoolNone || opts.OnlyShowRelevant {
if opts.OnlyShowRelevant && opts.Fork == util.OptionalBoolNone {
cond = cond.And(builder.Eq{"is_fork": false})
} else {
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})
}
}

if opts.Mirror != util.OptionalBoolNone {
Expand All @@ -486,6 +494,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"}))
}

if opts.OnlyShowRelevant {
// Only show a repo that either has a topic or description.
subQueryCond := builder.NewCond()

// Topic checking. Topics is non-null.
subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"}))

// Description checking. Description not empty.
subQueryCond = subQueryCond.Or(builder.Neq{"description": ""})

// Repo has a avatar.
subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""})

// Always hide repo's that are empty.
subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false})

cond = cond.And(subQueryCond)
}

return cond
}

Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ var (
CustomEmojisMap map[string]string `ini:"-"`
SearchRepoDescription bool
UseServiceWorker bool
OnlyShowRelevantRepos bool

Notification struct {
MinTimeout time.Duration
Expand Down Expand Up @@ -1084,6 +1085,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(false)
UI.OnlyShowRelevantRepos = Cfg.Section("ui").Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)

HasRobotsTxt, err = util.IsFile(path.Join(CustomPath, "robots.txt"))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ org_no_results = No matching organizations found.
code_no_results = No source code matching your search term found.
code_search_results = Search results for '%s'
code_last_indexed_at = Last indexed %s
relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden.
relevant_repositories = Only relevant repositories are being shown, <a href="%s">show unfiltered results</a>.


[auth]
create_new_account = Register Account
Expand Down
20 changes: 14 additions & 6 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
}

var (
repos []*repo_model.Repository
count int64
err error
orderBy db.SearchOrderBy
repos []*repo_model.Repository
count int64
err error
orderBy db.SearchOrderBy
onlyShowRelevant bool
)

ctx.Data["SortType"] = ctx.FormString("sort")
Expand All @@ -60,8 +61,6 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
orderBy = db.SearchOrderByNewest
case "oldest":
orderBy = db.SearchOrderByOldest
case "recentupdate":
Gusted marked this conversation as resolved.
Show resolved Hide resolved
orderBy = db.SearchOrderByRecentUpdated
case "leastupdate":
orderBy = db.SearchOrderByLeastUpdated
case "reversealphabetically":
Expand All @@ -83,9 +82,16 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
default:
ctx.Data["SortType"] = "recentupdate"
orderBy = db.SearchOrderByRecentUpdated
onlyShowRelevant = setting.UI.OnlyShowRelevantRepos && !ctx.FormBool("no_filter")
}

keyword := ctx.FormTrim("q")
if keyword != "" {
onlyShowRelevant = false
}

ctx.Data["OnlyShowRelevant"] = onlyShowRelevant

topicOnly := ctx.FormBool("topic")
ctx.Data["TopicOnly"] = topicOnly

Expand All @@ -107,6 +113,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
TopicOnly: topicOnly,
Language: language,
IncludeDescription: setting.UI.SearchRepoDescription,
OnlyShowRelevant: onlyShowRelevant,
})
if err != nil {
ctx.ServerError("SearchRepository", err)
Expand All @@ -133,6 +140,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "topic", "TopicOnly")
pager.AddParam(ctx, "language", "Language")
pager.AddParamString("no_filter", ctx.FormString("no_filter"))
ctx.Data["Page"] = pager

ctx.HTML(http.StatusOK, opts.TplName)
Expand Down
5 changes: 5 additions & 0 deletions templates/explore/repo_search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
<button class="ui primary button">{{.locale.Tr "explore.search"}}</button>
</div>
</form>
{{if .OnlyShowRelevant}}
<div class="ui blue attached message explore-relevancy-note">
<span class="ui tooltip" data-content="{{.locale.Tr "explore.relevant_repositories_tooltip"}}">{{.locale.Tr "explore.relevant_repositories" ((printf "%s%s" $.Link "?no_filter=1")|Escape) | Safe}}</span>
</div>
{{end}}
<div class="ui divider"></div>
6 changes: 6 additions & 0 deletions web_src/less/_explore.less
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@
}
}
}

.ui.explore-relevancy-note {
border-top: 0;
margin-top: 0;
max-width: 90%;
}