我这样做了吗?我试图在这个方法中从索引中删除一个实体,这是我第一次尝试,所以我不知道它是否有效:
def get(self):
timeline = datetime.now () - timedelta (days = 59)
edge = datetime.now () - timedelta (days = 60)
ads = Ad.all().filter("published =", True).filter("modified <", timeline).filter("url IN", ['www.koolbusiness.com']).filter("modified >", edge)
for ad in ads:
if ad.title:
subject= ad.title
else:
subject = 'Reminder'
message = mail.EmailMessage(sender='admin@koolbusiness.com', subject=subject)
reminder = 'You can renew your advertisement'
message.body = ('%s \nhttp://www.koolbusiness.com/vi/%d %s') % (reminder, ad.key().id(), '\nIf you like, you can also add us on Facebook \nhttp://apps.facebook.com/koolbusiness')
message.to=ad.email
message.bcc='fridge@koolbusiness.com'
message.send()
index = search.Index(name='ad',
consistency=Index.PER_DOCUMENT_CONSISTENT)
index.remove(str(ad.key())
上述代码应该发送超时广告提醒,然后从索引中删除。如果广告被更新,则可以再次将其添加到索引中。它会起作用吗?
答案 0 :(得分:2)
您的代码应该有效,但恕我直言,最好将广告标记为已过期,而不是将其从索引中删除。这样可以节省重新制作重新投放广告的需求,并且可以让您更好地审核广告。