Discussion:
[Zope3-Users] local search engine
christophe petit
2013-08-01 12:10:44 UTC
Permalink
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
Michael Howitz
2013-08-14 17:19:58 UTC
Permalink
Am 01.08.2013 um 14:10 schrieb christophe petit <***@gmail.com>:
[…]
Post by christophe petit
@adapter(ISearchz, IObjectAddedEvent)
[…]
Post by christophe petit
Could you see what's wrong at first sight ?
You define two arguments in the adapter decorator, but your function accepts only one.

Yours sincerely,
--
Michael Howitz · ***@gocept.com · software developer
gocept gmbh & co. kg · Forsterstraße 29 · 06112 Halle (Saale) · Germany
http://gocept.com · Tel +49 345 1229889-8
Python, Pyramid, Plone, Zope · consulting, development, hosting, operations
Loading...