<commit_before># Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# MIT License. See license.txt 

# Search
from __future__ import unicode_literals
import webnotes
import webnotes.widgets.reportview
import webnotes.widgets.query_builder
from webnotes.utils import cstr
from startup.query_handlers import standard_queries

# this is called by the Link Field
@webnotes.whitelist()
def search_link(doctype, txt, query=None, filters=None):
	search_widget(doctype, txt, query, page_len=20, filters=filters)
	webnotes.response['results'] = build_for_autosuggest(webnotes.response["values"])

# this is called by the search box
@webnotes.whitelist()
def search_widget(doctype, txt, query=None, searchfield="name", start=0, 
	page_len=50, filters=None):
	if isinstance(filters, basestring):
		import json
		filters = json.loads(filters)

	meta = webnotes.get_doctype(doctype)
	
	if query and query.split()[0].lower()!="select":
		# by method
		webnotes.response["values"] = webnotes.get_method(query)(doctype, txt, 
			searchfield, start, page_len, filters)
	elif not query and doctype in standard_queries:
		# from standard queries
		search_widget(doctype, txt, standard_queries[doctype], 
			searchfield, start, page_len, filters)
	else:
		if query:
			# custom query
			webnotes.response["values"] = webnotes.conn.sql(scrub_custom_query(query, 
				searchfield, txt))
		else:
			if isinstance(filters, dict):
				filters_items = filters.items()
				filters = []<commit_msg>[minor] fix search widget for no startup standard queries<commit_after># Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# MIT License. See license.txt 

# Search
from __future__ import unicode_literals
import webnotes
import webnotes.widgets.reportview
import webnotes.widgets.query_builder
from webnotes.utils import cstr

try:
	from startup.query_handlers import standard_queries
	startup_standard_queries = True
except ImportError:
	startup_standard_queries = False

# this is called by the Link Field
@webnotes.whitelist()
def search_link(doctype, txt, query=None, filters=None):
	search_widget(doctype, txt, query, page_len=20, filters=filters)
	webnotes.response['results'] = build_for_autosuggest(webnotes.response["values"])

# this is called by the search box
@webnotes.whitelist()
def search_widget(doctype, txt, query=None, searchfield="name", start=0, 
	page_len=50, filters=None):
	if isinstance(filters, basestring):
		import json
		filters = json.loads(filters)

	meta = webnotes.get_doctype(doctype)
	
	if query and query.split()[0].lower()!="select":
		# by method
		webnotes.response["values"] = webnotes.get_method(query)(doctype, txt, 
			searchfield, start, page_len, filters)
	elif startup_standard_queries and not query and doctype in standard_queries:
		# from standard queries
		search_widget(doctype, txt, standard_queries[doctype], 
			searchfield, start, page_len, filters)
	else:
		if query:
			# custom query
			webnotes.response["values"] = webnotes.conn.sql(scrub_custom_query(query, 
				searchfield, txt))
		else:
			if isinstance(filters, dict):
				filters_items = filters.items()
				filters = []
{'fraction_non_alphanumeric': 0.10286081645773064, 'fraction_numerical': 0.006428801028608165, 'mean_word_length': 5.621276595744681, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6481806', 'n_tokens_mistral': 1075, 'n_tokens_neox': 972, 'n_words': 263}