Beispiel #1
0
	def fetch(self):
		sql = 'SELECT * FROM %s WHERE %s LIKE :q;'
		query = sql % (self._endpoint, self._default_field)
		result = g.db.execute(query, {'q': self._id}).fetchall()
		if len(result) == 0:
			raise exception.resource_not_found()
		if self._endpoint == 'author':
			self.fq.value = self.fq.value.replace('-', '*')
		meta = dict(zip(QueryFactory(self._endpoint).fields, result[0]))
		if self._endpoint == 'department':
			if meta['parent'] != '':
				self.fq.value = 'sub_department:%s' % (self._id)
		meta.update(super(FilteredContentSearchQuery, self).fetch())
		return meta
Beispiel #2
0
	def fetch(self):
		raw = self._fetch_raw()

		if len(raw['response']['docs']) == 0:
			raise exception.resource_not_found()
		else:
			doc = raw['response']['docs'][0]

		categories = [('department', 'department'), ('product', 'product'),
			('sub_department', 'department'), ('series', 'series')]
		whitelist = ['categories', 'creators', 'keywords', 'relations']
		blacklist = ['body']

		for key in whitelist:
			doc[key] = []

		for key in blacklist:
			if doc.has_key(key): del doc[key]

		if 'uri' in self.fields:
			doc['uri'] = '%s/%s/%s' % (current_app.config['API_URL'],
				self._endpoint, doc['uuid'])

		if doc.has_key('keyword') and 'keywords' in self.fields:
			kw = self._fetch_keywords(doc['keyword'])
			doc['keywords'].extend(kw)
			del doc['keyword']

		if doc.has_key('related') and 'relations' in self.fields:
			rl = self._fetch_relations(doc['related'])
			doc['relations'].extend(rl)
			del doc['related']

		if doc.has_key('author') and 'creators' in self.fields:
			au = self._fetch_authors(doc['author'])
			doc['creators'].extend(au)
			del doc['author']

		for category, endpoint in categories:
			if doc.has_key(category) and 'categories' in self.fields:
				cat_id = doc[category]
				cat = self._fetch_category(endpoint, cat_id, category)
				doc['categories'].extend(cat)
				del doc[category]

		for key in doc.keys():
			if key not in self.fields: del doc[key]

		return doc
Beispiel #3
0
def handle_resource_not_found(error):
	return exception.resource_not_found(error)