etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.2k stars 130 forks source link

Clearing the database-cached data? #167

Closed evcb closed 8 years ago

evcb commented 8 years ago

I have a platform where advertisements often get marked as "deleted" if they are not renewed. The problem is that they still appear registered on watson, leading to a 404 error. I believe, in my case, I will have to rebuild the whole search table every time I update watson. Is there any command to clear the table, @etianen ? I want to use it before I run build watson.

etianen commented 8 years ago

If the advertisments are only marked as deleted, then you can filter these out of your watson searches without having to rebuild the search data.

watson.register(YourModel.objects.filter(is_deleted=False))

See https://github.com/etianen/django-watson/wiki/Registering-models#only-displaying-live-search-results

On Fri, 17 Jun 2016 at 10:31 hellvix notifications@github.com wrote:

I have a platform where advertisements often get marked as "deleted" if they are not renewed. The problem is that they still appear registered on watson, leading to a 404 error. I believe, in my case, I will have to rebuild the whole search table every time I update watson. Is there any command to clear the table, @etianen https://github.com/etianen ? I want to use it before I run build watson.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167, or mute the thread https://github.com/notifications/unsubscribe/AAJFCEcjhQFThyVJYYxj-1RNKNz57O1dks5qMmlygaJpZM4I4L7N .

evcb commented 8 years ago

Yeah, I do that. Somehow the results are still there. The build command returns the following:

17/06/2016 09:00:11 Deleted 0 stale search entry(s) in 'default' search engine. 17/06/2016 09:00:11 Deleted 0 stale search entry(s) in 'admin' search engine. 17/06/2016 09:00:11 Refreshed 1492 search entry(s) in 'admin' search engine.

Does it rebuild it from scratch or just adds new ones?

Note: And yes, they are just flagged as deleted in the database.

etianen commented 8 years ago

Are you using a bulk update to flip the flag? If so, don't, because that will skip sending the post_save() signal that watson needs to keep it's indices updated.

On Fri, 17 Jun 2016 at 11:07 hellvix notifications@github.com wrote:

Yeah, I do that. Somehow the results are still there. The build command returns the following:

17/06/2016 09:00:11 Deleted 0 stale search entry(s) in 'default' search engine. 17/06/2016 09:00:11 Deleted 0 stale search entry(s) in 'admin' search engine. 17/06/2016 09:00:11 Refreshed 1492 search entry(s) in 'admin' search engine.

Does it rebuild it from scratch or just adds new ones?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167#issuecomment-226732086, or mute the thread https://github.com/notifications/unsubscribe/AAJFCET12hElLH1EMnQi3lKQjTvFgMvxks5qMnHrgaJpZM4I4L7N .

evcb commented 8 years ago

Yeah, I have a crontab script that runs a django management command to bulk update my entries. However, I do update watson manually every now and then through crontab with the buildwatson command.

etianen commented 8 years ago

Hmm, actually, if you're doing watson.register(YourModel.objects.filter(is_deleted=False)), then you shouldn't need to run buildwatson to update the indices, since the is_deleted filter is applied when the models are searched. It'll even work with bulk updates.

What watson API call are you doing to get the search results with the deleted models in?

On Fri, 17 Jun 2016 at 11:44 hellvix notifications@github.com wrote:

Yeah, I have a crontab script that runs a django management command to bulk update my entries. However, I do update watson manually every now and then through crontab.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167#issuecomment-226738717, or mute the thread https://github.com/notifications/unsubscribe/AAJFCDasgmn8GtHXD8CDgqswZFSG777Hks5qMnqVgaJpZM4I4L7N .

evcb commented 8 years ago

I use

views.py

from watson import search as watson
search_result = watson.filter(Advertisement, query)

apps.py

