Skip to content

feat: index library collections in meilisearch [FC-0062] - #35324

Merged
bradenmacdonald merged 12 commits into
openedx:masterfrom
open-craft:navin/collection_indexing
Aug 27, 2024
Merged

feat: index library collections in meilisearch [FC-0062]#35324
bradenmacdonald merged 12 commits into
openedx:masterfrom
open-craft:navin/collection_indexing

Conversation

@navinkarkera

@navinkarkera navinkarkera commented Aug 19, 2024

Copy link
Copy Markdown
Contributor

Description

Updates rebuild_index function to include collections for indexing in meilisearch.

Supporting information

Testing instructions

import random
from openedx_learning.api import authoring as authoring_api
from openedx_learning.api import authoring_models
learning_packages = authoring_models.LearningPackage.objects.all()
for i in range(20):
    learning_id = random.choice(learning_packages)
    authoring_api.create_collection(learning_id, f"collection_{i}", None, f'description_{i}')

Deadline

None

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 19, 2024
@openedx-webhooks

openedx-webhooks commented Aug 19, 2024

Copy link
Copy Markdown

Thanks for the pull request, @navinkarkera!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch 4 times, most recently from 4aa6025 to af40d47 Compare August 20, 2024 13:51
@navinkarkera navinkarkera changed the title feat: index library collections in meillisearch feat: index library collections in meilisearch Aug 20, 2024
@navinkarkera navinkarkera changed the title feat: index library collections in meilisearch feat: index library collections in meilisearch [FC-0062] Aug 20, 2024
@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch 3 times, most recently from 8ce6b33 to 3777566 Compare August 20, 2024 14:00
@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch from 3777566 to 885ee47 Compare August 20, 2024 14:12
status_cb(f"Done! {num_blocks_done} blocks indexed across {num_contexts_done} courses and libraries.")
############## Collections ##############
status_cb("Indexing collections...")
# To reduce memory usage on large instances, split up the Collections into pages of 100 collections:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great!

@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch 2 times, most recently from 523fab9 to d605a5c Compare August 21, 2024 11:01
@navinkarkera
navinkarkera marked this pull request as ready for review August 21, 2024 11:01
@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch from 2d5d1f7 to 47db5d1 Compare August 21, 2024 14:23
@navinkarkera
navinkarkera requested a review from rpenido August 21, 2024 15:00
Comment thread requirements/edx/kernel.in Outdated
openedx-events # Open edX Events from Hooks Extension Framework (OEP-50)
openedx-filters # Open edX Filters from Hooks Extension Framework (OEP-50)
openedx-learning # Open edX Learning core (experimental)
# FIXME Remove this line after release of openedx-learning

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

num_blocks_done += len(docs)

status_cb(f"Done! {num_blocks_done} blocks indexed across {num_contexts_done} courses and libraries.")
############## Collections ##############

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to get really big.

We have a lot of local variables here, but could you try to create some inner functions like config_index(), index_libraries(), index_courses(), and index_collections()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido Not sure if it improves readability but converted some parts to inner functions.

@rpenido rpenido left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Thank you for your work, @navinkarkera!

There is a small nit in the testing instructions.

  • I tested this using the instructions from the PR, using the updated snippet:
import random
from openedx_learning.api import authoring as authoring_api
from openedx_learning.api import authoring_models
learning_packages = authoring_models.LearningPackage.objects.all()
for i in range(20):
    learning_id = random.choice(learning_packages).id
    authoring_api.create_collection(learning_id, f"collection_{i}", None, f'description_{i}')
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

Not blocking, but I think a small refactor in our indexing function would be great.

Also, we could add the description field to the searchable attributes. What do you think?

@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch 2 times, most recently from da19109 to c1edbb0 Compare August 22, 2024 09:30
@navinkarkera

Copy link
Copy Markdown
Contributor Author

@rpenido Thanks!

There is a small nit in the testing instructions.

There was an update to openedx_learning after I created this PR so missed to update the instructions. Thanks!

Also, we could add the description field to the searchable attributes. What do you think?

Updated.

@navinkarkera
navinkarkera requested a review from rpenido August 22, 2024 13:52

@rpenido rpenido left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @navinkarkera!

@pomegranited This is ready for CC review.

@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch from c1edbb0 to 51ba403 Compare August 22, 2024 15:14
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Aug 22, 2024

@pomegranited pomegranited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this and it works perfectly, using your test instructions, thank you @navinkarkera :)

But I've got a concern about this line that I'd like addressed before approving here.

Comment thread openedx/core/djangoapps/content/search/api.py
Fields.context_key: collection.learning_package.key,
}
# Just in case learning_package is not related to a library
if hasattr(collection.learning_package, 'contentlibrary'):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually the way to check if a learning package has an associated content library? It doesn't seem right..
Could you add a test for the case where a collection is associated with a learning package that is not associated with a content library, so we can be sure this logic is correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited That is a good point. I am not really sure if we have a scenario where a learning_package is not related to a library, maybe a course?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, within the context of openedx, a collection should always be related to a learning_package with a content library (courses don't have collections). I just think the hasattr mechanism is weird, and may always be true, even if collection.learning_package.contentlibrary == None.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pomegranited Ohh, I added a test with a learning package that is not associated with a library. The hasattr mechanism worked but like you said it is weird and may not work in case the attr is none, so updated to make use of try..catch DoesNotExist exception.

@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch from 51ba403 to 0e87179 Compare August 23, 2024 05:57
@navinkarkera
navinkarkera force-pushed the navin/collection_indexing branch from 0e87179 to 7664e02 Compare August 23, 2024 06:06

@pomegranited pomegranited left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Works perfectly, thank you @navinkarkera !

I also tested with your latest change on openedx-learning.

  • I tested this using the PR test instructions (with one change, line 6 of the code sample should be learning_id = random.choice(learning_packages).id)
  • I read through the code
  • I checked for accessibility issues N/A
  • Includes documentation
  • User-facing strings are extracted for translation N/A

Comment thread openedx/core/djangoapps/content/search/documents.py Outdated
Co-authored-by: Jillian <jill@opencraft.com>
@pomegranited
pomegranited force-pushed the navin/collection_indexing branch from c38a198 to ed66903 Compare August 27, 2024 05:33
@pomegranited
pomegranited force-pushed the navin/collection_indexing branch from ed66903 to 2ac22c3 Compare August 27, 2024 05:44
@bradenmacdonald
bradenmacdonald merged commit c65478e into openedx:master Aug 27, 2024
@bradenmacdonald
bradenmacdonald deleted the navin/collection_indexing branch August 27, 2024 17:45
@openedx-webhooks

Copy link
Copy Markdown

@navinkarkera 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants