Skip to content

Commit

Permalink
issue #20 - search.py correction
Browse files Browse the repository at this point in the history
  • Loading branch information
melanie-fressard committed Nov 1, 2023
1 parent 4d6c0a2 commit d5de670
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions search.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import subprocess
import sys
import logging
import louis.db.api as api
import louis.db as db
from microbench import MicroBench, MBReturnValue, MBFunctionCall
import pandas as pd


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

class Bench(MicroBench, MBFunctionCall, MBReturnValue):
pass


outfile = "benchmarking/search_results.json"
OUTFILE = "benchmarking/search_results.json"
commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip().decode("utf-8")
basic_bench = Bench(
output_file=outfile, commit_version=commit, function_version="0.0.1"
output_file=OUTFILE, commit_version=commit, function_version="0.0.1"
)


def search(cursor, query):
"""Execute the SQL search function"""
return api.search_from_text_query(cursor, query)


@basic_bench
def init_bench(query):
"""Initialize the benchmark by calling the function search"""
connection = db.connect_db()
with db.cursor(connection) as cursor:
return search(cursor, query)
return api.search_from_text_query(cursor, query)


if __name__ == "__main__":
"""How to execute: python3 -m search.py query"""
init_bench(" ".join(sys.argv[1:]))
with open(outfile, "r") as result_file:
"""Execute the sql search function with the query passed as an argument.
How to execute: python3 -m search.py query"""
query = " ".join(sys.argv[1:])
logging.debug(f"Query is: {query}")
init_bench(query)
with open(OUTFILE, "r") as result_file:
print(pd.read_json(result_file, lines=True))

0 comments on commit d5de670

Please sign in to comment.