Skip to content
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

colophons fix #576

Merged
merged 1 commit into from
Oct 16, 2024
Merged

colophons fix #576

merged 1 commit into from
Oct 16, 2024

Conversation

khoidt
Copy link
Contributor

@khoidt khoidt commented Oct 16, 2024

Summary by Sourcery

Fix the colophon name query to handle short query strings and refactor the query logic into a separate function for better code organization. Update tests to cover the new query behavior.

Bug Fixes:

  • Fix the colophon name query to handle cases where the query string is less than three characters.

Enhancements:

  • Refactor the colophon name query into a separate function for improved readability and maintainability.

Tests:

  • Update the test for fetching colophon names to include a case for queries with less than three characters.

Copy link
Contributor

sourcery-ai bot commented Oct 16, 2024

Reviewer's Guide by Sourcery

This pull request implements improvements to the colophon name search functionality in the ebl (Electronic Babylonian Library) project. It refactors the existing code to enhance the search capabilities and adds support for collation in the query process.

Class diagram for MongoFragmentRepositoryGetExtended

classDiagram
    class MongoFragmentRepositoryGetExtended {
        +fetch_names(name_query: str) List~str~
    }
    MongoFragmentRepositoryGetExtended --> CollatedFieldQuery
    class CollatedFieldQuery {
        +value: str
    }
    class MongoFragmentRepositoryBase {
    }
    MongoFragmentRepositoryGetExtended --> MongoFragmentRepositoryBase
    note for MongoFragmentRepositoryGetExtended "Refactored fetch_names method to use _get_colophon_names_query and CollatedFieldQuery."
Loading

File-Level Changes

Change Details Files
Refactored colophon name search functionality
  • Extracted colophon name query logic into a separate function
  • Added a minimum character limit for name queries
  • Implemented collation support for name searches
ebl/fragmentarium/infrastructure/mongo_fragment_repository_get_extended.py
Added support for colophon data type in query collation
  • Defined a new data type 'colophons' in the Fields enum
  • Added collation fields for the 'colophons' data type
ebl/common/query/query_collation.py
Updated test cases for colophon name search
  • Modified a test name to include a diacritic character
  • Added a test case for short name queries
ebl/tests/fragmentarium/test_fragment_repository_colophon.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codeclimate bot commented Oct 16, 2024

Code Climate has analyzed commit d06fb38 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (75% is the threshold).

This pull request will bring the total coverage in the repository to 91.4% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @khoidt - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider providing a justification for the minimum length requirement (len(name_query) < 3) in fetch_names, or consider if this limitation is necessary. It might prevent some valid use cases.
  • In Fields.findByDataType, consider updating the error message for invalid data types to include the new 'colophons' type for completeness.
  • Good job on refactoring the colophon name query logic and extending the functionality. The code organization has improved, and the new test case with the macron character is a nice touch.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

{"$sort": {"unique_names": 1}},
{"$project": {"_id": 0, "name": "$unique_names"}},
]
if len(name_query) < 3:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider making the minimum query length configurable

While this check is a good optimization, hardcoding the value '3' might not be flexible enough for all use cases. Consider making this a configurable parameter, perhaps defined in a configuration file or as a class constant.

MIN_QUERY_LENGTH = 3  # Consider moving this to a configuration file

if len(name_query) < MIN_QUERY_LENGTH:
    return []



def has_none_values(dictionary: dict) -> bool:
return not all(dictionary.values())


def _get_colophon_names_query(name_regex: str) -> Sequence[dict]:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Add comments explaining each stage of the pipeline

The pipeline in this function is quite complex. Consider adding inline comments to explain the purpose of each stage in the pipeline. This would greatly improve readability and maintainability.

@khoidt khoidt merged commit 36d660d into master Oct 16, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant