-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Support of including blog in the website search #2136
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
base: main
Are you sure you want to change the base?
Conversation
83133b1
to
4f9e4bf
Compare
I was given tacit approval (lack of pushback) from the website WG to use this approach. I plan on working on this at the DjangoCon Africa sprints (Aug 14 & 15), but if anyone wants to complete it before that, please do! |
4f9e4bf
to
2bf75cd
Compare
I'm going to try to clean up the commits shortly here. |
a9a4f8a
to
837e808
Compare
Cleaned up the commits. Please let me know if any other changes are necessary. |
docs/models.py
Outdated
path = reverse_path(url_name, kwargs=kwargs) | ||
request = RequestFactory().get(path, HTTP_HOST=www_host) | ||
body = resolve(path).func(request).render().text | ||
# Need to parse the body element. |
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.
Forgot this TODO yet.
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.
@bmispelon do you have any good ideas here?
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 is a fantastic PR, thanks for submitting it! It addresses a real issue that's been plaguing the site for a long time, and as far as PR go, it's a really high quality one, kudos 👏🏻
Of course because I'm me I'll always find something to complain about so I've left a few comments ranging from improvement suggestions to open questions.
I'll note that I have not tested the code locally (yet). I'm still working on getting the preview server up and running and I think this PR would be a great candidate for it.
docs/tests/test_models.py
Outdated
cls.document_index, cls.document_view, cls.document_detail = ( | ||
cls.release.documents.order_by("path") | ||
) |
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 will break if/when more views are added to _sync_views_to_db()
, right?
I'd suggest breaking the single test_document_url()
method into three separate tests then.
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.
Judging from the rest of the tests, it seems like there's an effort to keep them efficient. It may make more sense as two separate tests, one for the old document_url
and then a new one for the DocumentationCategory.WEBSITE
branch. Let me know if you disagree.
docs/models.py
Outdated
] | ||
if not www_hosts or not (www_host := www_hosts[0]): | ||
return | ||
synced_views = [ |
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.
I think this should live in a constant at the top level of a module (I'll let you decide which module makes more sense 😁 )
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.
If we're moving this from the code away from the usage logic, then we should use a dataclass
so it's not relying on positional arguments. That gets a bit more verbose and likely could go in an entirely separate module.
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.
May be side-stepped due to #2136 (comment)
docs/models.py
Outdated
path = reverse_path(url_name, kwargs=kwargs) | ||
request = RequestFactory().get(path, HTTP_HOST=www_host) | ||
body = resolve(path).func(request).render().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.
That's a lot of stuff going on in such a few lines: you make it look deceptively simple 😁
I'm curious: did you try other approaches before settling on this? I'm a bit worried that the whole www_host
logic could be a bit brittle. If we're calling the view function directly anyway, can we skip setting the host on the request object?
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 is definitely for a reason, but let me try once more and better document the weirdness.
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.
Okay, so the simplest we can get it is to use get_template("aggregator/ecosystem.html").render()
. However, that does sort of open us to the problem of the view (which is defined in the urls.py) of using a different template or implementation than expected. However, using this approach eliminates the need to get the host which eliminates having the search the ALLOWED_HOSTS setting. So I think it's worth it. Let me know what you think.
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.
I like the move to a dataclass
for SearchableView
, nice one 👍🏻
I think we can go further and delegate the nitty-gritty details of getting a "document"'s URL and content to that class.
I've got grand ideas of generalizing this and having a collection of searchable/indexable models (sphinx document, blog, template view, flat page, ...) but that'd make the scope of this PR explode and I'd rather see this shipped. We can always iterate.
Other than that I left a question about the new support_end
. I think we should be conservative with adding new fields and would like to explore reusing existing ones, to minimize the combinatorial explosion of possible model states. If we have to keep support_end
, would it be possible for the existing DocumentRelease
to get a sensible default assigned to them with a data migration (we have 100 of them in production, it'd be a shame if we had to go and back-populate them by hand).
Thanks again for your work on this!
docs/models.py
Outdated
support_end = models.DateField( | ||
null=True, | ||
blank=True, | ||
help_text="The end of support for this release of Django.", | ||
) |
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.
Do we need a dedicated field for this, why couldn't we get the information from release.eol_date
instead?
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 is why we do code reviews. Let me get this switched over.
Can you review this PR based on this latest change in the search docs #2192 |
@pauloxnet I don't see anything obvious that would cause a problem. As long as #2192 didn't change how the search data needs to be stored, then this PR won't be impacted. The hack that is this PR is to insert search-able data and point it to the blog or ecosystem page. |
I was indirectly suggesting using the approach outlined in the documentation, which involves delegating the generation of search vectors to a generated field. I'm sorry I don't have the time to do a more thorough review of this PR (I'm recuperating from my Django sprints). 😅 |
@pauloxnet I think you can agree there's value in shipping functionality rather than perfecting the approach. If that suggestion is more of a, "hey we need to conform to this new standard", I can make the changes. If it's a "it'd be cool if it did this" type suggestion, I'm going to push for shipping something first. |
My comment was, rather, I saw that you started this PR before the docs search improvement with GeneratedField, and, not having time to do a full review of the PR, I tried to point it out in this PR. No intent of perfectionism. |
396050c
to
ad94998
Compare
The blog results should have a property of whether it is included in the search results. We should also limit the blogs that are searchable for a version of Django based on the support end. This will allow us to limit the inclusion of blog posts in the search based on the time the entry was created, keeping the search results relevant to that version of Django. * Added is_searchable and made published accept datetime cut-off parameter. * Used Entry.get_absolute_url to encapsulate www host. * Extracted get_search_config helper function. Co-authored-by: Baptiste Mispelon <[email protected]>
d9d40ab
to
ec0d063
Compare
@sarahboyce identified a problem outside of the PR in that the |
Want to add that there is a little bit more here. We only update the docs for the search if there are changes to the docs. This means only when the So we might want to have that the blog/website entries can be created without changes being required on the |
@sarahboyce and I discussed this PR. We arrived at the following conclusions:
|
This is ready for a hopefully final review. Can I provide a script to run on production to batch update blog posts? |
You mean a data migration? Sure you can add one to the PR 😁 I'm hoping to be able to review this tomorrow during Mr Triplett's office hours, so you have time to push a few more commits. |
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.
Thank you for all the work on this Tim!
I did some testing and have reviewed - this looks great ⭐
I created a separate issue around the UI: #2266
It's likely something like update_docs --force --language=en
needs to be run in order to have some older versions get the blog entries and ecosystem page (once the blogs are marked as searchable)
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.
What an excellent PR, outstanding work Tim! 💚
I feel you deserve a prize for this 🙃
Anyway, I only found a nothingburger of a nitpick, the PR is good to go as far as I'm concerned.
Let's 🚢 this!
Co-authored-by: Baptiste Mispelon <[email protected]>
2ef9631
to
ee63cfc
Compare
@bmispelon I don't agree with using a data migration to bulk update the entries. I have primary keys and if we put it in a data migration, we run the risk of updating data in non-production environments unexpectedly causing weird issues that are difficult to debug. Edit: Considering there are only 22, I can do them manually after it's been deployed.
|
Oh, so the script is just:
? |
Oh, no. It was just "Tim's picks". If others want to add more, that's fine, but figured we could start with those. |
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.
I've tested this locally and it works great!
I'm happy to merge, would you prefer to squash all the commits, or do you think it makes sense to keep some of them separate?
Also, do you want to add a couple dozen "Co-authored: Tim Schilling" to the commit message for good measure? 😁
I was assuming you'd use the squash and merge option. I can squash them in a bit though.
|
Unsure how much of an issue this would be but be aware that blog items that currently exist in https://www.djangoproject.com/sitemap.xml would now also exist in https://docs.djangoproject.com/sitemap-en.xml Fixing this should be relatively simple 🤔 |
Can cherry-pick 932d8ce onto this PR 👍 |
The blog results should have a property of whether it is included in the search results. We should also limit the blogs that are searchable for a version of Django based on the support end. This will allow us to limit the inclusion of blog posts in the search based on the time the entry was created, keeping the search results relevant to that version of Django.
This is a WIP yet. I'm opening the draft PR to solicit early feedback on the approach. I'm thinking we'll re-use theDocumentationCategory.WEBSITE
in place of "weblog".