-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1c41df
commit 084813e
Showing
10 changed files
with
296 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import click | ||
from pyramid.paster import bootstrap | ||
from sqlalchemy import select, func | ||
|
||
from privatim.models import SearchableAssociatedFiles | ||
from privatim.models.file import SearchableFile | ||
from privatim.orm import Base | ||
|
||
|
||
@click.command() | ||
@click.argument('config_uri') | ||
def print_tsvectors(config_uri: str) -> None: | ||
""" | ||
Iterate over all models inheriting from SearchableAssociatedFiles | ||
and print their tsvector of searchable_text. | ||
""" | ||
env = bootstrap(config_uri) | ||
|
||
with env['request'].tm: | ||
db = env['request'].dbsession | ||
seen = set() | ||
for mapper in Base.registry.mappers: | ||
cls = mapper.class_ | ||
if issubclass(cls, SearchableAssociatedFiles) and cls not in seen: | ||
seen.add(cls) | ||
click.echo(f"\nProcessing model: {cls.__name__}") | ||
stmt = select(cls.searchable_text_de_CH) | ||
results = db.execute(stmt).fetchall() | ||
for id, tsvector in results: | ||
click.echo(f"ID: {id}") | ||
click.echo(f"TSVector: {tsvector}") | ||
click.echo("---") | ||
|
||
|
||
@click.command() | ||
@click.argument('config_uri') | ||
def print_text(config_uri: str) -> None: | ||
""" | ||
Iterate over all models inheriting from SearchableAssociatedFiles | ||
and print their tsvector of searchable_text. | ||
""" | ||
env = bootstrap(config_uri) | ||
|
||
with env['request'].tm: | ||
db = env['request'].dbsession | ||
seen = set() | ||
for mapper in Base.registry.mappers: | ||
cls = mapper.class_ | ||
if issubclass(cls, SearchableAssociatedFiles) and cls not in seen: | ||
seen.add(cls) | ||
click.echo(f"\nProcessing model: {cls.__name__}") | ||
texts2 = db.execute(select( | ||
func.string_agg(SearchableFile.extract, ' ')).select_from( | ||
cls).join(cls.files).group_by(cls.id)).all() | ||
for content in texts2: | ||
click.echo(f"text_contents: {content}") | ||
click.echo("---") | ||
|
||
|
||
@click.command() | ||
@click.argument('config_uri') | ||
def reindex(config_uri: str) -> None: | ||
|
||
env = bootstrap(config_uri) | ||
|
||
with env['request'].tm: | ||
db = env['request'].dbsession | ||
seen = set() | ||
for mapper in Base.registry.mappers: | ||
cls = mapper.class_ | ||
if issubclass(cls, SearchableAssociatedFiles) and cls not in seen: | ||
seen.add(cls) | ||
click.echo(f"\nProcessing model: {cls.__name__}") | ||
|
||
stmt = select(cls) | ||
results = db.execute(stmt).scalars().fetchall() | ||
for instance in results: | ||
assert isinstance(instance, cls) | ||
click.echo(f"\nReindexing model: {cls.__name__} with " | ||
f"title: {instance.title[:30]}") | ||
instance.reindex_files() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from privatim.models.associated_file import SearchableAssociatedFiles | ||
from privatim.orm import Base | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.