Skip to content

Commit

Permalink
[frontend] search improvements
Browse files Browse the repository at this point in the history
For the improvements to take effect, call ./manage.py update_indexes
and use flask-whooshee with fedora-copr/flask-whooshee#13 merged.
  • Loading branch information
clime committed Apr 13, 2016
1 parent 912f00b commit 7588cac
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions frontend/coprs_frontend/coprs/whoosheers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

from coprs import models
from coprs import whooshee

from coprs import db

@whooshee.register_whoosheer
class CoprUserWhoosheer(AbstractWhoosheer):
schema = whoosh.fields.Schema(
copr_id=whoosh.fields.NUMERIC(stored=True, unique=True),
user_id=whoosh.fields.NUMERIC(stored=True),
username=whoosh.fields.TEXT(),
username=whoosh.fields.TEXT(field_boost=2),
# treat dash as a normal character - so searching for example
# "copr-dev" will really search for "copr-dev"
coprname=whoosh.fields.TEXT(
analyzer=whoosh.analysis.StandardAnalyzer(
expression=r"\w+(-\.?\w+)*")),
expression=r"\w+(-\.?\w+)*"), field_boost=2),
chroots=whoosh.fields.TEXT(field_boost=2),
description=whoosh.fields.TEXT(),
instructions=whoosh.fields.TEXT())

Expand All @@ -34,6 +35,7 @@ def update_copr(cls, writer, copr):
user_id=copr.owner.id,
username=copr.owner.name,
coprname=copr.name,
chroots=cls.get_chroot_info(copr),
description=copr.description,
instructions=copr.instructions)

Expand All @@ -48,9 +50,26 @@ def insert_copr(cls, writer, copr):
user_id=copr.owner.id,
username=copr.owner.name,
coprname=copr.name,
chroots=cls.get_chroot_info(copr),
description=copr.description,
instructions=copr.instructions)

@classmethod
def delete_copr(cls, writer, copr):
writer.delete_by_term("copr_id", copr.id)


@classmethod
def get_chroot_info(cls, copr):
# NOTE: orm db session for Copr model is already commited at the point insert_*/update_* methods are called.
# Hence we use db.engine directly (for a new session).
result = db.engine.execute(
"""
SELECT os_release, os_version, arch
FROM mock_chroot
JOIN copr_chroot ON copr_chroot.mock_chroot_id=mock_chroot.id
WHERE copr_chroot.copr_id={0}
""".format(copr.id)
)
return ["{}-{}-{}".format(t[0], t[1], t[2]) for t in result.fetchall()]

0 comments on commit 7588cac

Please sign in to comment.