Commit 1b0e6036 authored by Stan Hu's avatar Stan Hu

Merge branch '251223-blob-search-should-match-on-the-blob-id' into 'master'

Add the `blob:` search filter to search by Git object-id

Closes #251223

See merge request gitlab-org/gitlab!42752
parents bcfcf43e 21ada901
...@@ -62,6 +62,7 @@ The Advanced Search Syntax also supports the use of filters. The available filte ...@@ -62,6 +62,7 @@ The Advanced Search Syntax also supports the use of filters. The available filte
- filename: Filters by filename. You can use the glob (`*`) operator for fuzzy matching. - filename: Filters by filename. You can use the glob (`*`) operator for fuzzy matching.
- path: Filters by path. You can use the glob (`*`) operator for fuzzy matching. - path: Filters by path. You can use the glob (`*`) operator for fuzzy matching.
- extension: Filters by extension in the filename. Please write the extension without a leading dot. Exact match only. - extension: Filters by extension in the filename. Please write the extension without a leading dot. Exact match only.
- blob: Filters by Git `object-id`. Exact match only.
To use them, simply add them to your query in the format `<filter_name>:<value>` without To use them, simply add them to your query in the format `<filter_name>:<value>` without
any spaces between the colon (`:`) and the value. any spaces between the colon (`:`) and the value.
...@@ -83,6 +84,7 @@ Filters can be inversed to **filter out** results from the result set, by prefix ...@@ -83,6 +84,7 @@ Filters can be inversed to **filter out** results from the result set, by prefix
- `-filename` - `-filename`
- `-path` - `-path`
- `-extension` - `-extension`
- `-blob`
Examples: Examples:
......
---
title: Add 'blob:' search filter to search for a specific Git object ID.
merge_request: 42752
author:
type: added
...@@ -115,6 +115,7 @@ module Elastic ...@@ -115,6 +115,7 @@ module Elastic
filter :filename, field: :file_name filter :filename, field: :file_name
filter :path, parser: ->(input) { "*#{input.downcase}*" } filter :path, parser: ->(input) { "*#{input.downcase}*" }
filter :extension, field: :path, parser: ->(input) { '*.' + input.downcase } filter :extension, field: :path, parser: ->(input) { '*.' + input.downcase }
filter :blob, field: :oid
end end
bool_expr = Gitlab::Elastic::BoolExpr.new bool_expr = Gitlab::Elastic::BoolExpr.new
......
...@@ -46,6 +46,9 @@ RSpec.describe Repository, :elastic do ...@@ -46,6 +46,9 @@ RSpec.describe Repository, :elastic do
# Finds files/markdown/ruby-style-guide.md # Finds files/markdown/ruby-style-guide.md
expect(project.repository.elastic_search('def | popen extension:md')[:blobs][:total_count]).to eq(1) expect(project.repository.elastic_search('def | popen extension:md')[:blobs][:total_count]).to eq(1)
# Finds files/ruby/popen.rb
expect(project.repository.elastic_search('* blob:7e3e39ebb9b2bf433b4ad17313770fbe4051649c')[:blobs][:total_count]).to eq(1)
end end
def search_and_check!(on, query, type:, per: 1000) def search_and_check!(on, query, type:, per: 1000)
......
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