2018-zoekmachines-goeievraagle/backend/question.py

32 lines
722 B
Python
Raw Normal View History

2018-10-26 09:10:46 +00:00
from elasticsearch_dsl import Document, Date, Keyword, Text, Boolean
class Question(Document):
title = Text(analyzer="snowball")
2018-10-23 11:16:23 +00:00
body = Text(
analyzer="snowball",
fielddata=True,
)
category = Keyword()
date = Date()
2018-10-26 09:10:46 +00:00
answers = Text(analyzer="snowball")
dead = Boolean()
error = Boolean()
class Index:
name = "goeievraag"
def save(self, **kwargs):
return super(Question, self).save(**kwargs)
def url(self):
id_ = self.meta.id
return f"https://www.startpagina.nl/v/vraag/{id_}/"
def summary(self, length=128):
if len(self.body) > length:
return self.body[:length - 3] + "..."
return self.body