Commit 2f89f43f authored by Valery Sizov's avatar Valery Sizov

Elasticsearch does not find partial matches in project names

parent 1b0e045d
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.12.0 (Unreleased) v 8.12.0 (Unreleased)
- [ES] Instrument Elasticsearch::Git::Repository - [ES] Instrument Elasticsearch::Git::Repository
- [ES] Instrument other Gitlab::Elastic classes - [ES] Instrument other Gitlab::Elastic classes
- [ES] Fix: Elasticsearch does not find partial matches in project names
v 8.11.6 v 8.11.6
- Exclude blocked users from potential MR approvers - Exclude blocked users from potential MR approvers
......
...@@ -13,14 +13,26 @@ module Elastic ...@@ -13,14 +13,26 @@ module Elastic
analysis: { analysis: {
analyzer: { analyzer: {
default: { default: {
tokenizer: "standard", tokenizer: 'standard',
filter: ["standard", "lowercase", "my_stemmer"] filter: ['standard', 'lowercase', 'my_stemmer']
},
my_ngram_analyzer: {
tokenizer: 'my_ngram_tokenizer',
filter: ['lowercase']
} }
}, },
filter: { filter: {
my_stemmer: { my_stemmer: {
type: "stemmer", type: 'stemmer',
name: "light_english" 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 ...@@ -12,7 +12,8 @@ module Elastic
indexes :path, type: :string, indexes :path, type: :string,
index_options: 'offsets' index_options: 'offsets'
indexes :name_with_namespace, type: :string, indexes :name_with_namespace, type: :string,
index_options: 'offsets' index_options: 'offsets',
analyzer: :my_ngram_analyzer
indexes :path_with_namespace, type: :string, indexes :path_with_namespace, type: :string,
index_options: 'offsets' index_options: 'offsets'
indexes :description, type: :string, indexes :description, type: :string,
......
...@@ -58,7 +58,7 @@ namespace :gitlab do ...@@ -58,7 +58,7 @@ namespace :gitlab do
desc "GitLab | Elasticsearch | Index wiki repositories" desc "GitLab | Elasticsearch | Index wiki repositories"
task index_wikis: :environment do 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| projects.find_each do |project|
unless project.wiki.empty? unless project.wiki.empty?
......
...@@ -11,7 +11,7 @@ describe Project, elastic: true do ...@@ -11,7 +11,7 @@ describe Project, elastic: true do
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
it "searches projects" do it "finds projects" do
project_ids = [] project_ids = []
Sidekiq::Testing.inline! do Sidekiq::Testing.inline! do
...@@ -29,6 +29,20 @@ describe Project, elastic: true 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) expect(described_class.elastic_search('someone_elses_project', options: { pids: project_ids }).total_count).to eq(0)
end 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 it "returns json with all needed elements" do
project = create :empty_project 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