Commit b72ae798 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '258377_search_filter_defaults' into 'master'

Set default query string when searching with filters

See merge request gitlab-org/gitlab!49872
parents f4be2749 192cf86b
---
title: Set default query string when searching with filters
merge_request: 49872
author:
type: added
......@@ -63,6 +63,24 @@ RSpec.describe Repository, :elastic do
# Finds files/ruby/popen.rb
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
def search_and_check!(on, query, type:, per: 1000)
......
......@@ -51,6 +51,7 @@ module Gitlab
end
query = (@raw_query.split - fragments).join(' ')
query = '*' if query.empty?
[query, filters]
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