only extract fulltext if fulltext key is defined

This commit is contained in:
j 2019-12-01 16:17:58 +01:00
parent 96912f14b0
commit 44b4f092d1

View file

@ -27,6 +27,7 @@ class FulltextMixin:
return es return es
def extract_fulltext(self): def extract_fulltext(self):
if self.file:
if self.extension == 'pdf': if self.extension == 'pdf':
return extract_text(self.file.path) return extract_text(self.file.path)
elif self.extension in ('png', 'jpg'): elif self.extension in ('png', 'jpg'):
@ -38,7 +39,11 @@ class FulltextMixin:
def delete_fulltext(self): def delete_fulltext(self):
res = self.elasticsearch().delete(index=self._ES_INDEX, doc_type='document', id=self.id) res = self.elasticsearch().delete(index=self._ES_INDEX, doc_type='document', id=self.id)
def has_fulltext_key():
return bool([k for k in settings.CONFIG['documentKeys'] if k.get('fulltext')])
def update_fulltext(self): def update_fulltext(self):
if self.has_fulltext_key():
text = self.extract_fulltext() text = self.extract_fulltext()
if text: if text:
doc = { doc = {