How can change the searching list appearance.Like here i searched for SB01 ,but the item SB01-BH01 comes first.I want to make the searched item comes in the first one in the list.(sb01 is an item not a template)
@Fathima Please Refer this document and create your custom filter query and adding last in sql order_by the name length then your problem are resolve
example :
# searches for leads which are not converted
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def lead_query(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""
SELECT name, lead_name, company_name
FROM `tabLead`
WHERE docstatus < 2
AND ifnull(status, '') != 'Converted'
AND ({key} LIKE %(txt)s
OR lead_name LIKE %(txt)s
OR company_name LIKE %(txt)s)
{mcond}
ORDER BY
IF(LOCATE(%(_txt)s, name), LOCATE(%(_txt)s, name), 99999),
IF(LOCATE(%(_txt)s, lead_name), LOCATE(%(_txt)s, lead_name), 99999),
IF(LOCATE(%(_txt)s, company_name), LOCATE(%(_txt)s, company_name), 99999),
name, lead_name
LIMIT %(start)s, %(page_len)s
""".format(**{
'key': searchfield,
'mcond':get_match_cond(doctype)
}), {
'txt': "%{}%".format(txt),
'_txt': txt.replace("%", ""),
'start': start,
'page_len': page_len
})