Commit 192cf86b authored by Changzheng Liu's avatar Changzheng Liu

Set default query string when searching with filters

parent 54b2e5a8
---
title: Set default query string when searching with filters
merge_request: 49872
author:
type: added
...@@ -63,6 +63,24 @@ RSpec.describe Repository, :elastic do ...@@ -63,6 +63,24 @@ RSpec.describe Repository, :elastic do
# Finds files/ruby/popen.rb # Finds files/ruby/popen.rb
expect(project.repository.elastic_search('* blob:7e3e39ebb9b2bf433b4ad17313770fbe4051649c')[:blobs][:total_count]).to eq(1) expect(project.repository.elastic_search('* blob:7e3e39ebb9b2bf433b4ad17313770fbe4051649c')[:blobs][:total_count]).to eq(1)
# filename filter without search term
count = project.repository.ls_files('master').count { |path| path.split('/')[-1].include?('test') }
expect(project.repository.elastic_search('filename:test')[:blobs][:total_count]).to eq(count)
expect(project.repository.elastic_search('filename:test')[:blobs][:total_count]).to be > 0
# extension filter without search term
count = project.repository.ls_files('master').count { |path| path.split('/')[-1].split('.')[-1].include?('md') }
expect(project.repository.elastic_search('extension:md')[:blobs][:total_count]).to eq(count)
expect(project.repository.elastic_search('extension:md')[:blobs][:total_count]).to be > 0
# path filter without search term
count = project.repository.ls_files('master').count { |path| path.include?('ruby') }
expect(project.repository.elastic_search('path:ruby')[:blobs][:total_count]).to eq(count)
expect(project.repository.elastic_search('path:ruby')[:blobs][:total_count]).to be > 0
# blob filter without search term
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)
......
...@@ -51,6 +51,7 @@ module Gitlab ...@@ -51,6 +51,7 @@ module Gitlab
end end
query = (@raw_query.split - fragments).join(' ') query = (@raw_query.split - fragments).join(' ')
query = '*' if query.empty?
[query, filters] [query, filters]
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