Commit fbffea40 authored by Terri Chu's avatar Terri Chu Committed by Dylan Griffith

Search API - Allow notes scope for group/global search

parent 06c6774a
...@@ -27,7 +27,7 @@ GET /search ...@@ -27,7 +27,7 @@ GET /search
Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, snippet_titles, users. Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, snippet_titles, users.
If Elasticsearch is enabled additional scopes available are blobs, wiki_blobs and commits. Find more about [the feature](../integration/elasticsearch.md). **(STARTER)** If Elasticsearch is enabled additional scopes available are blobs, wiki_blobs, notes, and commits. Find more about [the feature](../integration/elasticsearch.md). **(STARTER)**
The response depends on the requested scope. The response depends on the requested scope.
...@@ -362,6 +362,40 @@ Example response: ...@@ -362,6 +362,40 @@ Example response:
NOTE: **Note:** NOTE: **Note:**
`filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path. For details, see [issue 34521](https://gitlab.com/gitlab-org/gitlab/-/issues/34521). `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path. For details, see [issue 34521](https://gitlab.com/gitlab-org/gitlab/-/issues/34521).
### Scope: notes **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/6/search?scope=notes&search=maxime"
```
Example response:
```json
[
{
"id": 191,
"body": "Harum maxime consequuntur et et deleniti assumenda facilis.",
"attachment": null,
"author": {
"id": 23,
"name": "User 1",
"username": "user1",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/111d68d06e2d317b5a59c2c6c5bad808?s=80&d=identicon",
"web_url": "http://localhost:3000/user1"
},
"created_at": "2017-09-05T08:01:32.068Z",
"updated_at": "2017-09-05T08:01:32.068Z",
"system": false,
"noteable_id": 22,
"noteable_type": "Issue",
"noteable_iid": 2
}
]
```
### Scope: users ### Scope: users
```shell ```shell
...@@ -402,7 +436,7 @@ GET /groups/:id/search ...@@ -402,7 +436,7 @@ GET /groups/:id/search
Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, users. Search the expression within the specified scope. Currently these scopes are supported: projects, issues, merge_requests, milestones, users.
If Elasticsearch is enabled additional scopes available are blobs, wiki_blobs and commits. Find more about [the feature](../integration/elasticsearch.md). **(STARTER)** If Elasticsearch is enabled additional scopes available are blobs, wiki_blobs, notes, and commits. Find more about [the feature](../integration/elasticsearch.md). **(STARTER)**
The response depends on the requested scope. The response depends on the requested scope.
...@@ -706,6 +740,40 @@ Example response: ...@@ -706,6 +740,40 @@ Example response:
NOTE **Note:** NOTE **Note:**
`filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path. For details, see [issue 34521](https://gitlab.com/gitlab-org/gitlab/-/issues/34521). `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path. For details, see [issue 34521](https://gitlab.com/gitlab-org/gitlab/-/issues/34521).
### Scope: notes **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/6/search?scope=notes&search=maxime"
```
Example response:
```json
[
{
"id": 191,
"body": "Harum maxime consequuntur et et deleniti assumenda facilis.",
"attachment": null,
"author": {
"id": 23,
"name": "User 1",
"username": "user1",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/111d68d06e2d317b5a59c2c6c5bad808?s=80&d=identicon",
"web_url": "http://localhost:3000/user1"
},
"created_at": "2017-09-05T08:01:32.068Z",
"updated_at": "2017-09-05T08:01:32.068Z",
"system": false,
"noteable_id": 22,
"noteable_type": "Issue",
"noteable_iid": 2
}
]
```
### Scope: users ### Scope: users
```shell ```shell
......
---
title: Search API allow group/global notes scope
merge_request: 42624
author:
type: changed
...@@ -11,12 +11,12 @@ module EE ...@@ -11,12 +11,12 @@ module EE
override :global_search_scopes override :global_search_scopes
def global_search_scopes def global_search_scopes
['wiki_blobs', 'blobs', 'commits', *super] ['wiki_blobs', 'blobs', 'commits', 'notes', *super]
end end
override :group_search_scopes override :group_search_scopes
def group_search_scopes def group_search_scopes
['wiki_blobs', 'blobs', 'commits', *super] ['wiki_blobs', 'blobs', 'commits', 'notes', *super]
end end
end end
end end
......
...@@ -9,7 +9,7 @@ module EE ...@@ -9,7 +9,7 @@ module EE
helpers do helpers do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
ELASTICSEARCH_SCOPES = %w(wiki_blobs blobs commits).freeze ELASTICSEARCH_SCOPES = %w(wiki_blobs blobs commits notes).freeze
override :verify_search_scope! override :verify_search_scope!
def verify_search_scope!(resource:) def verify_search_scope!(resource:)
......
...@@ -273,29 +273,27 @@ RSpec.describe API::Search do ...@@ -273,29 +273,27 @@ RSpec.describe API::Search do
it_behaves_like 'pagination', scope: 'users', search: '' it_behaves_like 'pagination', scope: 'users', search: ''
end end
if level == :global context 'for notes scope', :sidekiq_inline do
context 'for snippet_titles scope', :sidekiq_inline do
before do before do
create_list(:snippet, 2, :public, title: 'Some code', content: 'Check it out') create(:note_on_merge_request, project: project, note: 'awesome note')
mr = create(:merge_request, source_project: project, target_branch: 'another_branch')
create(:note, project: project, noteable: mr, note: 'another note')
ensure_elasticsearch_index! ensure_elasticsearch_index!
end end
it_behaves_like 'pagination', scope: 'snippet_titles' it_behaves_like 'pagination', scope: 'notes'
end
end end
if level == :project if level == :global
context 'for notes scope', :sidekiq_inline do context 'for snippet_titles scope', :sidekiq_inline do
before do before do
create(:note_on_merge_request, project: project, note: 'awesome note') create_list(:snippet, 2, :public, title: 'Some code', content: 'Check it out')
mr = create(:merge_request, source_project: project, target_branch: 'another_branch')
create(:note, project: project, noteable: mr, note: 'another note')
ensure_elasticsearch_index! ensure_elasticsearch_index!
end end
it_behaves_like 'pagination', scope: 'notes' it_behaves_like 'pagination', scope: 'snippet_titles'
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment