[Grok-dev] Indexes not updated on object modification

Sebastian Ware sebastian at urbantalk.se
Thu Dec 8 09:09:51 UTC 2011


You have to call 

  grok.notify(grok.ObjectModifiedEvent(the_modified_object))

for indexes to be updated if you update properties manually. This is done automatically in when you do

  self.applyData(self.context, **data)

in forms. This is easy to forget and I do all the time... but it gives nice control over when the reindexing of the object is performed. It also exposes a useful event to listen to if you have other objects that need to be updated on modifications (you would need to fire grok.ObjectModifiedEvent events in those event listeners too if the change affects the indexing of those objects).

Mvh Sebastian

7 dec 2011 kl. 19.47 skrev Àlex Magaz Graça:

> Hi,
> 
> I'm getting indexes updated on object creation but not when they are modified, unless I call ICatalog.updateIndexes(). Shouldn't       the catalog be notified about modifications and update affected indexes?
> 
> This is more or less what I have:
> 
> class Helpdesk(grok.Application, grok.Container):
>     def __init__(self):
>         super(Helpdesk, self).__init__()
>         self["tickets"] = TicketCatalog()
> 
> class TicketCatalog(grok.Container):
>     pass
> 
> class Ticket(grok.Model):
>     def __init__(self, reporter):
>         super(Ticket, self).__init__()
>         self.reporter = reporter
> 
> class TicketIndex(grok.Indexes):
>     grok.site(Helpdesk)
>     grok.context(Ticket)
>     
>     reporter = grok.index.Field()
> 
> 
> After adding an object I get it from searchResults:
> 
> ticket1 = Ticket("foo")
> context["1"] = ticket1
> catalog = getUtility(ICatalog)
> results = catalog.searchResults( reporter=("bar", "bar") )
> (results empty)
> 
> here "context" would be an instance of TicketCatalog. However, if later I
> decide to modify the stored object, the index is not updated and searchResults
> still gives me the same results:
> 
> ticket1.reporter = "bar"
> catalog = getUtility(ICatalog)
> results = catalog.searchResults( reporter=("bar", "bar") )
> (results empty again)
> 
> catalog.updateIndexes()
> results = catalog.searchResults( reporter=("bar", "bar") )
> (I get the ticket)
> 
> Is there anything wrong?
> 
> Thanks,
> Àlex
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev




More information about the Grok-dev mailing list