From da42dfb3cf4a2fb0cdcc1a3b41438516a0bed0e5 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 24 Nov 2017 12:24:24 +0100 Subject: Use fuzzy search with minimum length of 3 characters where appropriate --- app/models/snippet.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'app/models/snippet.rb') diff --git a/app/models/snippet.rb b/app/models/snippet.rb index e621404f3ae..05a16f11b59 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -136,10 +136,7 @@ class Snippet < ActiveRecord::Base # # Returns an ActiveRecord::Relation. def search(query) - t = arel_table - pattern = to_pattern(query) - - where(t[:title].matches(pattern).or(t[:file_name].matches(pattern))) + fuzzy_search(query, [:title, :file_name]) end # Searches for snippets with matching content. @@ -150,7 +147,7 @@ class Snippet < ActiveRecord::Base # # Returns an ActiveRecord::Relation. def search_code(query) - where(arel_table[:content].matches(to_pattern(query))) + fuzzy_search(query, [:content]) end end end -- cgit v1.2.1