fixed order by for common queries, should be ordered based on startswith match and then alphabetical order for fuzzy match

This commit is contained in:
Anand Doshi
2012-11-21 18:00:22 +05:30
parent f8c5960cc2
commit b45cbda7fa
3 changed files with 74 additions and 57 deletions

View File

@@ -22,7 +22,11 @@ erpnext.utils.profile_query = function() {
from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \
concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
order by name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when concat_ws(' ', first_name, middle_name, last_name) like \"%s%%\" \
then 0 else 1 end, \
name asc limit 50";
};
// searches for active employees
@@ -30,7 +34,10 @@ erpnext.utils.employee_query = function() {
return "select name, employee_name from `tabEmployee` \
where status = 'Active' and docstatus < 2 and \
(%(key)s like \"%s\" or employee_name like \"%%%s\") \
order by name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when employee_name like \"%s%%\" then 0 else 1 end, \
name limit 50";
};
// searches for leads which are not converted
@@ -38,5 +45,9 @@ erpnext.utils.lead_query = function() {
return "select name, lead_name, company_name from `tabLead` \
where docstatus < 2 and ifnull(status, '') != 'Converted' and \
(%(key)s like \"%s\" or lead_name like \"%%%s\" or company_name like \"%%%s\") \
order by lead_name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when lead_name like \"%s%%\" then 0 else 1 end, \
case when company_name like \"%s%%\" then 0 else 1 end, \
lead_name asc limit 50";
};