def get_jobs_from_last_week(): """Jobs created the last 7 days.""" query = Q("range", **{"_created": {"gte": "now-7d/d", "lt": "now/d"}}) & Q( "term", status="open" ) search = JobsSearch().query(query).params(size=10000).sort("-_created") return search.execute().hits
def test_indexer_deletes_record_from_es(inspire_app): record = create_record("job") record["deleted"] = True record.index(delay=False) current_search.flush_and_refresh("records-jobs") expected_records_count = 0 record_lit_es = JobsSearch().get_record(str(record.id)).execute().hits assert expected_records_count == len(record_lit_es)
def get_jobs_by_deadline(date): """Return a list of all open jobs whose deadlines match the given date. Args: date (datetime): date object. Return: list: list of open jobs matching a deadline. """ query = Q("match", **{"deadline_date": date.isoformat()}) & Q( "match", **{"status": "open"} ) results = JobsSearch().query(query).execute().hits return results
def test_reindex_all_types_records(inspire_app, cli): record_lit = create_record_factory("lit") record_aut = create_record_factory("aut") record_job = create_record_factory("job") record_con = create_record_factory("con") cli.invoke(["index", "reindex", "--all"]) current_search.flush_and_refresh("*") results_lit_uuid = LiteratureSearch().execute().hits.hits[0]["_id"] results_aut_uuid = AuthorsSearch().execute().hits.hits[0]["_id"] results_con_uuid = ConferencesSearch().execute().hits.hits[0]["_id"] results_job_uuid = JobsSearch().execute().hits.hits[0]["_id"] assert str(record_lit.id) == results_lit_uuid assert str(record_aut.id) == results_aut_uuid assert str(record_con.id) == results_con_uuid assert str(record_job.id) == results_job_uuid
def test_jobs_query_from_iq_regression(inspire_app): query_to_dict = JobsSearch().query_from_iq("kek-bf-belle-ii").to_dict() expected_query = { "query": { "bool": { "must": [ { "query_string": { "query": "kek-bf-belle-ii", "default_operator": "AND", } }, { "term": { "status": "open" } }, ] } }, "track_total_hits": True, } assert expected_query == query_to_dict
def jobs(): only_open = Q("term", status="open") return JobsSearch().query(only_open)
def assert_record_is_deleted_from_es(): current_search.flush_and_refresh("records-jobs") expected_records_count = 0 record_lit_es = JobsSearch().get_record(str(record.id)).execute().hits assert expected_records_count == len(record_lit_es)
def get_jobs_from_last_week(): """Jobs created the last 7 days.""" query = Q("range", **{"_created": {"gte": "now-7d/d", "lt": "now/d"}}) search = JobsSearch().query(query).sort("-_created") return search.execute().hits