Commit 45402b12 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'es_project_search' into 'master'

Fix: Elasticsearch does not find partial matches in project names

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/960

See merge request !726
parents e75c8bd2 2f89f43f
......@@ -3,6 +3,7 @@ v 8.12.0 (Unreleased)
- Reduce UPDATE queries when moving between import states on projects
- [ES] Instrument Elasticsearch::Git::Repository
- [ES] Instrument other Gitlab::Elastic classes
- [ES] Fix: Elasticsearch does not find partial matches in project names
v 8.11.6
- Exclude blocked users from potential MR approvers
......
......@@ -13,14 +13,26 @@ module Elastic
analysis: {
analyzer: {
default: {
tokenizer: "standard",
filter: ["standard", "lowercase", "my_stemmer"]
tokenizer: 'standard',
filter: ['standard', 'lowercase', 'my_stemmer']
},
my_ngram_analyzer: {
tokenizer: 'my_ngram_tokenizer',
filter: ['lowercase']
}
},
filter: {
my_stemmer: {
type: "stemmer",
name: "light_english"
type: 'stemmer',
name: 'light_english'
}
},
tokenizer: {
my_ngram_tokenizer: {
type: 'nGram',
min_gram: 2,
max_gram: 3,
token_chars: [ 'letter', 'digit' ]
}
}
}
......
......@@ -12,7 +12,8 @@ module Elastic
indexes :path, type: :string,
index_options: 'offsets'
indexes :name_with_namespace, type: :string,
index_options: 'offsets'
index_options: 'offsets',
analyzer: :my_ngram_analyzer
indexes :path_with_namespace, type: :string,
index_options: 'offsets'
indexes :description, type: :string,
......
......@@ -58,7 +58,7 @@ namespace :gitlab do
desc "GitLab | Elasticsearch | Index wiki repositories"
task index_wikis: :environment do
projects = apply_project_filters(Project.where(wiki_enabled: true))
projects = apply_project_filters(Project.with_wiki_enabled)
projects.find_each do |project|
unless project.wiki.empty?
......
......@@ -11,7 +11,7 @@ describe Project, elastic: true do
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end
it "searches projects" do
it "finds projects" do
project_ids = []
Sidekiq::Testing.inline! do
......@@ -29,6 +29,20 @@ describe Project, elastic: true do
expect(described_class.elastic_search('someone_elses_project', options: { pids: project_ids }).total_count).to eq(0)
end
it "finds partial matches in project names" do
project_ids = []
Sidekiq::Testing.inline! do
project = create :empty_project, name: 'tesla-model-s'
project1 = create :empty_project, name: 'tesla_model_s'
project_ids += [project.id, project1.id]
Gitlab::Elastic::Helper.refresh_index
end
expect(described_class.elastic_search('tesla', options: { pids: project_ids }).total_count).to eq(2)
end
it "returns json with all needed elements" do
project = create :empty_project
......
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