From 5d1ecb2e47f02544756f560fecc1cc03afd2d6b3 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sun, 3 Mar 2019 00:27:13 +0530 Subject: [PATCH] fix: Global Search fixes - Update title, route and published in sync_value - Update search_template for BS4 --- .../templates/includes/search_template.html | 31 +++++++++++-------- frappe/utils/global_search.py | 16 ++++++++-- frappe/www/search.py | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/frappe/templates/includes/search_template.html b/frappe/templates/includes/search_template.html index 9e0994792b..b756c96695 100644 --- a/frappe/templates/includes/search_template.html +++ b/frappe/templates/includes/search_template.html @@ -1,15 +1,15 @@

{{ title }}

{%- macro search_results_section(results, title, has_more) -%} -
+
{% if title %} -

{{ title }}

+

{{ title }}

{% endif %} {% for d in results %} -
+
{{ d.title }} -

{{ d.preview }}

+

{{ d.preview }}

{% endfor %} {% if has_more %} @@ -19,15 +19,20 @@
{%- endmacro %} -
-
- - -
+
+
+
+
+ +
+ +
+
+
+
{% if results %} diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index 76f433cf80..af38570021 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -311,16 +311,26 @@ def sync_value(value): Sync a given document to global search :param value: dict of { doctype, name, content, published, title, route } ''' - + frappe.db.multisql({ 'mariadb': '''INSERT INTO `__global_search` (`doctype`, `name`, `content`, `published`, `title`, `route`) VALUES (%(doctype)s, %(name)s, %(content)s, %(published)s, %(title)s, %(route)s) - ON DUPLICATE key UPDATE `content`=%(content)s''', + ON DUPLICATE key UPDATE + `content`=%(content)s, + `published`=%(published)s, + `title`=%(title)s, + `route`=%(route)s + ''', 'postgres': '''INSERT INTO `__global_search` (`doctype`, `name`, `content`, `published`, `title`, `route`) VALUES (%(doctype)s, %(name)s, %(content)s, %(published)s, %(title)s, %(route)s) - ON CONFLICT("doctype", "name") DO UPDATE SET `content`=%(content)s''' + ON CONFLICT("doctype", "name") DO UPDATE SET + `content`=%(content)s, + `published`=%(published)s, + `title`=%(title)s, + `route`=%(route)s + ''' }, value) def delete_for_document(doc): diff --git a/frappe/www/search.py b/frappe/www/search.py index 56b6ff4e36..e545f4840f 100644 --- a/frappe/www/search.py +++ b/frappe/www/search.py @@ -29,7 +29,7 @@ def get_search_results(text, start=0, as_html=False): for d in results: d.content = html2text(d.content) index = d.content.lower().index(text.lower()) - d.content = d.content[:index] + '' + d.content[index:][:len(text)] + '' + d.content[index + len(text):] + d.content = d.content[:index] + '' + d.content[index:][:len(text)] + '' + d.content[index + len(text):] if index < 40: start = 0