Commit ab6b7025 authored by Valery Sizov's avatar Valery Sizov Committed by Sean McGivern

[Elasticsearch] Improve code search for camel case

parent 818f0655
---
title: "[Elasticsearch] Improve code search for camel case"
merge_request:
author:
......@@ -33,7 +33,7 @@ module Elasticsearch
code_analyzer: {
type: 'custom',
tokenizer: 'standard',
filter: %w(code lowercase asciifolding),
filter: %w(code edgeNGram_filter lowercase asciifolding),
char_filter: ["code_mapping"]
},
code_search_analyzer: {
......@@ -61,8 +61,14 @@ module Elasticsearch
preserve_original: 1,
patterns: [
"(\\p{Ll}+|\\p{Lu}\\p{Ll}+|\\p{Lu}+)",
"(\\d+)"
"(\\d+)",
"(?=([\\p{Lu}]+[\\p{L}]+))"
]
},
edgeNGram_filter: {
type: 'edgeNGram',
min_gram: 2,
max_gram: 40
}
},
char_filter: {
......
......@@ -399,6 +399,45 @@ describe Gitlab::Elastic::SearchResults, lib: true do
expect(results.blobs_count).to eq 0
end
context 'Searches CamelCased methods' do
before do
project_1.repository.create_file(
user,
'test.txt',
' function writeStringToFile(){} ',
message: 'added test file',
branch_name: 'master')
project_1.repository.index_blobs
Gitlab::Elastic::Helper.refresh_index
end
def search_for(term)
blobs = described_class.new(user, term, [project_1.id]).objects('blobs')
blobs.map do |blob|
blob["_source"]["blob"]["path"]
end
end
it 'find by first word' do
expect(search_for('write')).to include('test.txt')
end
it 'find by first two words' do
expect(search_for('writeString')).to include('test.txt')
end
it 'find by last two words' do
expect(search_for('ToFile')).to include('test.txt')
end
it 'find by exact match' do
expect(search_for('writeStringToFile')).to include('test.txt')
end
end
end
describe 'Wikis' do
......
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