Skip to content

Commit

Permalink
Fixed a bug in subject filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Chitipothu committed Dec 31, 2013
1 parent f20b79b commit f947643
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions openlibrary/core/loanstats.py
Expand Up @@ -49,7 +49,7 @@ def solr_select(self, params):
params['fq'].append("ia_collections_id:" + self.solrescape(self.collection)) params['fq'].append("ia_collections_id:" + self.solrescape(self.collection))


if self.subject: if self.subject:
params['fq'].append(self._get_subject_filter(self.solrescape(self.subject))) params['fq'].append(self._get_subject_filter(self.subject))


if self.time_period: if self.time_period:
start, end = self.time_period start, end = self.time_period
Expand All @@ -72,12 +72,14 @@ def solrescape(self, text):
return re_solrescape.sub(r'\\\1', text) return re_solrescape.sub(r'\\\1', text)


def _get_subject_filter(self, subject): def _get_subject_filter(self, subject):
# subjects are stored as subject_key field as values like:
# ["subject:fiction", "subject:history", "place:england"]
# etc.
if ":" in subject: if ":" in subject:
type, subject = subject.split(":", 1) type, subject = subject.split(":", 1)
else: else:
type = "subject" type = "subject"
key = type + "_key" return "subject_key:%s\\:%s" % (type, self.solrescape(subject))
return "%s:%s" % (key, subject)


def solr_select_facet(self, facet_field): def solr_select_facet(self, facet_field):
facet_counts = self._get_all_facet_counts() facet_counts = self._get_all_facet_counts()
Expand Down

0 comments on commit f947643

Please sign in to comment.