get result

This commit is contained in:
Daniel Tsvetkov 2022-05-05 07:45:47 +02:00
parent ecbb2363ea
commit 5405417c64

19
main.py
View File

@ -37,10 +37,11 @@ def setup_logging_level(debug=False):
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('query', nargs='*', default="", help="freeform")
parser.add_argument('-r', dest='result', type=int, default=0)
parser.add_argument('-i', dest='case_insensitive', action='store_false')
parser.add_argument('-s', dest='is_stemming', action='store_false')
parser.add_argument('-f', dest='is_fuzzed', action='store_false')
parser.add_argument('-r', dest='results_cnt', type=int, default=DEFAULT_RESULTS_COUNT)
parser.add_argument('-c', dest='results_cnt', type=int, default=DEFAULT_RESULTS_COUNT)
parser.add_argument('--debug', dest='debug', action='store_true')
return parser.parse_args()
@ -92,11 +93,12 @@ def search(query, is_case_insensitive=True, is_stemming=True, is_fuzzed=True):
def format_results(results, results_cnt):
for result in results[:results_cnt]:
print("{} - {} - (score: {})".format(result[0].get(FIELD_EMOJI),
result[0].get(FIELD_DESCRIPTION),
result[1],
))
for idx, result in enumerate(results[:results_cnt]):
print("[{}] {} - {} - (score: {})".format(idx + 1,
result[0].get(FIELD_EMOJI),
result[0].get(FIELD_DESCRIPTION),
round(result[1], 2),
))
def main():
@ -107,7 +109,10 @@ def main():
is_stemming=args.is_stemming,
is_fuzzed=args.is_fuzzed,
)
format_results(results, results_cnt=args.results_cnt)
if args.result and 0 < args.result <= len(results):
print(results[args.result - 1][0].get(FIELD_EMOJI))
else:
format_results(results, results_cnt=args.results_cnt)
if __name__ == "__main__":