[Zope3-Users] local search engine

6 views
Skip to first unread message

christophe petit

unread,
Sep 8, 2013, 11:19:31 PM9/8/13
to zope3-users
Hi,

Finally, I get to make appear in ZMI my local search engine product by setting into the following creationCatalog.py source :


--------------------------------------------------------------------------------------------------
from zope.component import adapter
from zope.app.intid.interfaces import IIntIds
from zope.app.intid import IntIds
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
from zope.app.catalog.text import TextIndex
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.container.interfaces import IObjectAddedEvent
from interfaces import ISearchz
from zope.app.component.site import LocalSiteManager
from zope.index.text.interfaces import ISearchableText

@adapter(ISearchz, IObjectAddedEvent)
def creationCatalog(site, event):
      sm = LocalSiteManager(site)
      intids = IntIds()
      sm['intids'] = intids
      sm.registerUtility(intids, IIntIds)

      catalog = Catalog()
      sm['catalog'] = catalog
      sm.registerUtility(catalog, ICatalog)

      fulltext = TextIndex(
          interface=ISearchableText,
          field_name='getSearchableText',
          field_callable=True
          )
      catalog[u'fulltext'] = fulltext
--------------------------------------------------------------------------------------------------

but now, problem happens when I try to add it on root folder.

Here's the Searchz.py source (in bold the several options that I tried to use for making
appear, once product is added, an "update item" for updating the catalog) :

--------------------------------------------------------------------------------------------------
from zope.component import getUtility, queryMultiAdapter
from zope.interface import implements
from zope.publisher.browser import BrowserPage
from zope.dublincore.interfaces import IZopeDublinCore
from zope.index.text.interfaces import ISearchableText
from zope.traversing.browser import absoluteURL
from zope.app.catalog.interfaces import ICatalog
from zope.app.pagetemplate import ViewPageTemplateFile
from interfaces import ISearchz
from persistent import Persistent
from zope.app.folder import Folder
from zope.app.container.btree import BTreeContainer

class Searchz(Persistent):
#class Searchz(
Folder):
#class Searchz(BTreeContainer):

      implements(ISearchz)
      def update(self, query):
          catalog = getUtility(ICatalog)
          self.results = catalog.searchResults(fulltext=query)

      render = ViewPageTemplateFile ('search.pt')

      def __call__(self, query):
          self.update(query)
          return self.render()

      def getResultsInfo(self):
          for obj in self.results:
              icon = queryMultiAdapter((obj, self.request), name='zmi_icon')

          if icon is not None:
             icon = icon()

          title = None
          dc = IZopeDublinCore(obj, None)

          if dc is not None:
             title = dc.title
             text = ISearchableText(obj).getSearchableText()

          if len(text) > 100:
             text = text[:97] + u'...'

          yield {'icon': icon, 'title': title, 'text': text,
                 'absolute_url': absoluteURL(obj, self.request)}

class QueryPage(BrowserPage):
      template = ViewPageTemplateFile('query.pt')
      count = 0
      total = 0
      def __call__(self):
          if "UPDATE_SUBMIT" in self.request.form:
              d = "delete_first" in self.request.form
              self.count, self.total = self.context.update(delete=d)
          return self.template()
--------------------------------------------------------------------------------------------------

The only option which works is "class Searchz(Persistent):" but I can't see the content
of a persistent object into ZMI. Folder and BTreeContainer doesn't work...

I have to find a container which allows to create a folder with an update item.

Could you tell me what I need to solve this ?

Thanks

ps: cc seb, j'espère avoir bien résumé :)





--------------------------------------------------------------------------------------------------
Subject: local search engine
To: zope3-users <zope3...@zope.org>


Hi,

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.

My issue occurs when I add the product in ZMI ("A system error occurred") with log :

ERROR SiteError https://site.com/@@contents.html
...
......
 File "/usr/lib/python2.4/site-packages/zope/tales/expressions.py", line 217, in __call__
    return self._eval(econtext)
  File "/usr/lib/python2.4/site-packages/zope/tales/expressions.py", line 211, in _eval
    return ob()
  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/contents.py", line 80, in listContentInfo
    self.addObject()
  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/contents.py", line 245, in addObject
    adding.action(request['type_name'], new)
  File "/usr/lib/python2.4/site-packages/zope/app/container/browser/adding.py", line 142, in action
    content = factory()
  File "/usr/lib/python2.4/site-packages/zope/component/factory.py", line 37, in __call__
    return self._callable(*args, **kw)
TypeError: __init__() takes exactly 3 arguments (1 given)

Here are the different sources :

__init__.py :

----------------------------------------------------------------------

from interfaces import ISearchz
from Searchz import Searchz, QueryPage

----------------------------------------------------------------------

Searchz.py :

----------------------------------------------------------------------

from zope.component import getUtility, queryMultiAdapter
from zope.interface import implements
from zope.publisher.browser import BrowserPage
from zope.dublincore.interfaces import IZopeDublinCore
from zope.index.text.interfaces import ISearchableText
from zope.traversing.browser import absoluteURL
from zope.app.catalog.interfaces import ICatalog
from zope.app.pagetemplate import ViewPageTemplateFile
from interfaces import ISearchz

