def query_performance(mysql, index, size, content, topics, unwanted_topics, user_topics, unwanted_user_topics): language = Language("en", "English") language.id = 5 # build elasticsearch query query_body = build_elastic_query(size, content, topics, unwanted_topics, user_topics, unwanted_user_topics, language, 100, 0) # build Mysql query mysql_query = mysql_fulltext_query(mysql, size, content, topics, unwanted_topics, user_topics, unwanted_user_topics, language, 100, 0) # Elasticsearch res = es.search(index=index, body=query_body) for result in res['hits']['hits']: elastic_title = result['_source']['title'] elastic_content = result['_source']['content'] published_time = result['_source']['published_time'] write_results_to_csv("elastic", elastic_title, elastic_content, published_time) # Mysql result = mysql_query.all() for mysql_result in result: mysql_title = mysql_result.title mysql_content = mysql_result.content published_time = mysql_result.published_time write_results_to_csv("mysql_full_text", mysql_title, mysql_content, published_time)
def query_performance(mysql, index, size_of_index, size, content, topics, unwanted_topics, user_topics, unwanted_user_topics): language = Language("en", "English") language.id = 5 elastic_query_body = build_elastic_query(size, content, topics, unwanted_topics, user_topics, unwanted_user_topics, language, 100, 0) mysql_query_full_text = mysql_fulltext_query(mysql, size, content, topics, unwanted_topics, user_topics, unwanted_user_topics, language, 100, 0) mysql_query_old = base_mysql_query(mysql, size, content, topics, unwanted_topics, user_topics, unwanted_user_topics, language, 100, 0) elastic_time_lst = [] elastic_returned_articles = [] for j in range(20): start = timer() res = es.search(index=index, body=elastic_query_body) elastic_returned_articles.append(len(res['hits'].get('hits'))) end = timer() elastic_time_lst.append(end - start) write_results_to_csv(size_of_index + " elastic", average_time_in_ms(elastic_time_lst), size) # #MySQL Full Text mysql_time_lst = [] mysql_returned_articles = [] for i in range(10): start = timer() result = mysql_query_full_text.all() mysql_returned_articles.append(len(result)) end = timer() mysql_time_lst.append(end - start) write_results_to_csv(size_of_index + " MySQL Full Text", average_time_in_ms(mysql_time_lst), size) # MySQL Base Version mysql_time_lst = [] mysql_returned_articles = [] for i in range(10): start = timer() result = mysql_query_old.all() mysql_returned_articles.append(len(result)) end = timer() mysql_time_lst.append(end - start) write_results_to_csv(size_of_index + " MySQL Base Version", average_time_in_ms(mysql_time_lst), size)