Skip to content

Commit

Permalink
Implement Threebean's idea for match_all, with a few tweaks. Tests wi…
Browse files Browse the repository at this point in the history
…ll still not pass, because we need to make "contains" look for whole words, and not just parts.
  • Loading branch information
dtgay committed Jul 28, 2013
1 parent df64ba3 commit 0c4a50a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tahrir_api/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from utils import autocommit
from model import Badge, Invitation, Issuer, Assertion, Person
from sqlalchemy import create_engine, func
from sqlalchemy import create_engine, func, and_
from sqlalchemy.orm import sessionmaker, scoped_session
from datetime import (
datetime,
Expand Down Expand Up @@ -82,10 +82,10 @@ def get_badges_from_tags(self, tags, match_all=False):

if match_all:
# Return badges matching all tags
f = func.lower(Badge.tags)
for tag in tags:
f = f.contains(str(tag).lower())
badges.extend(self.session.query(Badge).filter(f).all())
# ... by doing argument-expansion on a list comprehension
badges.extend(self.session.query(Badge).filter(and_(*[
func.lower(Badge.tags).contains(str(tag).lower())
for tag in tags])))
else:
# Return badges matching any of the tags
for tag in tags:
Expand Down

0 comments on commit 0c4a50a

Please sign in to comment.