def ready(self):
        from housefy_app.models import Post
        from watson import search as watson

        advertisement = self.get_model('Advertisement')
        city = self.get_model('City')

        watson.register(advertisement.objects.filter(pub_status=Post.STATUS_PUBLISHED), fields=(
            "title",
            "type__name",
            "type__tags",
            "category__name",
            "category__tags",
            "city__name",
            "city__region",
            "city__tags",
        ))

        watson.register(city, fields=(
            "post_code",
            "name",
            "tags",
            "region",
        ))

Should buildwatson return any "deleted" entries if an entry that had been previously registered does not fit the criteria anymore?

etianen commented 8 years ago

Ah, yes, a bit of a gotcha there. The filtering you specify in the register() doesn't apply to watson.filter(), only watson.search(). No good reason for that, just legacy. It should really be fixed.

Meanwhile, you can get what you want with:

search_result = watson.filter(Advertisement, query).filter(deleted=False)

watson.filter() just returns a queryset of your model, so you can filter it however you want. :)

On Fri, 17 Jun 2016 at 13:20 hellvix notifications@github.com wrote:

I use

from watson import search as watson search_result = watson.filter(Advertisement, query)

apps.py

def ready(self): from housefy_app.models import Post from watson import search as watson

    advertisement = self.get_model('Advertisement')
    city = self.get_model('City')

    watson.register(advertisement.objects.filter(pub_status=Post.STATUS_PUBLISHED), fields=(
        "title",
        "type__name",
        "type__tags",
        "category__name",
        "category__tags",
        "city__name",
        "city__region",
        "city__tags",
    ))

    watson.register(city, fields=(
        "post_code",
        "name",
        "tags",
        "region",
    ))

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167#issuecomment-226754904, or mute the thread https://github.com/notifications/unsubscribe/AAJFCPrU2GSk2Wc7NVkUzvKyKP5R6ckBks5qMpEagaJpZM4I4L7N .

evcb commented 8 years ago

Humm, ok. In the documentation it says:

watson.register(YourModel.objects.filter(is_published=True))

The above code will ensure that no models where is_published == False will appear in your search results.

I thought it would apply the filter and add the results to watson's search table.

0) Is there a way to use another method that will get the results from register? I wanted to implement a more dynamic filtering, such as the one I did on apps.py. I mean, there is the central point where I do the whole selection of results that will appear in the results. 1) Why adding a filter to the register() method if the results will be fetched without it?

etianen commented 8 years ago

I think I summed that up with "Ah, yes, a bit of a gotcha there. The filtering you specify in the register() doesn't apply to watson.filter(), only watson.search(). No good reason for that, just legacy. It should really be fixed."

On Fri, 17 Jun 2016 at 15:04 hellvix notifications@github.com wrote:

Humm, ok. In the documentation it says:

watson.register(YourModel.objects.filter(is_published=True))

The above code will ensure that no models where is_published == False will appear in your search results.

I thought it would apply the filter and add the results to watson's search table.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167#issuecomment-226777326, or mute the thread https://github.com/notifications/unsubscribe/AAJFCHdEdwmjVCPdDZ4B8GXwCWJKSVX0ks5qMqlcgaJpZM4I4L7N .

evcb commented 8 years ago

:+1:

Thanks for the help. :-)

etianen commented 8 years ago

To be honest, django-watson needs a bit of love. I recently gave django-reversion a massive facelift, cleaning up 8 years worth of cruft and rewriting the docs. django-watson will get this treatment too, just as soon as I have the energy to contemplate it! :)

evcb commented 8 years ago

Ok :-) Den 17. jun. 2016 16.14 skrev "Dave Hall" notifications@github.com:

To be honest, django-watson needs a bit of love. I recently gave django-reversion a massive facelift, cleaning up 8 years worth of cruft and rewriting the docs. django-watson will get this treatment too, just as soon as I have the energy to contemplate it! :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/167#issuecomment-226779800, or mute the thread https://github.com/notifications/unsubscribe/APauDmE6HpxjsfbGDkiIda4QU_sRkxCSks5qMquVgaJpZM4I4L7N .