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 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 __init__(self: Any, index_key: str, search_string: str) -> None: self.body = { "_source": suggestion_fields([index_key]), "query": query_utils.title_suggestion_query(fields=title_fields([index_key ]), search_string=search_string), }
def test_match_in_title_info_model(): expected = { "bool": { "must": { "dis_max": { "queries": [ { "multi_match": { "query": "RA-05 string", "type": "bool_prefix", "fields": [ "title.en.ngrams", "title.en.ngrams.2_gram", "title.en.ngrams.3_gram", ], } }, { "multi_match": { "query": "RA-05 string", "type": "bool_prefix", "fields": [ "title.nb.ngrams", "title.nb.ngrams.2_gram", "title.nb.ngrams.3_gram", ], } }, { "multi_match": { "query": "RA-05 string", "type": "bool_prefix", "fields": [ "title.nn.ngrams", "title.nn.ngrams.2_gram", "title.nn.ngrams.3_gram", ], } }, { "multi_match": { "query": "RA-05 string", "type": "bool_prefix", "fields": [ "title.no.ngrams", "title.no.ngrams.2_gram", "title.no.ngrams.3_gram", ], } }, { "query_string": { "query": "*RA* *05* *string*", "fields": [ "title.en.raw", "title.nb.raw", "title.nn.raw", "title.no.raw", ], } }, ], } }, "should": [ { "match": { "provenance.code": "NASJONAL" } }, { "term": { "nationalComponent": "true" } }, { "bool": { "must": [ { "term": { "accessRights.code.keyword": "PUBLIC" } }, { "term": { "distribution.openLicense": "true" } }, ] } }, ], "boost": 10, } } result = title_query(fields=title_fields([IndicesKey.INFO_MODEL]), search_string="RA-05 string") assert json.dumps(result) == json.dumps(expected)