I originally sent this message by mistake only to Chiristian who
replied to my previous one.
I send a copy to the mailing list in case it may be useful for someone else too.


---------- Forwarded message ----------
From: Massimiliano della Rovere <massimiliano.dellarov...@gmail.com>
Date: Wed, Feb 18, 2009 at 21:09
Subject: Re: [Zope3-Users] Search multiple fields with TextIndex
To: Christian Lück <christian.lu...@ruhr-uni-bochum.de>


On Tue, Feb 17, 2009 at 23:50, Christian Lück
<christian.lu...@ruhr-uni-bochum.de> wrote:
> Massimiliano della Rovere wrote:
>> Another question is:
>> is there a way to automatically create TextIndices for certain (all) fields
>> of an interface?
>
> No, I think there's not. The event subscriber to IEventoNuovoSiteMabon
> is the way to go.
> Instead of using a field manager :) I suggest you use the api of
> zope.interface and zope.schema to iterate over the fields and drop some.
> See p.64 of Philipp's book (third edition).
I use the Field manager because I find the omit function more elegant
than an "if" in a iterator:
campi = [ campo for campo in zope.schema.getFieldNames(IScheda) if
campo not in ('__name__', '__parent__', 'titolo') ]

> form zope.app.catalog.text import TextIndex
>
> def catalogo_e_indice(event):
>  gs = event.object.getSiteManager()
>
>  ... # create intid utility and catalog as you did
>
>  for campo in zope.schema.getFieldNames(IScheda):
>    if not campo in ('__name__', '__parent__', 'some_field_I_want_to_drop'):
>      catalogo[campo] = TextIndex(
>        interface = IScheda,
>        field_name = campo,
>        field_callable = False)
there is something strange in my opinion using this method.
When I specify the interface=IScheda, I do not link the data extractor
to the actual istance of the Scheda class.
On the contrary using an adapter, like TestoSchedaPerRicerca (see
below), the istance which to extract the data from is passed as
context.

When I use this method I receive the following error:
Traceback (most recent call last):
 File "/usr/lib/python2.4/site-packages/zope/publisher/publish.py",
line 133, in publish
   result = publication.callObject(request, obj)
 File 
"/usr/lib/python2.4/site-packages/zope/app/publication/zopepublication.py",
line 161, in callObject
   return mapply(ob, request.getPositionalArguments(), request)
 File "/usr/lib/python2.4/site-packages/zope/publisher/publish.py",
line 108, in mapply
   return debug_call(obj, args)
  - __traceback_info__: <security proxied
zope.app.publisher.browser.viewmeta.ModuloAggiungiScheda instance at
0xa89c4cc>
 File "/usr/lib/python2.4/site-packages/zope/publisher/publish.py",
line 114, in debug_call
   return obj(*args)
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
769, in __call__
   self.update()
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
750, in update
   result = action.success(data)
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
594, in success
   return self.success_handler(self.form, self, data)
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
861, in handle_add
   self.createAndAdd(data)
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
868, in createAndAdd
   return self.add(ob)
 File "/usr/lib/python2.4/site-packages/zope/formlib/form.py", line
877, in add
   ob = self.context.add(object)
 File "/usr/lib/python2.4/site-packages/zope/app/container/browser/adding.py",
line 72, in add
   container[name] = content
 File "/usr/lib/python2.4/site-packages/zope/app/container/sample.py",
line 86, in __setitem__
   setitem(self, self.__data.__setitem__, key, object)
 File "/usr/lib/python2.4/site-packages/zope/app/container/contained.py",
line 593, in setitem
   notify(event)
 File "/usr/lib/python2.4/site-packages/zope/event/__init__.py", line
23, in notify
   subscriber(event)
 File "/usr/lib/python2.4/site-packages/zope/component/event.py",
line 26, in dispatch
   for ignored in zope.component.subscribers(event, None):
 File "/usr/lib/python2.4/site-packages/zope/component/_api.py", line
130, in subscribers
   return sitemanager.subscribers(objects, interface)
 File "/usr/lib/python2.4/site-packages/zope/component/registry.py",
line 290, in subscribers
   return self.adapters.subscribers(objects, provided)
 File "/usr/lib/python2.4/site-packages/zope/interface/adapter.py",
