1
我正在做對嗎?我想從這個方法刪除索引中的實體,這是我第一次嘗試,所以我不知道,如果它的工作:從索引刪除實體?
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='[email protected]', 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='[email protected]'
message.send()
index = search.Index(name='ad',
consistency=Index.PER_DOCUMENT_CONSISTENT)
index.remove(str(ad.key())
上面的代碼應該發送提醒超時廣告,然後從索引中刪除。如果廣告被更新,它可以再次被添加到索引。它會起作用嗎?
謝謝謝伊。我會考慮將廣告標記爲過期的建議,但這樣會出現在可能不需要的搜索結果中。 –
您需要篩選出來 –