【问题标题】:Delete entity from index?从索引中删除实体?
【发布时间】:2012-09-03 23:31:21
【问题描述】:

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

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

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

【问题讨论】:

    标签: google-app-engine python-2.7 webapp2


    【解决方案1】:

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

    【讨论】:

    • 谢谢谢伊。我会考虑将广告标记为过期的建议,但它会出现在搜索结果中,这可能是不想要的。
    • 当然你需要过滤掉这个
    猜你喜欢
    • 2015-09-20
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多