Example #1
0
def run_search(dict_file, postings_file, queries_file, results_file):
    """
    Using the given dictionary file and postings file,
    perform searching on the given queries file and output the results to a file
    """
    print('Running search on the queries...')

    dictionaries = Dictionaries(dict_file)
    dictionaries.load()
    postings = Postings(postings_file)
    searcher = Searcher(dictionaries, postings)

    result_string = ''
    with open(queries_file, 'r') as f, open(results_file, 'w') as o:
        for i, query in enumerate(f):
            searcher.set_query(query.strip())
            output = searcher.evaluate_query()
            result_string += output.strip() + '\n'
            searcher.clear_postings()
        f.close()
        o.write(result_string.strip())
        o.close()