mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 11:47:28 +01:00
Add migration to fix search weights
This commit is contained in:
parent
bae1df2e8d
commit
631ef2b10a
@ -2,6 +2,7 @@ from flask import abort, current_app
|
|||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
from sqlalchemy.orm import subqueryload
|
from sqlalchemy.orm import subqueryload
|
||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
|
from sqlalchemy_searchable import search
|
||||||
|
|
||||||
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User, Tag, \
|
from .models import db, PackageType, Package, ForumTopic, License, MinetestRelease, PackageRelease, User, Tag, \
|
||||||
ContentWarning, PackageState, PackageDevState
|
ContentWarning, PackageState, PackageDevState
|
||||||
@ -171,7 +172,7 @@ class QueryBuilder:
|
|||||||
|
|
||||||
def orderPackageQuery(self, query):
|
def orderPackageQuery(self, query):
|
||||||
if self.search:
|
if self.search:
|
||||||
query = query.search(self.search, sort=self.order_by is None)
|
query = search(query, self.search, sort=self.order_by is None)
|
||||||
|
|
||||||
if self.random:
|
if self.random:
|
||||||
query = query.order_by(func.random())
|
query = query.order_by(func.random())
|
||||||
|
29
migrations/versions/76ff303f76d8_.py
Normal file
29
migrations/versions/76ff303f76d8_.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 76ff303f76d8
|
||||||
|
Revises: 6e59ad5cc62a
|
||||||
|
Create Date: 2022-08-18 15:41:28.411877
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
from sqlalchemy_searchable import sync_trigger
|
||||||
|
|
||||||
|
revision = '76ff303f76d8'
|
||||||
|
down_revision = '6e59ad5cc62a'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
conn = op.get_bind()
|
||||||
|
|
||||||
|
options = {"weights": {"name": "A", "title": "B", "short_desc": "C", "desc": "D"}}
|
||||||
|
sync_trigger(conn, 'package', 'search_vector', ["name", "title", "short_desc", "desc"], options=options)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
conn = op.get_bind()
|
||||||
|
sync_trigger(conn, 'package', 'search_vector', ["name", "title", "short_desc", "desc"])
|
Loading…
Reference in New Issue
Block a user