[Zope] searching for a blank value
Chris Withers
chrisw@nipltd.com
Tue, 13 May 2003 09:23:35 +0100
Michael Havard wrote:
> Okay I have my FieldIndexes set up to search by 4 fields. Searching
> works great unless you need to search for a blank field.
>
> Lets say I have a search where I need to find
> Field1='Test'
> Field2='Test'
> Field3=''
> Field4=''
>
> the search string looks like
>
> /search?Fields1=Test&Field2=Test&Field3=&Field4=
>
> The search would return all records where the first two fields matched
> PLUS the rest of the records that had any values at all. So I might get
> back records with a field list like:
>
> 1) 'Test' 'Test' 'Test' 'Test'
> 2) 'Test' 'Test' 'Test' ''
> 3) 'Test' 'Test' '' ''
This is by design, since it makes it easier for search forms with text boxes on
them to work as expected in most cases. ie: you leave the box empty, that box
doesn't affect the search results.
> When all I really need is #3.
In that case, modify your search script so it looks something like:
searchSpec = {}
for key,value in context.REQUEST.form:
if not value:
value = ('',)
searchSpec[key] = value
brains = context.your_catalog(searchSpec)
cheers,
Chris