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
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.
......@@ -362,6 +362,40 @@ Example response:
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).
### 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
```shell
......@@ -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.
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.
......@@ -706,6 +740,40 @@ Example response:
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).
### 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
```shell
......
---
title: Search API allow group/global notes scope
merge_request: 42624
author:
type: changed
......@@ -11,12 +11,12 @@ module EE
override :global_search_scopes
def global_search_scopes
['wiki_blobs', 'blobs', 'commits', *super]
['wiki_blobs', 'blobs', 'commits', 'notes', *super]
end
override :group_search_scopes
def group_search_scopes
['wiki_blobs', 'blobs', 'commits', *super]
['wiki_blobs', 'blobs', 'commits', 'notes', *super]
end
end
end
......
......@@ -9,7 +9,7 @@ module EE
helpers do
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!
def verify_search_scope!(resource:)
......
......@@ -273,29 +273,27 @@ RSpec.describe API::Search do
it_behaves_like 'pagination', scope: 'users', search: ''
end
if level == :global
context 'for snippet_titles scope', :sidekiq_inline do
before do
create_list(:snippet, 2, :public, title: 'Some code', content: 'Check it out')
ensure_elasticsearch_index!
end
context 'for notes scope', :sidekiq_inline do
before do
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')
it_behaves_like 'pagination', scope: 'snippet_titles'
ensure_elasticsearch_index!
end
it_behaves_like 'pagination', scope: 'notes'
end
if level == :project
context 'for notes scope', :sidekiq_inline do
if level == :global
context 'for snippet_titles scope', :sidekiq_inline do
before do
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')
create_list(:snippet, 2, :public, title: 'Some code', content: 'Check it out')
ensure_elasticsearch_index!
end
it_behaves_like 'pagination', scope: 'notes'
it_behaves_like 'pagination', scope: 'snippet_titles'
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