Google app engine 是否从索引中删除实体?

Google app engine 是否从索引中删除实体?,google-app-engine,python-2.7,webapp2,Google App Engine,Python 2.7,Webapp2,我这样做对吗?我正试图用这种方法从索引中删除一个实体,这是我第一次尝试,所以我不知道它是否有效: def get(self): timeline = datetime.now () - timedelta (days = 59) edge = datetime.now () - timedelta (days = 60) ads = Ad.all().filter("published =", True).filter("modified <", timeline)

我这样做对吗?我正试图用这种方法从索引中删除一个实体,这是我第一次尝试,所以我不知道它是否有效:

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())
def get(self):
timeline=datetime.now()-timedelta(天=59)
edge=datetime.now()-timedelta(天=60)
ads=Ad.all().filter(“published=”,True)。filter(“modified”,edge)
对于广告中的广告:
如果是广告标题:
主题=广告标题
其他:
主题='提醒'
message=mail.EmailMessage(发件人=)admin@koolbusiness.com,subject=subject)
提醒='您可以续订您的广告'
message.body=(“%s\nhttp://www.koolbusiness.com/vi/%d %s')%(提醒,ad.key().id(),'\n如果您愿意,也可以在Facebook上添加我们\nhttp://apps.facebook.com/koolbusiness')
message.to=ad.email
message.bcc=fridge@koolbusiness.com'
message.send()
index=search.index(name='ad',
一致性=索引。每个文档(一致)
index.remove(str(ad.key())

上面的代码应该发送超时广告的提醒,然后从索引中删除。如果广告已续订,则可以再次将其添加到索引中。是否有效?

您的代码应该有效,但我认为最好将广告标记为过期,而不是从索引中删除。这将节省您重新编制索引的需要更新广告和将给你更好的审计你的广告。< / P >谢谢你Shay。我会考虑的意见,标志广告作为过期的替代,但它会出现在搜索结果,可能是不想要的。