def add_search_string(self: Any, param: str) -> Any:
     self.query["dis_max"]["queries"].append(
         query_utils.title_exact_match_query(
             fields=title_fields(
                 [IndicesKey.EVENTS, IndicesKey.PUBLIC_SERVICES]),
             search_string=param,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.title_query(
             fields=title_fields(
                 [IndicesKey.EVENTS, IndicesKey.PUBLIC_SERVICES]),
             search_string=param,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.organization_and_keyword_query(param))
     self.query["dis_max"]["queries"].append(
         query_utils.description_query(
             fields=description_fields(
                 [IndicesKey.EVENTS, IndicesKey.PUBLIC_SERVICES]),
             search_string=param,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.simple_query_string(
             fields=fulltext_fields(
                 [IndicesKey.EVENTS, IndicesKey.PUBLIC_SERVICES]),
             search_string=param,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.query_string(
             fields=fulltext_fields(
                 [IndicesKey.EVENTS, IndicesKey.PUBLIC_SERVICES]),
             search_string=param,
         ))
 def add_search_string(self: Any, search_string: str) -> Any:
     self.query["dis_max"]["queries"].append(
         query_utils.title_exact_match_query(fields=title_fields(
             [IndicesKey.CONCEPTS]),
                                             search_string=search_string))
     self.query["dis_max"]["queries"].append(
         query_utils.title_query(
             fields=title_fields([IndicesKey.CONCEPTS]),
             search_string=search_string,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.organization_and_keyword_query(search_string))
     self.query["dis_max"]["queries"].append(
         query_utils.description_query(
             fields=description_fields([IndicesKey.CONCEPTS]),
             search_string=search_string,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.simple_query_string(
             fields=fulltext_fields([IndicesKey.CONCEPTS]),
             search_string=search_string,
         ))
     self.query["dis_max"]["queries"].append(
         query_utils.query_string(
             fields=fulltext_fields([IndicesKey.CONCEPTS]),
             search_string=search_string,
         ))
def test_query_string():
    expected = {
        "bool": {
            "must": {
                "query_string": {
                    "query": "*mange* *bekker*"
                }
            },
            "should": [
                {
                    "match": {
                        "provenance.code": "NASJONAL"
                    }
                },
                {
                    "term": {
                        "nationalComponent": "true"
                    }
                },
                {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "accessRights.code.keyword": "PUBLIC"
                                }
                            },
                            {
                                "term": {
                                    "distribution.openLicense": "true"
                                }
                            },
                        ]
                    }
                },
            ],
            "boost":
            0.001,
        }
    }

    result = query_string(search_string="mange bekker", )

    assert json.dumps(result) == json.dumps(expected)
def test_query_string_with_fields():
    expected = {
        "bool": {
            "must": {
                "query_string": {
                    "query":
                    "*mange* *bekker*",
                    "fields": [
                        "accessRights.code",
                        "accessRights.prefLabel.*^3",
                        "description.*",
                        "distribution.format",
                        "distribution.title.*",
                        "expandedLosTema.*",
                        "keyword.*^2",
                        "objective.*",
                        "publisher.name^3",
                        "publisher.prefLabel^3",
                        "subject.altLabel.*",
                        "subject.definition.*",
                        "subject.prefLabel.*",
                        "theme.title.*",
                        "title.*^3",
                    ],
                }
            },
            "should": [
                {
                    "match": {
                        "provenance.code": "NASJONAL"
                    }
                },
                {
                    "term": {
                        "nationalComponent": "true"
                    }
                },
                {
                    "bool": {
                        "must": [
                            {
                                "term": {
                                    "accessRights.code.keyword": "PUBLIC"
                                }
                            },
                            {
                                "term": {
                                    "distribution.openLicense": "true"
                                }
                            },
                        ]
                    }
                },
            ],
            "boost":
            0.001,
        }
    }

    result = query_string(
        search_string="mange bekker",
        fields=fulltext_fields([IndicesKey.DATA_SETS]),
    )
    assert json.dumps(result) == json.dumps(expected)