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
--------------------------------------------------------------------------------------------------
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