Skip to content

Commit

Permalink
783329 - fix indexing of pkgs for elastic search and use in system te…
Browse files Browse the repository at this point in the history
…mplates UI

This commit makes some modifications to the indexing of packages
for elastic search.  The primary change is to allow us to support
'autocomplete' by providing an ngram filter on packages.  This also
allows for us to use the same name_search when the user provides the
full package name or partial.

Also, updated the system template UI to use the elastic search query
vs pulp.

Note: for system templates the auto-complete will sort the results based
on 'most relevent'... We may want to improve this in the future to only
show those that are absolutely relevant (e.g. only show entries that contain
exactly the characters typed.)
  • Loading branch information
bbuckingham committed Jan 24, 2012
1 parent ae63357 commit e4f68e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/app/controllers/packages_controller.rb
Expand Up @@ -47,8 +47,7 @@ def dependencies

def auto_complete_locker
name = params[:term]
render :json=>Pulp::Package.name_search(name).sort.uniq[0..19]
#ender :json=>Glue::Pulp::Package.name_search(name + '*')
render :json=>Glue::Pulp::Package.name_search(name)
end

private
Expand Down
30 changes: 26 additions & 4 deletions src/app/models/glue/pulp/package.rb
Expand Up @@ -19,12 +19,35 @@ def self.find id
Glue::Pulp::Package.new(Pulp::Package.find(id))
end

def self.index_settings
{
"index" => {
"analysis" => {
"filter" => {
"ngram_filter" => {
"type" => "edgeNGram",
"side" => "front",
"min_gram" => 1,
"max_gram" => 10
}
},
"analyzer" => {
"name_analyzer" => {
"type" => "custom",
"tokenizer" => "keyword",
"filter" => ["standard", "lowercase", "asciifolding", "ngram_filter"]
}
}
}
}
}
end

def self.index_mapping
{
:package => {
:properties => {
:name => { :type=> 'string', :analyzer=>'keyword'},
:name => { :type=> 'string', :analyzer=>'name_analyzer'},
:nvrea => { :type=> 'string', :analyzer=>'keyword'},
:nvrea_sort => { :type => 'string', :index=> :not_analyzed }
}
Expand Down Expand Up @@ -55,9 +78,8 @@ def self.name_search query, repoids=nil, number=15, sort=[:nvrea_sort, "ASC"]
end

if repoids
filter :terms, :repository_ids => repoids
filter :terms, :repoids => repoids
end
sort { by sort[0], sort[1] }
end
to_ret = []
search.results.each{|pkg|
Expand All @@ -81,7 +103,7 @@ def self.search query, start, page_size, repoids=nil, not_repoids=nil, sort=[:nv
from start
end
if repoids
filter :terms, :repository_ids => repoids
filter :terms, :repoids => repoids
end
if not_repoids
#filter do
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/repository.rb
Expand Up @@ -94,7 +94,7 @@ def update_related_index
def index_packages
pkgs = self.packages.collect{|pkg| pkg.as_json.merge(pkg.index_options)}
Tire.index Glue::Pulp::Package.index do
create :mappings => Glue::Pulp::Package.index_mapping
create :settings => Glue::Pulp::Package.index_settings, :mappings => Glue::Pulp::Package.index_mapping
import pkgs
end if !pkgs.empty?
end
Expand Down

0 comments on commit e4f68e7

Please sign in to comment.