2012-09-11 136 views
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()) 

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

回答

2

您的代码应该可以正常工作,但恕我直言,最好将广告标记为已过期,而不是将其从索引中移除。这样可以为您节省重新分配续订广告的需求,并且可以更好地审核您的广告。

+0

谢谢谢伊。我会考虑将广告标记为过期的建议,但这样会出现在可能不需要的搜索结果中。 –

+0

您需要筛选出来 –