+fun search(index: ModelIndex, toolcontext: ToolContext, query: String): Float do
+ var clock = new Clock
+ print "# {query}\n"
+
+ var res
+ if toolcontext.opt_name_prefix.value then
+ res = index.find_by_name_prefix(query)
+ else if toolcontext.opt_full_name_prefix.value then
+ res = index.find_by_full_name_prefix(query)
+ else if toolcontext.opt_name_similarity.value then
+ res = index.find_by_name_similarity(query)
+ else if toolcontext.opt_full_name_similarity.value then
+ res = index.find_by_full_name_similarity(query)
+ else if toolcontext.opt_name.value then
+ res = index.find_by_name(query)
+ else if toolcontext.opt_full_name.value then
+ res = index.find_by_full_name(query)
+ else
+ res = index.find(query)
+ end
+
+ res = res.sort(new ScoreComparator, new MEntityComparator).
+ uniq.
+ limit(10).
+ sort(new VisibilityComparator, new NameComparator)
+
+ for e in res do
+ if toolcontext.opt_no_color.value then
+ print " * {e.score}: {e.mentity.name} ({e.mentity.full_name})"
+ else
+ print " * {e.score}: {e.mentity.color} ({e.mentity.full_name})"
+ end
+ end
+ return clock.total
+end
+