<div dir="ltr"><div><div><div>Hi,<br><br></div>Finally, I get to make appear in ZMI my local search engine product by setting into the following creationCatalog.py source :<br><br><br>--------------------------------------------------------------------------------------------------<br>
from zope.component import adapter<br>from zope.app.intid.interfaces import IIntIds<br>from zope.app.intid import IntIds<br>from zope.app.catalog.interfaces import ICatalog<br>from zope.app.catalog.catalog import Catalog<br>
from zope.app.catalog.text import TextIndex<br>from zope.app.pagetemplate import ViewPageTemplateFile<br>from zope.app.container.interfaces import IObjectAddedEvent<br>from interfaces import ISearchz<br>from zope.app.component.site import LocalSiteManager<br>
from zope.index.text.interfaces import ISearchableText<br><br>@adapter(ISearchz, IObjectAddedEvent)<br>def creationCatalog(site, event):<br>      sm = LocalSiteManager(site)<br>      intids = IntIds()<br>      sm['intids'] = intids<br>
      sm.registerUtility(intids, IIntIds)<br><br>      catalog = Catalog()<br>      sm['catalog'] = catalog<br>      sm.registerUtility(catalog, ICatalog)<br><br>      fulltext = TextIndex(<br>          interface=ISearchableText,<br>
          field_name='getSearchableText',<br>          field_callable=True<br>          )<br>      catalog[u'fulltext'] = fulltext<br>--------------------------------------------------------------------------------------------------<br>
<br>but now, problem happens when I try to add it on root folder.<br><br></div>Here's the Searchz.py source (in bold the several options that I tried to use for making <br></div>appear, once product is added, an "update item" for updating the catalog) :<br>
<div><br>--------------------------------------------------------------------------------------------------<br>from zope.component import getUtility, queryMultiAdapter<br>from zope.interface import implements<br>from zope.publisher.browser import BrowserPage<br>
from zope.dublincore.interfaces import IZopeDublinCore<br>from zope.index.text.interfaces import ISearchableText<br>from zope.traversing.browser import absoluteURL<br>from zope.app.catalog.interfaces import ICatalog<br>from zope.app.pagetemplate import ViewPageTemplateFile<br>
from interfaces import ISearchz<br>from persistent import Persistent<br>from zope.app.folder import Folder<br>from zope.app.container.btree import BTreeContainer<br><br><b>class Searchz(Persistent):<br>#class Searchz(</b><b>Folder):<br>
#class Searchz(BTreeContainer):</b><br>      implements(ISearchz)<br>      def update(self, query):<br>          catalog = getUtility(ICatalog)<br>          self.results = catalog.searchResults(fulltext=query)<br><br>      render = ViewPageTemplateFile ('<a href="http://search.pt">search.pt</a>')<br>
<br>      def __call__(self, query):<br>          self.update(query)<br>          return self.render()<br><br>      def getResultsInfo(self):<br>          for obj in self.results:<br>              icon = queryMultiAdapter((obj, self.request), name='zmi_icon')<br>
<br>          if icon is not None:<br>             icon = icon()<br><br>          title = None<br>          dc = IZopeDublinCore(obj, None)<br><br>          if dc is not None:<br>             title = dc.title<br>             text = ISearchableText(obj).getSearchableText()<br>
<br>          if len(text) > 100:<br>             text = text[:97] + u'...'<br><br>          yield {'icon': icon, 'title': title, 'text': text,<br>                 'absolute_url': absoluteURL(obj, self.request)}<br>
<br>class QueryPage(BrowserPage):<br>      template = ViewPageTemplateFile('<a href="http://query.pt">query.pt</a>')<br>      count = 0<br>      total = 0<br>      def __call__(self):<br>          if "UPDATE_SUBMIT" in self.request.form:<br>
              d = "delete_first" in self.request.form<br>              self.count, self.total = self.context.update(delete=d)<br>          return self.template()<br>--------------------------------------------------------------------------------------------------<br>
