# Path: pyeqs/dsl/query_string.py
# class QueryString(dict):
# 
#     def __init__(self, query, fields=None, default_field=None, tie_breaker=None, use_dis_max=None):
#         super(QueryString, self).__init__()
#         self.query = query
#         self.fields = fields
#         self.default_field = default_field
#         self.tie_breaker = tie_breaker
#         self.use_dis_max = use_dis_max
#         self["query_string"] = self._build_dict()
# 
#     def _build_dict(self):
#         query_string = {"query": self.query}
#         if self.fields is not None:
#             query_string["fields"] = self.fields
#         elif self.default_field is not None:
#             query_string["default_field"] = self.default_field
#         if self.use_dis_max is not None:
#             query_string["use_dis_max"] = self.use_dis_max
#         if self.tie_breaker is not None:
#             query_string["tie_breaker"] = self.tie_breaker
#         return query_string
# 
# Path: tests/helpers.py
# def homogeneous(a, b):
#     json.dumps(a, sort_keys=True).should.equal(json.dumps(b, sort_keys=True))


from pyeqs.dsl import QueryString
from tests.helpers import homogeneous
    # Then I see the appropriate JSON
    results = {
        "query_string": {
            "query": "foo",
            "fields": ["bar"],
            "tie_breaker": 0.05,
            "use_dis_max": True
        }
    }

    homogeneous(t, results)


def test_query_string_with_default_field():
    """
    Create Query String Block with default_field instead of fields
    """
    # When we create a query string using a default_field
    t = QueryString("foo", default_field="bar", use_dis_max=True, tie_breaker=0.05)

    # Then we see the appropriate JSON
    results = {
        "query_string": {
            "query": "foo",
            "default_field": "bar",
            "tie_breaker": 0.05,
            "use_dis_max": True
        }
    }


# Path: pyeqs/dsl/query_string.py
# class QueryString(dict):
# 
#     def __init__(self, query, fields=None, default_field=None, tie_breaker=None, use_dis_max=None):
#         super(QueryString, self).__init__()
#         self.query = query
#         self.fields = fields
#         self.default_field = default_field
#         self.tie_breaker = tie_breaker
#         self.use_dis_max = use_dis_max
#         self["query_string"] = self._build_dict()
# 
#     def _build_dict(self):
#         query_string = {"query": self.query}
#         if self.fields is not None:
#             query_string["fields"] = self.fields
#         elif self.default_field is not None:
#             query_string["default_field"] = self.default_field
#         if self.use_dis_max is not None:
#             query_string["use_dis_max"] = self.use_dis_max
#         if self.tie_breaker is not None:
#             query_string["tie_breaker"] = self.tie_breaker
#         return query_string
# 
# Path: tests/helpers.py
# def homogeneous(a, b):
#     json.dumps(a, sort_keys=True).should.equal(json.dumps(b, sort_keys=True))


# Path: tests/unit/test_query_string.py
from pyeqs.dsl import QueryString
from tests.helpers import homogeneous

    # Then I see the appropriate JSON
    results = {
        "query_string": {
            "query": "foo",
            "fields": ["bar"],
            "tie_breaker": 0.05,
            "use_dis_max": True
        }
    }

    homogeneous(t, results)


def test_query_string_with_default_field():
    """
    Create Query String Block with default_field instead of fields
    """
    # When we create a query string using a default_field
    t = QueryString("foo", default_field="bar", use_dis_max=True, tie_breaker=0.05)

    # Then we see the appropriate JSON
    results = {
        "query_string": {
            "query": "foo",
            "default_field": "bar",
            "tie_breaker": 0.05,
            "use_dis_max": True
        }
    }


    homogeneous(t, results)