Skip to content

Commit

Permalink
limit results to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
abaldeweg authored Oct 29, 2024
1 parent b46c9db commit 5548730
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gateway/core/repository/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type AuthorRepository struct {

const tableName = "author"

const limit = 100

// NewAuthorRepository creates a new author repository.
func NewAuthorRepository(db *gorm.DB) *AuthorRepository {
return &AuthorRepository{db: db}
Expand All @@ -20,7 +22,7 @@ func NewAuthorRepository(db *gorm.DB) *AuthorRepository {
// FindAllByTerm returns all authors by term.
func (r *AuthorRepository) FindAllByTerm(term string) ([]models.Author, error) {
var authors []models.Author
result := r.db.Table(tableName).Where("firstname LIKE ? OR surname LIKE ? OR CONCAT(firstname, ' ', surname) LIKE ? OR CONCAT(surname, ' ', firstname) LIKE ? OR CONCAT(firstname, ',', surname) LIKE ? OR CONCAT(firstname, ', ', surname) LIKE ?", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%").Find(&authors)
result := r.db.Table(tableName).Where("firstname LIKE ? OR surname LIKE ? OR CONCAT(firstname, ' ', surname) LIKE ? OR CONCAT(surname, ' ', firstname) LIKE ? OR CONCAT(firstname, ',', surname) LIKE ? OR CONCAT(firstname, ', ', surname) LIKE ?", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%", "%"+term+"%").Limit(limit).Find(&authors)
return authors, result.Error
}

Expand Down

0 comments on commit 5548730

Please sign in to comment.