def test_web_page_index(self): global_search.update_global_search_for_all_web_pages() global_search.sync_global_search() frappe.db.commit() results = global_search.web_search('unsubscribe') self.assertTrue('Unsubscribe' in results[0].content) results = global_search.web_search(text='unsubscribe', scope="manufacturing\" UNION ALL SELECT 1,2,3,4,doctype from __global_search") self.assertTrue(results == [])
def get_search_results(text, scope=None, start=0, as_html=False): results = web_search(text, scope, start, limit=21) out = frappe._dict() if len(results) == 21: out.has_more = 1 results = results[:20] for d in results: try: d.content = html2text(d.content) index = d.content.lower().index(text.lower()) d.content = d.content[:index] + '<mark>' + d.content[index:][:len(text)] + '</mark>' + d.content[index + len(text):] if index < 40: start = 0 prefix = '' else: start = index - 40 prefix = '...' suffix = '' if (index + len(text) + 47) < len(d.content): suffix = '...' d.preview = prefix + d.content[start:start + len(text) + 87] + suffix except Exception: d.preview = html2text(d.content)[:97] + '...' out.results = results if as_html: out.results = frappe.render_template('templates/includes/search_result.html', out) return out
def get_search_results(text, start=0, as_html=False): results = web_search(text, start, limit=21) out = frappe._dict() if len(results) == 21: out.has_more = 1 results = results[:20] for d in results: d.content = html2text(d.content) index = d.content.lower().index(text.lower()) d.content = d.content[:index] + '<b>' + d.content[index:][:len(text)] + '</b>' + d.content[index + len(text):] if index < 40: start = 0 prefix = '' else: start = index - 40 prefix = '...' suffix = '' if (index + len(text) + 47) < len(d.content): suffix = '...' d.preview = prefix + d.content[start:start + len(text) + 87] + suffix out.results = results if as_html: out.results = frappe.render_template('templates/includes/search_result.html', out) return out
def test_web_page_index(self): global_search.update_global_search_for_all_web_pages() global_search.sync_global_search() frappe.db.commit() results = global_search.web_search('unsubscribe') self.assertTrue('Unsubscribe' in results[0].content)