Skip to content

Commit

Permalink
11616 ppr api search no duplicates (#880)
Browse files Browse the repository at this point in the history
* PPR search results bug fix: no duplicate registrations.

Signed-off-by: Doug Lovett <doug@diamante.ca>

* PPR search results bug fix: no duplicate registrations.

Signed-off-by: Doug Lovett <doug@diamante.ca>
doug-lovett authored Jul 27, 2022
1 parent 66e1655 commit 59d658c
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions ppr-api/src/ppr_api/models/search_result.py
Original file line number Diff line number Diff line change
@@ -104,23 +104,8 @@ def update_selection(self, search_select, account_name: str = None, callback_url
}
detail_response['payment'] = payment

results = self.search_response
new_results = []
similar_count = 0
self.search_select = self.set_search_selection(search_select)
# Use the same order as the search selection match list in the registration list.
for select in self.search_select:
if select['matchType'] == model_utils.SEARCH_MATCH_EXACT or \
('selected' not in select or select['selected']):
reg_num = select['baseRegistrationNumber']
for result in results:
if reg_num == result['financingStatement']['baseRegistrationNumber']:
new_results.append(result)
if result['matchType'] == model_utils.SEARCH_MATCH_SIMILAR:
similar_count += 1
break

self.similar_match_count = similar_count
new_results = self.build_details()
# current_app.logger.debug('saving updates')
# Update summary information and save.
detail_response['similarResultsSize'] = self.similar_match_count
@@ -139,6 +124,31 @@ def update_selection(self, search_select, account_name: str = None, callback_url
self.callback_url = current_app.config.get('UI_SEARCH_CALLBACK_URL')
self.save()

def build_details(self):
"""Generate the search selection details from the search selection order without duplicates."""
results = self.search_response
new_results = []
similar_count = 0
# Use the same order as the search selection match list in the registration list.
for select in self.search_select:
if select['matchType'] == model_utils.SEARCH_MATCH_EXACT or \
('selected' not in select or select['selected']):
if select['matchType'] != model_utils.SEARCH_MATCH_EXACT:
similar_count += 1
reg_num = select['baseRegistrationNumber']
found = False
if new_results: # Check for duplicates.
for match in new_results:
if match['financingStatement']['baseRegistrationNumber'] == reg_num:
found = True
if not found: # No duplicates.
for result in results:
if reg_num == result['financingStatement']['baseRegistrationNumber']:
new_results.append(result)
break
self.similar_match_count = similar_count
return new_results

def set_search_selection(self, search_select):
"""Replace the request items with the matching search query items so selection is complete for report TOC."""
original_select = self.search.search_response

0 comments on commit 59d658c

Please sign in to comment.