nitc :: CmdCatalogSearch :: defaultinit
# A CmdSearch command using a Catalog
class CmdCatalogSearch
super CmdCatalog
super CmdSearch
autoinit(model, catalog, filter, query, limit, page, count, max)
redef fun init_results do
if results != null then return new CmdSuccess
var res = super
if not res isa CmdSuccess then return res
var query = self.query
if query == null then return new ErrorNoQuery
sorter = null
var filter = self.filter
var index = model.index
# lookup by name prefix
var matches = index.find_by_name_prefix(query, filter).uniq.
sort(lname_sorter, name_sorter, kind_sorter)
matches = matches.rerank.sort(vis_sorter, score_sorter)
# lookup by tags
var malus = matches.length
if catalog.tag2proj.has_key(query) then
for mpackage in catalog.tag2proj[query] do
if filter != null and not filter.accept_mentity(mpackage) then continue
matches.add new IndexMatch(mpackage, malus)
malus += 1
end
matches = matches.uniq.rerank.sort(vis_sorter, score_sorter)
end
# lookup by full_name prefix
malus = matches.length
var full_matches = new IndexMatches
for match in index.find_by_full_name_prefix(query, filter).
sort(lfname_sorter, fname_sorter) do
match.score += 1
full_matches.add match
end
matches = matches.uniq
# lookup by similarity
malus = matches.length
var sim_matches = new IndexMatches
for match in index.find_by_similarity(query, filter).sort(score_sorter, kind_sorter, lname_sorter, name_sorter) do
if match.score > query.length then break
match.score += 1
sim_matches.add match
end
matches.add_all sim_matches
matches = matches.uniq
results = matches.rerank.sort(vis_sorter, score_sorter).mentities
return res
end
private var score_sorter = new ScoreComparator
private var vis_sorter = new VisibilityComparator
private var name_sorter = new NameComparator
private var lname_sorter = new NameLengthComparator
private var fname_sorter = new FullNameComparator
private var lfname_sorter = new FullNameLengthComparator
private var kind_sorter = new MEntityComparator
end
src/doc/commands/commands_catalog.nit:31,1--98,3