Quantcast

Indexes not updated on object modification

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Indexes not updated on object modification

À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
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Indexes not updated on object modification

Sebastian Ware
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
> [hidden email]
> https://mail.zope.org/mailman/listinfo/grok-dev


_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Indexes not updated on object modification

Àlex Magaz Graça
Thanks a lot Sebastian! It works now.

I was following the Grok book, but it doesn't say anything about it.
Also looked in the Grok web, but at the wrong place: the grok.Indexes  
documentation...

Àlex

El 08/12/11 10:09, Sebastian Ware escribió:

> 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
>> [hidden email]
>> https://mail.zope.org/mailman/listinfo/grok-dev
>
_______________________________________________
Grok-dev mailing list
[hidden email]
https://mail.zope.org/mailman/listinfo/grok-dev
Loading...