def search(self,<EOL>query_string=None,<EOL>field_dictionary=None,<EOL>filter_dictionary=None,<EOL>exclude_dictionary=None,<EOL>facet_terms=None,<EOL>**kwargs):  
if MockSearchEngine._disabled:<EOL><INDENT>return {<EOL>"<STR_LIT>": <NUM_LIT:10>,<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": []<EOL>}<EOL><DEDENT>documents_to_search = []<EOL>if "<STR_LIT>" in kwargs:<EOL><INDENT>documents_to_search = MockSearchEngine.load_doc_type(self.index_name, kwargs["<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>index = MockSearchEngine.load_index(self.index_name)<EOL>for doc_type in index:<EOL><INDENT>documents_to_search.extend(index[doc_type])<EOL><DEDENT><DEDENT>if field_dictionary:<EOL><INDENT>documents_to_search = _filter_intersection(documents_to_search, field_dictionary)<EOL><DEDENT>if filter_dictionary:<EOL><INDENT>documents_to_search = _filter_intersection(documents_to_search, filter_dictionary, True)<EOL><DEDENT>if query_string:<EOL><INDENT>documents_to_search = _process_query_string(documents_to_search, query_string)<EOL><DEDENT>if "<STR_LIT>" in kwargs:<EOL><INDENT>if not exclude_dictionary:<EOL><INDENT>exclude_dictionary = {}<EOL><DEDENT>if "<STR_LIT:id>" not in exclude_dictionary:<EOL><INDENT>exclude_dictionary["<STR_LIT:id>"] = []<EOL><DEDENT>exclude_dictionary["<STR_LIT:id>"].extend(kwargs["<STR_LIT>"])<EOL><DEDENT>if exclude_dictionary:<EOL><INDENT>documents_to_search = _process_exclude_dictionary(documents_to_search, exclude_dictionary)<EOL><DEDENT>def score_documents(documents_to_search):<EOL><INDENT>"""<STR_LIT>"""<EOL>search_results = []<EOL>max_score = <NUM_LIT:0><EOL>while documents_to_search:<EOL><INDENT>current_doc = documents_to_search[<NUM_LIT:0>]<EOL>score = len([d for d in documents_to_search if d == current_doc])<EOL>if score > max_score:<EOL><INDENT>max_score = score<EOL><DEDENT>documents_to_search = [d for d in documents_to_search if d != current_doc]<EOL>data = copy.copy(current_doc)<EOL>search_results.append(<EOL>{<EOL>"<STR_LIT>": score,<EOL>"<STR_LIT:data>": data,<EOL>}<EOL>)<EOL><DEDENT>return search_results, max_score<EOL><DEDENT>search_results, max_score = score_documents(documents_to_search)<EOL>results = MockSearchEngine._paginate_results(<EOL>kwargs["<STR_LIT:size>"] if "<STR_LIT:size>" in kwargs else None,<EOL>kwargs["<STR_LIT>"] if "<STR_LIT>" in kwargs else None,<EOL>sorted(search_results, key=lambda k: k["<STR_LIT>"])<EOL>)<EOL>response = {<EOL>"<STR_LIT>": <NUM_LIT:10>,<EOL>"<STR_LIT>": len(search_results),<EOL>"<STR_LIT>": max_score,<EOL>"<STR_LIT>": results<EOL>}<EOL>if facet_terms:<EOL><INDENT>response["<STR_LIT>"] = _count_facet_values(documents_to_search, facet_terms)<EOL><DEDENT>return response<EOL>
Perform search upon documents within index