<div><br></div><div>The only option which works is <b>"class Searchz(Persistent):" </b>but I can't see the content <br></div><div>of a persistent object into ZMI. <b>Folder </b>and <b>BTreeContainer</b> doesn't work...<br>
<br></div><div>I have to find a container which allows to create a folder with an update item.<br><br></div><div>Could you tell me what I need to solve this ?<br><br></div><div>Thanks<br><br></div><div>ps: cc seb, j'espère avoir bien résumé :)<br>
</div><div><br><br><br><br><div><div><div><div><div class="gmail_quote"><br>--------------------------------------------------------------------------------------------------<br>Subject: local search engine<br>To: zope3-users <<a href="mailto:zope3-users@zope.org">zope3-users@zope.org</a>><br>
<br><br><div dir="ltr"><div><div><div><div>Hi,<br><br></div>I try to implement a local search engine product with Catalog. For this, I have followed the "Indexing and searching" part from "Web component Development with Zope3" book.<br>


<br></div>My issue occurs when I add the product in ZMI ("A system error occurred") with log :<br><br>ERROR SiteError <a href="https://site.com/@@contents.html" target="_blank">https://site.com/@@contents.html</a><br>

...<br>......<br>
 File "/usr/lib/python2.4/site-packages/zope/tales/expressions.py", line 217, in __call__<br>    return self._eval(econtext)<br>  File "/usr/lib/python2.4/site-packages/zope/tales/expressions.py", line 211, in _eval<br>


    return ob()<br>  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/contents.py", line 80, in listContentInfo<br>    self.addObject()<br>  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/contents.py", line 245, in addObject<br>


    adding.action(request['type_name'], new)<br>  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/adding.py", line 142, in action<br>    content = factory()<br>  File "/usr/lib/python2.4/site-packages/zope/component/factory.py", line 37, in __call__<br>


    return self._callable(*args, **kw)<br><b>TypeError: __init__() takes exactly 3 arguments (1 given)</b><br><br></div>Here are the different sources :<br><br></div>__init__.py :<br><br>----------------------------------------------------------------------<br>


<br><div>from interfaces import ISearchz<br>from Searchz import Searchz, QueryPage<br><div><br>----------------------------------------------------------------------<br><br></div><div>Searchz.py :<br></div><div><br>----------------------------------------------------------------------<br>


<br>from zope.component import getUtility, queryMultiAdapter<br>from zope.interface import implements<br>from zope.publisher.browser import BrowserPage<br>from zope.dublincore.interfaces import IZopeDublinCore<br>from zope.index.text.interfaces import ISearchableText<br>


from zope.traversing.browser import absoluteURL<br>from zope.app.catalog.interfaces import ICatalog<br>from zope.app.pagetemplate import ViewPageTemplateFile<br>from interfaces import ISearchz<br><br>class Searchz(BrowserPage):<br>


      implements(ISearchz)<br>      def update(self, query):<br>          catalog = getUtility(ICatalog)<br>          self.results = catalog.searchResults(fulltext=query)<br><br>      render = ViewPageTemplateFile ('<a href="http://search.pt" target="_blank">search.pt</a>')<br>


<br>      def __call__(self, query):<br>          self.update(query)<br>          return self.render()<br><br>      def getResultsInfo(self):<br>          for obj in self.results:<br>              icon = queryMultiAdapter((obj, self.request), name='zmi_icon')<br>


<br>          if icon is not None:<br>             icon = icon()<br><br>          title = None<br>          dc = IZopeDublinCore(obj, None)<br><br>          if dc is not None:<br>             title = dc.title<br>             text = ISearchableText(obj).getSearchableText()<br>


<br>          if len(text) > 100:<br>             text = text[:97] + u'...'<br><br>          yield {'icon': icon, 'title': title, 'text': text,<br>                 'absolute_url': absoluteURL(obj, self.request)}<br>


<br>class QueryPage(BrowserPage):<br>      template = ViewPageTemplateFile('<a href="http://query.pt" target="_blank">query.pt</a>')<br>      count = 0<br>      total = 0<br>      def __call__(self):<br>          if "UPDATE_SUBMIT" in self.request.form:<br>


              d = "delete_first" in self.request.form<br>              self.count, self.total = self.context.update(delete=d)<br>          return self.template()<br><br>----------------------------------------------------------------------<br>


