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='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())

上面的代码应该为超时的广告发送提醒,然后从索引中删除。如果广告被更新,它可以再次添加到索引中。它会起作用吗?

4

1 回答 1

2

您的代码应该可以工作,但恕我直言,最好将广告标记为已过期,而不是将其从索引中删除。这将使您无需重新索引更新的广告,并为您提供更好的广告审核。

于 2012-09-11T05:38:54.013 回答