-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic search backend #67 #76
Conversation
f652cb6
to
5c48d38
Compare
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.
overall looks good, and I appreciate the amount of work that's gone into powering this (new && different) search 👍
Mostly minor stuff, but happy to touch base about what I'm imagining is a too-fuzzy search 😁
arches_lingo/views/trees.py
Outdated
] | ||
|
||
# Todo: filter by nodegroup permissions | ||
return JSONResponse(data) |
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.
This has been altered in #79 to return more data about the query
2308eef
to
7df77dc
Compare
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.
overall looks good and works well! just some minor code style stuff really
arches_lingo/views/api/concepts.py
Outdated
page = paginator.get_page(page_number) | ||
|
||
data = [] | ||
if page: |
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.
nit: instead of control flow based on presence/absence of a pagintor page, can it based on the data fed into the paginator?
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 ConceptBuilder does queries to build a tree (or gets the cached one). If there are no search results, there's no need to build a tree, we can just quickly return empty. That was my thinking. I'm not exactly sure what you're suggesting as an alternative. I can clarify this to deindent a little bit.
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.
ya, I've not put a breakpoint to see if this holds up but
concept_query = concept_query.values_list("concept_id", flat=True).distinct()
returns something that will either have a length or not?
Since page_number
looks like it will always have a value, the only time there shouldn't be a page is when there's not data. Admittedly this is my assumption.
So instead of if page:
, can it be if len(concept_query): ( or whatever its new name is )
?
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.
Yeah I can signpost better. But we can't evaluate the queryset too early or we'll unnecessarily fetch lots of objects before doing the pagination to slim down the results.
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 case the implicit booleanness of the Page object is too opaque, I'll change it to if not len(page)
to clarify it's an iterable of objects.
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.
Actually, it saves one query in the no-data path to check page.count
, which seems like something I might ask on the Django forum about because len()
should work the same way. So I'll do that.
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.
Oops, this should be .count on the paginator, not the page.
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.
arches_lingo/views/api/concepts.py
Outdated
page = paginator.get_page(page_number) | ||
|
||
data = [] | ||
if page: |
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.
ya, I've not put a breakpoint to see if this holds up but
concept_query = concept_query.values_list("concept_id", flat=True).distinct()
returns something that will either have a length or not?
Since page_number
looks like it will always have a value, the only time there shouldn't be a page is when there's not data. Admittedly this is my assumption.
So instead of if page:
, can it be if len(concept_query): ( or whatever its new name is )
?
concept_query = VwLabelValue.objects.all().order_by("concept_id") | ||
concept_ids = concept_query.values_list("concept_id", flat=True).distinct() | ||
|
||
paginator = Paginator(concept_ids, items_per_page) |
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.
That way, this code gets reduced to something like:
if not concept_ids:
# No results: don't bother building the concept tree.
return JSONResponse([])
paginator = Paginator(concept_ids, items_per_page)
page = paginator.get_page(page_number)
builder = ConceptBuilder()
return JSONResponse([
builder.serialize_concept(str(concept_uuid), parents=True, children=False)
for concept_uuid in page
])
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.
Yeah, as I mentioned above, it would be a pessimization to evaluate the queryset before the paginator slices it. We need to delegate that to the paginator.
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.
looks good 👍
Trust the concept value instead.
28dac8e
to
89ef29f
Compare
Thanks for the review! |
Add basic search backend at api/search. Closes #67
GET params:
All are optional. If you don't provide a search term then the cached hierarchies are rebuilt. A use case for this might be some sort of "preflight" request to warm the cache when the search page loads and before the user interacts with the search input. All of this is up for discussion. The default cache life is 5 minutes and is configurable.
Demo
http://127.0.0.1:8000/api/search?term=oss
Result
Testing instructions
TODO: