mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 05:52:43 +00:00
Include description in repository search. (#7942)
* Add description in repository search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Refactor SearchRepositoryByName with a general function SearchRepository Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Allow to specify if description shall be included in API repo search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add new app.ini setting for whether to search within repo description. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Search keyword in description (if setting enabled) on: - Explore page - Organization profile page - User profile page - Admin repo page Do not search keyword in description on: - Any non-keyword search (not relevant) - Incremental search (uses API) Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Put parameters related to keyword directly after it Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add test cases for including (and not including) repository description in search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Rename test function from TestSearchRepositoryByName to TestSearchRepository. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Make setting SEARCH_REPO_DESCRIPTION default to true Signed-off-by: David Svantesson <davidsvantesson@gmail.com>
This commit is contained in:
parent
8c24bb9e43
commit
c9546d4cdd
11 changed files with 134 additions and 73 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSearchRepositoryByName(t *testing.T) {
|
||||
func TestSearchRepository(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// test search public repository on explore page
|
||||
|
@ -74,6 +74,34 @@ func TestSearchRepositoryByName(t *testing.T) {
|
|||
assert.Empty(t, repos)
|
||||
assert.Equal(t, int64(0), count)
|
||||
|
||||
// Test search within description
|
||||
repos, count, err = SearchRepository(&SearchRepoOptions{
|
||||
Keyword: "description_14",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Collaborate: util.OptionalBoolFalse,
|
||||
IncludeDescription: true,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, repos, 1) {
|
||||
assert.Equal(t, "test_repo_14", repos[0].Name)
|
||||
}
|
||||
assert.Equal(t, int64(1), count)
|
||||
|
||||
// Test NOT search within description
|
||||
repos, count, err = SearchRepository(&SearchRepoOptions{
|
||||
Keyword: "description_14",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Collaborate: util.OptionalBoolFalse,
|
||||
IncludeDescription: false,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, repos)
|
||||
assert.Equal(t, int64(0), count)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
opts *SearchRepoOptions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue