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

Allows to pass config name to search class configuration #2

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

fullonic
Copy link
Collaborator

@fullonic fullonic commented Feb 22, 2023

Description

Updates search-related functions and the SearchCriterion object to receive a new configuration parameter: config_name. By default, we use the PostgreSQL default text search config, pg_catalog.simple.

Motivation and Context

When using PostgreSQL search, the user might need to change the default configuration. This PR makes it possible by allowing the user to specify which config he/she wants to use. For example, using the PostgreSQL extension unaccent, we can now query as:

await City.filter(name__search=ToTsQuery("paris", "public.unaccent"))

Tortoise will generate the below SQL query

'SELECT "id", "name" FROM "cities" WHERE TO_TSVECTOR(\'public.unaccent\',"name") @@ TO_TSQUERY(\'public.unaccent\',\'paris\')'

Because of the current implementation of the __search filter, inside the SearchCriterion.__init__, we extract the config_name from the function in use, in the above example ToTsQuery, to pass it to the ToTsVector function.

How Has This Been Tested?

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@fullonic fullonic force-pushed the feature/allow-pass-dictonary-to-search branch from 4978555 to 1336bf0 Compare September 13, 2023 13:04
@coveralls
Copy link

coveralls commented Jun 6, 2024

Pull Request Test Coverage Report for Build 9398386413

Details

  • 10 of 11 (90.91%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall first build on feature/allow-pass-dictonary-to-search at 87.856%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/contrib/postgres/functions.py 6 7 85.71%
Totals Coverage Status
Change from base Build 9398213175: 87.9%
Covered Lines: 5780
Relevant Lines: 6481

💛 - Coveralls

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.

2 participants