def test_search_params_with_multiple_body_params_long(benchmark): search = params.SearchParamSource( track=track.Track(name="benchmark-track"), params={ "index": "_all", "body": { "suggest": { "song-suggest": { "prefix": "nor", "infix": "nor", "suffix": "nor", "completion": { "field": "suggest", "fuzzy": { "fuzziness": "AUTO" } } } } }, "body-params": { "suggest.song-suggest.prefix": terms, "suggest.song-suggest.infix": terms, "suggest.song-suggest.suffix": terms } }) benchmark(search.params)
def test_passes_request_parameters(self): type1 = track.Type("type1", mapping={}, number_of_documents=3) index1 = track.Index(name="index1", auto_managed=True, types=[type1]) source = params.SearchParamSource(indices=[index1], params={ "request-params": { "_source_include": "some_field" }, "body": { "query": { "match_all": {} } } }) p = source.params() self.assertEqual(5, len(p)) self.assertEqual("index1", p["index"]) self.assertEqual("type1", p["type"]) self.assertEqual({"_source_include": "some_field"}, p["request_params"]) self.assertFalse(p["use_request_cache"]) self.assertEqual({"query": {"match_all": {}}}, p["body"])
def test_replaces_body_params(self): import copy search = params.SearchParamSource( indices=[], params={ "index": "_all", "body": { "suggest": { "song-suggest": { "prefix": "nor", "completion": { "field": "suggest", "fuzzy": { "fuzziness": "AUTO" } } } } }, "body-params": { "suggest.song-suggest.prefix": ["a", "b"] } }) # the implementation modifies the internal dict in-place (safe because we only have one client per process) hence we need to copy. first = copy.deepcopy(search.params(choice=lambda d: d[0])) second = copy.deepcopy(search.params(choice=lambda d: d[1])) self.assertNotEqual(first, second)
def test_search_params_no_body_params(benchmark): search = params.SearchParamSource(track=track.Track(name="benchmark-track"), params={ "index": "_all", "body": { "suggest": { "song-suggest": { "prefix": "nor", "completion": { "field": "suggest", "fuzzy": { "fuzziness": "AUTO" } } } } } }) benchmark(search.params)
def test_search_params_with_one_body_param_long(benchmark): search = params.SearchParamSource(indices=[], params={ "index": "_all", "body": { "suggest": { "song-suggest": { "prefix": "nor", "completion": { "field": "suggest", "fuzzy": { "fuzziness": "AUTO" } } } } }, "body-params": { "suggest.song-suggest.prefix": terms } }) benchmark(search.params)