diff --git a/api/namex/resources/requests.py b/api/namex/resources/requests.py index 51f11859c..0aaf118a4 100644 --- a/api/namex/resources/requests.py +++ b/api/namex/resources/requests.py @@ -1438,7 +1438,8 @@ def get(nr, choice, *args, **kwargs): @api.route('/possible-conflicts/', methods=['GET', 'OPTIONS']) class PossibleConflicts(Resource): START = 0 - ROWS = 1000 + ROWS = 50 + STRICT = False @staticmethod @cors.crossdomain(origin='*') @@ -1459,7 +1460,8 @@ class PossibleConflicts(Resource): def get(name): start = request.args.get('start', PossibleConflicts.START) rows = request.args.get('rows', PossibleConflicts.ROWS) - results = SolrHlpers.get_possible_conflicts(name, start=start, rows=rows) + strict = request.args.get('strict', PossibleConflicts.STRICT) + results = SolrHlpers.get_possible_conflicts(name, start=start, rows=rows, strict=strict) return make_response(jsonify(results), 200) diff --git a/api/namex/services/solr/solr_client.py b/api/namex/services/solr/solr_client.py index 3314b76a2..fd06e4d02 100644 --- a/api/namex/services/solr/solr_client.py +++ b/api/namex/services/solr/solr_client.py @@ -62,11 +62,12 @@ def search_nrs(cls, query_value, start=0, rows=10): @classmethod - def get_possible_conflicts(cls, name, start=0, rows=100): + def get_possible_conflicts(cls, name, start=0, rows=100, strict=True): request_json = { 'query': { 'value': name }, 'start': start, - 'rows': rows + 'rows': rows, + 'strict': strict } token = cls._get_bearer_token() diff --git a/api/namex/services/solr/solr_helpers.py b/api/namex/services/solr/solr_helpers.py index fb64457e7..92994310a 100644 --- a/api/namex/services/solr/solr_helpers.py +++ b/api/namex/services/solr/solr_helpers.py @@ -63,7 +63,7 @@ def _conflicts_post_process(cls, q_data, query_name): exact_matches = [] similar_matches = [] histories = [] - + total_results = q_data.get('searchResults', {}).get('totalResults', 0) for rcd in q_data.get('searchResults', {}).get('results', []): nm = cls._get_name_without_designation(rcd.get('name')) if nm == query_name: @@ -85,7 +85,8 @@ def _conflicts_post_process(cls, q_data, query_name): return { 'names': similar_matches, 'exactNames': exact_matches, - 'histories': histories} + 'histories': histories, + 'total': total_results} def normalize_words(word): """ @@ -139,13 +140,13 @@ def _get_name_without_designation(cls, name): return ' '.join(filtered_words) @classmethod - def get_possible_conflicts(cls, name, start=0, rows=100): + def get_possible_conflicts(cls, name, start=0, rows=100, strict=True): # q_name = cls._name_pre_processing(name) q_name = name.lower().strip() # Keep the raw query for Solr ranking/boosts. Skip-word filtering for # match prep happens in namex-solr-api via DESIGNATIONS. stripped_name = cls._get_name_without_designation(q_name) - candidates = SolrClient.get_possible_conflicts(q_name, start, rows) + candidates = SolrClient.get_possible_conflicts(q_name, start, rows, strict) return cls._conflicts_post_process(candidates, stripped_name)