Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
a bit more logging, documenting the reason behind a test, correcting …
Browse files Browse the repository at this point in the history
…code I broke in #184.

close #255
  • Loading branch information
mfrasca committed Jan 4, 2016
1 parent 6b2ca27 commit 3c18ebf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions bauble/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def evaluate(self, env):
elif self.op in ('not', '<>', '!='):
return q.filter(a.any())
clause = lambda x: self.operation(a, x)
return q.group_by(a).having(clause(self.operands[1].express()))
logger.debug('filtering on %s(%s)' % (type(a), a))
return q.filter(clause(self.operands[1].express()))

def needs_join(self, env):
return [self.operands[0].needs_join(env)]
Expand Down Expand Up @@ -237,8 +238,9 @@ def evaluate(self, env):
# group by main ID
# apply having
main_table = q.column_descriptions[0]['type']
result = q.group_by(getattr(main_table, 'id')
).having(clause(self.operands[1].express()))
mta = getattr(main_table, 'id')
logger.debug('filtering on %s(%s)' % (type(mta), mta))
result = q.group_by(mta).having(clause(self.operands[1].express()))
return result


Expand Down Expand Up @@ -348,6 +350,9 @@ def invoke(self, search_strategy):
use ilike but this would raise an error on SQLite.
"""

logger.debug('QueryAction:invoke - %s(%s) %s(%s)' %
(type(self.domain), self.domain,
type(self.filter), self.filter))
domain = self.domain
check(domain in search_strategy._domains or
domain in search_strategy._shorthand,
Expand Down Expand Up @@ -389,6 +394,7 @@ def __repr__(self):
return "%s %s" % (self.genus_epithet, self.species_epithet)

def invoke(self, search_strategy):
logger.debug('BinomialNameAction:invoke')
from bauble.plugins.plants.genus import Genus
from bauble.plugins.plants.species import Species
result = search_strategy._session.query(Species).filter(
Expand Down Expand Up @@ -416,6 +422,7 @@ def __repr__(self):
return "%s %s %s" % (self.domain, self.cond, self.values)

def invoke(self, search_strategy):
logger.debug('DomainExpressionAction:invoke')
try:
if self.domain in search_strategy._shorthand:
self.domain = search_strategy._shorthand[self.domain]
Expand Down Expand Up @@ -505,6 +512,7 @@ def invoke(self, search_strategy):
add_meta()
"""

logger.debug('ValueListAction:invoke')
# make searches case-insensitive, in postgres use ilike,
# in other use upper()
like = lambda table, col, val: \
Expand Down Expand Up @@ -737,8 +745,9 @@ def search(self, text, session=None):
self._session = session

self._results.clear()
results = self.parser.parse_string(text.decode())
self._results.update(results.statement.invoke(self))
statement = self.parser.parse_string(text.decode()).statement
logger.debug("statement : %s(%s)" % (type(statement), statement))
self._results.update(statement.invoke(self))
logger.debug('search returns %s(%s)'
% (type(self._results), self._results))

Expand Down
2 changes: 1 addition & 1 deletion bauble/test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def test_search_by_query12(self):
f2 = Family(family=u'family2')
g2 = Genus(family=f2, genus=u'genus2')
f3 = Family(family=u'fam3')
# g3(homonym) is here just to have two matches on one value
g3 = Genus(family=f3, genus=u'genus2')
g4 = Genus(family=f3, genus=u'genus4')
self.session.add_all([f2, g2, f3, g3, g4])
Expand All @@ -401,7 +402,6 @@ def test_search_by_query12(self):
# search with or conditions
s = 'genus where genus=genus2 OR genus=genus1'
results = mapper_search.search(s, self.session)
raise SkipTest('this strange test broke during #184')
self.assertEquals(sorted([r.id for r in results]),
[g.id for g in (self.genus, g2, g3)])

Expand Down

0 comments on commit 3c18ebf

Please sign in to comment.