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

Resolves #2428 #2429

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions pkg/query/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ func NewSourceQueryBuilder(

type abstractResult struct {
source string
id int
base string
baseid int
name string
description string
votes int
provides []string
submitted int
modified int
popularity float64
}

type abstractResults struct {
Expand All @@ -106,6 +112,19 @@ func (a *abstractResults) Less(i, j int) bool {
var cmpResult bool

switch a.sortBy {
case "id":
cmpResult = pkgA.id > pkgB.id
case "base":
cmpResult = !text.LessRunes([]rune(pkgA.base), []rune(pkgB.base))
if a.separateSources {
cmpSources := strings.Compare(pkgA.source, pkgB.source)
if cmpSources != 0 {
cmpResult = cmpSources > 0
}
}

case "baseid":
cmpResult = pkgA.baseid > pkgB.baseid
case "name":
cmpResult = !text.LessRunes([]rune(pkgA.name), []rune(pkgB.name))
if a.separateSources {
Expand All @@ -114,6 +133,15 @@ func (a *abstractResults) Less(i, j int) bool {
cmpResult = cmpSources > 0
}
}
case "votes":
cmpResult = pkgA.votes > pkgB.votes
case "submitted":
cmpResult = pkgA.submitted > pkgB.submitted
case "modified":
cmpResult = pkgA.modified > pkgB.modified
case "popularity":
cmpResult = pkgA.popularity > pkgB.popularity

default:
simA := a.calculateMetric(&pkgA)
simB := a.calculateMetric(&pkgB)
Expand Down Expand Up @@ -167,10 +195,16 @@ func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor

sortableResults.results = append(sortableResults.results, abstractResult{
source: dbName,
id: aurResults[i].ID,
base: aurResults[i].PackageBase,
baseid: aurResults[i].PackageBaseID,
name: aurResults[i].Name,
description: aurResults[i].Description,
provides: aurResults[i].Provides,
votes: aurResults[i].NumVotes,
submitted: aurResults[i].FirstSubmitted,
modified: aurResults[i].LastModified,
popularity: aurResults[i].Popularity,
})
}
}
Expand Down
Loading