class Searchz(BrowserPage):
      implements(ISearchz)
      def update(self, query):
          catalog = getUtility(ICatalog)
          self.results = catalog.searchResults(fulltext=query)

      render = ViewPageTemplateFile ('search.pt')

      def __call__(self, query):
          self.update(query)
          return self.render()

      def getResultsInfo(self):
          for obj in self.results:
              icon = queryMultiAdapter((obj, self.request), name='zmi_icon')

          if icon is not None:
             icon = icon()

          title = None
          dc = IZopeDublinCore(obj, None)

          if dc is not None:
             title = dc.title
             text = ISearchableText(obj).getSearchableText()

          if len(text) > 100:
             text = text[:97] + u'...'

          yield {'icon': icon, 'title': title, 'text': text,
                 'absolute_url': absoluteURL(obj, self.request)}

class QueryPage(BrowserPage):
      template = ViewPageTemplateFile('query.pt')
      count = 0
      total = 0
      def __call__(self):
          if "UPDATE_SUBMIT" in self.request.form:
              d = "delete_first" in self.request.form
              self.count, self.total = self.context.update(delete=d)
          return self.template()

----------------------------------------------------------------------

creationCatalog.py :

from zope.component import adapter
from zope.app.intid.interfaces import IIntIds
from zope.app.intid import IntIds
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
from zope.app.catalog.text import TextIndex
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.container.interfaces import IObjectAddedEvent
from interfaces import ISearchz

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

      catalog = Catalog()
      sm['catalog'] = catalog
      sm.registerUtility(catalog, ICatalog)

      fulltext = TextIndex(
          interface=ISearchableText,
          field_name='getSearchableText',
          field_callable=True
          )
      catalog[u'fulltext'] = fulltext

----------------------------------------------------------------------

interfaces.py :

----------------------------------------------------------------------

from zope.interface import Interface
from zope.schema import Text, TextLine, Int
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.interfaces import IContainer

class ISearchz(Interface):
    def update():
        """
        update catalog
        """
    def getResultsInfo():
        """
        query for searching in catalog
        """
    def __setitem__(key, value):
        """
        add page
        """
        __setitem__.precondition = ItemTypePrecondition(ISearchz)

----------------------------------------------------------------------

and configure.zcml :

----------------------------------------------------------------------

<configure xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="searchz">

  <interface
      interface=".interfaces.ISearchz"
      type="zope.app.content.interfaces.IContentType" />

  <class
      class=".Searchz">
    <implements
        interface=".interfaces.ISearchz" />
    <implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable" />
    <factory
        id="searchz.Searchz"
        title="Search Engine"
        description="Search Engine" />
    <require
        permission="zope.Public"
        interface=".interfaces.ISearchz" />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.ISearchz" />
  </class>

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

  <browser:addMenuItem
      class=".Searchz"
      title="Search Engine"
      description="Search Engine"
      permission="zope.ManageContent" />

  <browser:containerViews
      for=".interfaces.ISearchz"
      index="zope.View"
      contents="zope.View"
      add="zope.ManageContent" />

  <browser:addform
      label="Add search engine"
      name="addsearch.html"
      schema=".interfaces.ISearchz"
      content_factory="searchz.Searchz"
      permission="zope.ManageContent" />

  <browser:page
      for=".interfaces.ISearchz"
      name="query.html"
      class=".QueryPage"
      permission="zope.ManageContent"
      menu="zmi_views"
      title="Update Catalog" />

<subscriber handler=".creationCatalog.creationCatalog" />

</configure>

----------------------------------------------------------------------

Could you see what's wrong at first sight ?

Thanks



Christopher Lozinski

unread,
Sep 9, 2013, 7:19:47 AM9/9/13
to christophe petit, zope3...@zope.org
On 9/8/13 10:19 PM, christophe petit wrote:
> but now, problem happens when I try to add it on root folder.
I will be happy to help you. I also need to be able to add local
search engine catalogs through the ZMI.

First let us establish the context.

You have a lot of zope.app stuff in there. And yet I thought zope.app
was deprecated in ZTK.
You also talk about the ZMI. Also gone from ZTK.

So what is your starting point? ZTFY? Are you using an older version
of Zope 3?

--
Regards
Christopher Lozinski


_______________________________________________
Zope3-users mailing list
Zope3...@zope.org
https://mail.zope.org/mailman/listinfo/zope3-users

Christopher Lozinski

unread,
Oct 19, 2013, 1:45:26 AM10/19/13
to zope3...@zope.org
my attention is now on this problem.

First let us see if I understand the high level picture of what is going
on.

Okay, so you have a catalog that you create.

Then you have a query page.

And some code for displaying the results.

By local search engine, you mean it only searches inside the local site.

Okay so what is the problem?

*TypeError: __init__() takes exactly 3 arguments (1 given)*


Where is that called from?

File "/usr/lib/python2.4/site-packages/zope/component/factory.py", line
37, in __call__
return self._callable(*args, **kw)

Let us take a look at the source code
https://github.com/zopefoundation/zope.component/blob/master/src/zope/component/factory.py

Although that is probably not hte correct release.

So looking for how to install zope 3.3
http://old.zope.org/Products/Zope3/3.3.0b1/README.txt/

Okay, here are the downloads.
http://old.zope.org/Products/Zope3/

Which version exactly are you using?
Am I following correctly so far?
I will wait until I hear back from you.


Chris
Reply all
Reply to author
Forward
0 new messages