add searchable names function to data_models#427
Open
CarsonDavis wants to merge 14 commits into
Open
Conversation
…ved searchable names functions and custom definitions
edkeeble
reviewed
Jan 11, 2023
edkeeble
left a comment
Contributor
There was a problem hiding this comment.
Can you provide a test case demonstrating non-unique results? I can't replicate it with a quick test:
for c in Campaign.search({"search": "convective processes"}):
print(c.short_name, c.long_name)
>> CPEX Convective Processes Experiment
>> CPEX-AW Convective Processes Experiment – Aerosols & WindsDoes it occur when multiple fields for the same record match the search criteria?
Comment on lines
+67
to
75
| def custom_search_fields(cls): | ||
| all_model_field_names = [field.name for field in cls._meta.get_fields()] | ||
| actual_searchable_names = [ | ||
| field | ||
| for field in POSSIBLE_SEARCHABLE_FIELDS | ||
| if field.split('__')[0] in all_model_field_names | ||
| ] | ||
| return actual_searchable_names | ||
|
|
Contributor
There was a problem hiding this comment.
Rather than supporting a list of each possible search field and checking against all fields of each subclass, could we not just override search_fields on the subclasses?
e.g.
class Image(BaseModel):
...
@staticmethod
def search_fields():
return ["title"]
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Most models have a variety of possible names which can refer to an object.
short_name,long_name,aliases, etc. A user desiring to search for a campaign based on a string will expect to see a result that is matched against any of the valid name fields.This PR implements a list of possible valid name fields for each model and updates the search function to use these fields in the default search.
PROBLEMS:
Currently, the list of returned results in the queryset is not unique, and adding a
.distinct('uuid')constraint seems to massively slow down the application.