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.21k stars 129 forks source link

Automaticlly update indexes for manytomany fields #131

Closed davegri closed 8 years ago

davegri commented 9 years ago

I have the following configuration:

 class CrawlersConfig(AppConfig):
     name = "crawlers"
     def ready(self):
         Image = self.get_model("Image")
         watson.register(Image,  fields=('tags__name',), store=('thumbnail__url', 'page_url', 'source_url',          'get_origin_display', 'tags__name'))     

According to the docs I just need to add the watson middleware in order for a change in the manytomany fields to update the index. I added it but it still doesn't update when I add or remove tags to my images.

etianen commented 9 years ago

I've just pushed up a commit to master that should fix this.

On Tue, 6 Oct 2015 at 18:05 David Griver notifications@github.com wrote:

I have the following configuration:

class CrawlersConfig(AppConfig): name = "crawlers" def ready(self): Image = self.get_model("Image") watson.register(Image, fields=('tagsname',), store=('thumbnailurl', 'page_url', 'source_url', 'get_origin_display', 'tags__name'))

According to the docs I just need to add the watson middleware in order for a change in the manytomany fields to update the index. I added it but it still doesn't update when I add or remove tags to my images.

— Reply to this email directly or view it on GitHub https://github.com/etianen/django-watson/issues/131.

davegri commented 9 years ago

It's still not working, also it dosen't create a new index for new objects, is it supposed to? how do I automatically index every new object I add?

etianen commented 9 years ago

I assume that you've set the app config as the default app config for your app?

On Wed, 7 Oct 2015 at 14:27 David Griver notifications@github.com wrote:

It's still not working, also it dosen't create a new index for new objects, is it supposed to? how do I automatically index every new object I add?

— Reply to this email directly or view it on GitHub https://github.com/etianen/django-watson/issues/131#issuecomment-146195992 .

davegri commented 9 years ago

I think so, can you elaborate?

etianen commented 9 years ago

In the init.py of the app, you need something along the lines of:

DEFAULT_APP_CONFIG = "yourapp.apps.YourAppConfig"

Easy check, put a print("foo") in your ready() method to ensure its executed! On Wed, 7 Oct 2015 at 21:26, David Griver notifications@github.com wrote:

I think so, can you elaborate?

— Reply to this email directly or view it on GitHub https://github.com/etianen/django-watson/issues/131#issuecomment-146317901 .

davegri commented 9 years ago

Yeah, the models wouldn't be registered otherwise so I have that.

etianen commented 9 years ago

If your models are registered, then calling save() on the model will create a new SearchEntry in the database. The change I pushed ot master was also adding to the SearchEntry index when the M2M fields are changed.

If that's not happening, then I don't think your models are being registered. Some print("foo") around the registration code will verify if this is the case,

On Thu, 8 Oct 2015 at 07:58 David Griver notifications@github.com wrote:

Yeah, the models wouldn't be registered otherwise so I have that.

— Reply to this email directly or view it on GitHub https://github.com/etianen/django-watson/issues/131#issuecomment-146438421 .