[Zope-CMF] Searching CMF returns all objects
Grégoire Weber
gregoire.weber@switzerland.org
Mon, 29 Apr 2002 16:45:54 +0200
Hi all,
Hi Tres (have at least a look at Points 6) and 7) below),
it's a combination of two problems as ist seems (old catalog Indexes
and changes in CMF search behaviour).
if you have code like
portal_catalog.searchresults(Subject='foo', sort_order='reverse')
in your DTML-Files the change Josef proposed doesn't exactly fit
your needs.
What I've done (just to inform interested people, but don't blame
me if your run into problems):
1) I replaced the following line in
lib/python/products/PluginIndexes/textIndex.py
line 312 (Zope 2.5.0):
for word in list(splitter(source,encoding=encoding)):
by
for word in list(splitter(source)):
2) Restarted Zope
3) Run the python code below as external method. It should not
generate a exception like:
Splitter() got an unexpected keyword argument 'encoding'
<CODE>
from Products.CMFCore.utils import getToolByName
def update_catalogIndexes(self, REQUEST):
"""
Drop, re-add, and rebuild catalog Indexes for Zope CMF
sites migrated Zope 2.3 to 2.4+.
"""
CMF_CATALOG_INDEXES = (
( 'Contributors', 'FieldIndex' )
, ( 'Creator', 'FieldIndex' )
, ( 'Date', 'FieldIndex' )
, ( 'Subject', 'KeywordIndex' )
, ( 'Type', 'FieldIndex' )
, ( 'allowedRolesAndUsers', 'KeywordIndex' )
, ( 'bobobase_modification_time', 'FieldIndex' )
, ( 'created', 'FieldIndex' )
, ( 'effective', 'FieldIndex' )
, ( 'expires', 'FieldIndex' )
, ( 'id', 'FieldIndex' )
, ( 'in_reply_to', 'FieldIndex' )
, ( 'meta_type', 'FieldIndex' )
, ( 'modified', 'FieldIndex' )
, ( 'review_state', 'FieldIndex' )
, ( 'Description', 'TextIndex' )
, ( 'PrincipiaSearchSource', 'TextIndex' )
, ( 'SearchableText', 'TextIndex' )
, ( 'Title', 'TextIndex' )
, ( 'title', 'TextIndex' )
)
catalog = getToolByName( self, 'portal_catalog' )
for index_name, index_type in CMF_CATALOG_INDEXES:
catalog.delIndex( index_name )
catalog.addIndex( index_name, index_type )
catalog.refreshCatalog(clear=1)
return 'Catalog Indexes rebuilt.'
</CODE>
4) I undo the changes done in
lib/python/products/PluginIndexes/textIndex.py:
5) Restarted Zope
6) I customized the doFormSearch skin python script and extended it a
little bit (would it make sense to put that into CMF 1.3? -- Tres?):
<CODE>
## Script (Python) "doFormSearch"
##parameters=REQUEST, *arg, **key
##title=Pre-process form variables, then return catalog query results.
##
form_vars = {}
# ----- new -----
for a in arg:
form_vars.update(a)
# ----- new -----
form_vars.update(key)
select_vars = ( 'review_state'
, 'Subject'
, 'created'
, 'Type'
)
for k, v in REQUEST.form.items():
if k in select_vars:
if same_type( v, [] ):
v = filter( None, v )
if not v:
continue
form_vars[ k ] = v
return context.portal_catalog( form_vars )
</CODE>
7) At places where I used code like
portal_catalog.searchResults(Subject='foo', sort_order='reverse')
I use now:
doFormSearch(REQUEST=REQUEST, Subject='foo', sort_oder="'reverse')
And it all works as before in Zope 2.3.3 with CMF 1.2
Hope that helps people having the same problems I had upgrading from
Zope 2.3.3/CMF 1.2 to Zope 2.5.x/CMF 1.3((pre(beta))
Gregoire
> I ran into the same problem. Then, I just start to do whatever I
> found and then
> I discovered that the CMF guys change the following line of
> the "search" method:
>
> <dtml-let results=portal_catalog>
>
> the new one should be:
>
> <dtml-let results="doFormSearch( REQUEST=REQUEST )">
>
> I changed it and it solved my problem.
>
> Hope it helps,
> greetings,
> Josef.
_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org