-
Notifications
You must be signed in to change notification settings - Fork 13
Conversation
if switch_is_active('ppe'): | ||
if embed is not None: | ||
facilities_qs = facilities_qs \ | ||
.filter(Q(name__icontains=free_text_query) | | ||
Q(id=free_text_query) | | ||
Q(ppe__icontains=free_text_query) | | ||
Q(custom_text__icontains=free_text_query)) | ||
Q(custom_text__contains=[custom_text])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search works well as exact match, but I'm curious why we are using contains
instead of iexact here for an exact match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we are searching through an array for an exact match within the array. The Array.contains docs says that 'returned objects will be those where the values passed are a subset of the data' (e.g., ['3|abcd'] returns any arrays with '3|abcd' as one of the values). So it's an exact match to an item in the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The detailed documentation and test instruction is super helpful to understand the context here. Nice work! I can notice the loading speed between changing map style and updating searchable field.
The only missing piece is the updating the front-end to make only one field to be searchable - using radio button instead of checkboxes.
After speaking to Justin, we've decided to drop the limitation of only being able to search by one field, so we don't need to change to radio buttons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on this improvement and thank you for checking with Justin about the scope of this issue!
Contributors want search queries in their embedded map to only return matches for custom text if it is an exact match to custom text which they submitted. We have updated the custom_text field to use an array of strings in the format '{contributor_id}|{custom_text}' (For example, '1|abcd'). We format the free text query in the search in the same way, and find exact matches. In our previous iteration of this feature, given Contributor 1 submitted a custom text value of "ABCD" for Facility A and Contributor 2 submitted a custom text value of "ABCD" for Facility B, searching for "D" in Contributor 1's map could return both Facility A and Facility B. In the current version, searching "D" would return no matches; and searching "ABCD" in Contributor 1's map would return only Facility A.
67bdc7d
to
827fbbd
Compare
Thank you for reviewing! |
Overview
Contributors want search queries in their embedded map to only return
matches for custom text if it is an exact match to custom text which
they submitted.
We have updated the custom_text field to use an array of strings in the
format '{contributor_id}|{custom_text}' (For example, '1|abcd'). We
format the free text query in the search in the same way, and find exact
matches.
In our previous iteration of this feature, given Contributor 1 submitted
a custom text value of "ABCD" for Facility A and Contributor 2
submitted a custom text value of "ABCD" for Facility B, searching for
"D" in Contributor 1's map could return both Facility A and Facility B.
In the current version, searching "D" would return no matches; and
searching "ABCD" in Contributor 1's map would return only Facility A.
Custom text was being reindexed each time the embed config was updated,
which is a lengthy process because we need to reindex custom text for all
facilities for the contributor each time. The embed config view has been updated to
compare the previous searchable column_names to the new searchable column_names,
and only run if the searchable column_names have been updated.
Connects #1652
Demo
Previous
custom_text
:Updated
custom_text
:After preventing the custom_text from reindexing on every save, there is significant difference in speed
between updating when there has been a searchability change and when there has not:
Updating searchable fields (causes reindexing): 532.80 ms
Updating map style (does not cause reindexing): 52.45 ms
Notes
We initially planned to limit contributors to one searchable field. However, due to using an array for the custom text, it doesn't add any additional complexity to the current design to allow multiple searchable fields, so we have decided not to limit the number of searchable fields at this time.
Testing Instructions
develop
, sign in as c2@example.com, submit a list with custom fields oar-extra-fields.csv and fully process it. Assign deluxe embed permissions to c2@example.com../scripts/manage shell_plus
and thenFacilityIndex.objects.distinct('custom_text').values('custom_text')
. You will see a list of custom text values../scripts/manage migrate
. The migrations should succeed../scripts/manage shell_plus
and thenFacilityIndex.objects.distinct('custom_text').values('custom_text')
. You will see a list of array-formatted custom text values. No values should have been lost.oar-extra-fields-alt.csv, and fully process the it. Assign deluxe embed permissions to c3@example.com.
./scripts/manage shell_plus
and thenFacilityIndex.objects.distinct('custom_text').values('custom_text')
. You will see a list of custom text values, which should now include the values from c3@example.com's list.Checklist
fixup!
commits have been squashed