line 535, in subscribers
   subscription(*objects)
 File "/usr/lib/python2.4/site-packages/zope/component/event.py",
line 33, in objectEventNotify
   adapters = zope.component.subscribers((event.object, event), None)
 File "/usr/lib/python2.4/site-packages/zope/component/_api.py", line
130, in subscribers
   return sitemanager.subscribers(objects, interface)
 File "/usr/lib/python2.4/site-packages/zope/component/registry.py",
line 290, in subscribers
   return self.adapters.subscribers(objects, provided)
 File "/usr/lib/python2.4/site-packages/zope/interface/adapter.py",
line 535, in subscribers
   subscription(*objects)
 File "/usr/lib/python2.4/site-packages/zope/app/intid/__init__.py",
line 169, in addIntIdSubscriber
   notify(IntIdAddedEvent(ob, event))
 File "/usr/lib/python2.4/site-packages/zope/event/__init__.py", line
23, in notify
   subscriber(event)
 File "/usr/lib/python2.4/site-packages/zope/component/event.py",
line 26, in dispatch
   for ignored in zope.component.subscribers(event, None):
 File "/usr/lib/python2.4/site-packages/zope/component/_api.py", line
130, in subscribers
   return sitemanager.subscribers(objects, interface)
 File "/usr/lib/python2.4/site-packages/zope/component/registry.py",
line 290, in subscribers
   return self.adapters.subscribers(objects, provided)
 File "/usr/lib/python2.4/site-packages/zope/interface/adapter.py",
line 535, in subscribers
   subscription(*objects)
 File "/usr/lib/python2.4/site-packages/zope/app/catalog/catalog.py",
line 153, in indexDocSubscriber
   cat.index_doc(id, ob)
 File "/usr/lib/python2.4/site-packages/zope/app/catalog/catalog.py",
line 62, in index_doc
   index.index_doc(docid, texts)
 File "/usr/lib/python2.4/site-packages/zope/app/catalog/attribute.py",
line 144, in index_doc
   return super(AttributeIndex, self).index_doc(docid, value)
 File "/usr/lib/python2.4/site-packages/zope/index/text/textindex.py",
line 45, in index_doc
   self.index.index_doc(docid, text)
 File "/usr/lib/python2.4/site-packages/zope/index/text/okapiindex.py",
line 225, in index_doc
   count = BaseIndex.index_doc(self, docid, text)
 File "/usr/lib/python2.4/site-packages/zope/index/text/baseindex.py",
line 95, in index_doc
   wids = self._lexicon.sourceToWordIds(text)
 File "/usr/lib/python2.4/site-packages/zope/index/text/lexicon.py",
line 66, in sourceToWordIds
   for t in last:
TypeError: iteration over non-sequence



>>> and the data extractor:
>>> class TestoSchedaPerRicerca(object):
>>> """Estrattore del testo per le ricerche"""
>>> implements(ISearchableText)
>>> adapts(IScheda)
>>>
>>> def __init__( self, context ):
>>> self.context = context
>>>
>>> def __getattr__( self, attr ):
I use the __getattr__ so that when the TestoSchedaPerRicerca is asked
for an attribute matching the name of those specified in the Index
definition:
       for i in campi:
               testuale = TextIndex(
                       interface = ISearchableText,
                       field_name = i,
                       field_callable = True
               )
               catalogo[i] = testuale

> # What is this method for? Does ISearchableText subclass IScheda?
No.
ISearchableText is an interface created to be used in conjuction with
Index creation.
It is in "zope.index.text.interfaces".



-- 
Se proprio dovete inserirmi in una mail in una
lista con indirizzi, vi prego di mettere il mio
nel campo CCN: o BCC: e non in TO: CC: oppure A:
------------
skype: masdero, icq: 473891447, yim: mas_dero, msn: mas_d...@hotmail.com
------------
Mi scriva in italiano; Write me in English; Skribu al mi Esperante!
------------
Volete farmi un regalo a natale e non sapete cosa? :D
http://www.boardgamegeek.com/collection/user/masdero?sort=wishlist&sortdir=asc&columns=title|thumbnail|status|rating|bggrating|plays|comment|commands&wishlist=1&ff=1
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to