<br></div><div>creationCatalog.py :<br></div><div><br>from zope.component import adapter<br>from zope.app.intid.interfaces import IIntIds<br>from zope.app.intid import IntIds<br>from zope.app.catalog.interfaces import ICatalog<br>


from zope.app.catalog.catalog import Catalog<br>from zope.app.catalog.text import TextIndex<br>from zope.app.pagetemplate import ViewPageTemplateFile<br>from zope.app.container.interfaces import IObjectAddedEvent<br>from interfaces import ISearchz<br>


<br>@adapter(ISearchz, IObjectAddedEvent)<br>def creationCatalog(event):<br>      sm = event.object.getSiteManager()<br>      intids = IntIds()<br>      sm['intids'] = intids<br>      sm.registerUtility(intids, IIntIds)<br>


<br>      catalog = Catalog()<br>      sm['catalog'] = catalog<br>      sm.registerUtility(catalog, ICatalog)<br><br>      fulltext = TextIndex(<br>          interface=ISearchableText,<br>          field_name='getSearchableText',<br>


          field_callable=True<br>          )<br>      catalog[u'fulltext'] = fulltext<br><br>----------------------------------------------------------------------<br><br></div><div>interfaces.py :<br><br>----------------------------------------------------------------------<br>


<br>from zope.interface import Interface<br>from zope.schema import Text, TextLine, Int<br>from zope.app.container.constraints import ItemTypePrecondition<br>from zope.app.container.interfaces import IContainer<br><br>class ISearchz(Interface):<br>


    def update():<br>        """<br>        update catalog<br>        """<br>    def getResultsInfo():<br>        """ <br>        query for searching in catalog<br>        """<br>


    def __setitem__(key, value):<br>        """ <br>        add page<br>        """<br>        __setitem__.precondition = ItemTypePrecondition(ISearchz)<br><br>----------------------------------------------------------------------<br>


<br></div><div>and configure.zcml :<br><br>----------------------------------------------------------------------<br><br><configure xmlns="<a href="http://namespaces.zope.org/zope" target="_blank">http://namespaces.zope.org/zope</a>"<br>


    xmlns:browser="<a href="http://namespaces.zope.org/browser" target="_blank">http://namespaces.zope.org/browser</a>"<br>    i18n_domain="searchz"><br><br>  <interface<br>      interface=".interfaces.ISearchz"<br>


      type="zope.app.content.interfaces.IContentType" /><br><br>  <class<br>      class=".Searchz"><br>    <implements<br>        interface=".interfaces.ISearchz" /><br>    <implements<br>


        interface="zope.annotation.interfaces.IAttributeAnnotatable" /><br>    <factory<br>        id="searchz.Searchz"<br>        title="Search Engine"<br>        description="Search Engine" /><br>


    <require<br>        permission="zope.Public"<br>        interface=".interfaces.ISearchz" /><br>    <require<br>        permission="zope.ManageContent"<br>        set_schema=".interfaces.ISearchz" /><br>


  </class><br><br>  <browser:icon name="zmi_icon"<br>      for=".interfaces.ISearchz"<br>      file="search.gif" /><br><br>  <browser:addMenuItem<br>      class=".Searchz"<br>


      title="Search Engine"<br>      description="Search Engine"<br>      permission="zope.ManageContent" /><br><br>  <browser:containerViews<br>      for=".interfaces.ISearchz"<br>


      index="zope.View"<br>      contents="zope.View"<br>      add="zope.ManageContent" /><br><br>  <browser:addform<br>      label="Add search engine"<br>      name="addsearch.html"<br>


      schema=".interfaces.ISearchz"<br>      content_factory="searchz.Searchz"<br>      permission="zope.ManageContent" /><br><br>  <browser:page<br>      for=".interfaces.ISearchz"<br>


      name="query.html"<br>      class=".QueryPage"<br>      permission="zope.ManageContent"<br>      menu="zmi_views"<br>      title="Update Catalog" /><br><br><b><subscriber handler=".creationCatalog.creationCatalog" /></b><br>


<br></configure><br><br></div><div>----------------------------------------------------------------------<br><br></div><div>Could you see what's wrong at first sight ?<br><br></div><div>Thanks<br></div><div><br>

<br>


</div></div></div>
</div><br></div></div></div></div></div></div></div>